OSDN Git Service

add unun event and ununsmell event.
authornagoling <>
Sun, 29 Sep 2013 05:41:19 +0000 (14:41 +0900)
committernagomi <nagomi@192.168.1.23>
Sun, 29 Sep 2013 05:41:19 +0000 (14:41 +0900)
ctrl.js
data/marisa/params.json
lang/ja.js
main.js

diff --git a/ctrl.js b/ctrl.js
index b10128f..0b68943 100644 (file)
--- a/ctrl.js
+++ b/ctrl.js
@@ -330,6 +330,7 @@ var MangMsg = enchant.Class.create({
                this.ctl = ctl;
        },
        output:function(yukkuri, emsg){
+               //var M = yukkuri.getMsg();
                if(emsg == EMsg.WALK){
                        if(rand(4) === 0){
                                yukkuri.tweet(M.WALK1);
@@ -364,6 +365,19 @@ var MangMsg = enchant.Class.create({
                else if(emsg == EMsg.DEAD){
                        yukkuri.tweet(M.DEAD1);
                }
+               else if(emsg == EMsg.UNUN){
+                       if(rand(2) === 0){
+                               yukkuri.tweet(M.UNUN1);
+                       }else{
+                               yukkuri.tweet(M.UNUN2);
+                       }
+               }
+               else if(emsg == EMsg.UNUN_END){
+                       yukkuri.tweet(M.UNUN_END1);
+               }
+               else if(emsg == EMsg.UNUN_SMELL){
+                       yukkuri.tweet(M.UNUN_SPELL1);
+               }
 
 
        }
index 250a1f5..24c8a6b 100644 (file)
@@ -4,7 +4,7 @@
                        "maxYukkuri":100,
                        "yukkuri":100,
                        "hungry":0,
-                       "unun2":0,
+                       "unun":0,
                        "sleep":0,
                        "stress":0,
                        "int":0,
index 5f40919..217e4eb 100644 (file)
@@ -10,6 +10,13 @@ M.DEAD1 = "もっとゆっくりしたかった…";
 M.EAT1 = "む~しゃむ~しゃ!\nそれなり~";
 M.EAT2 = "はふっはふっ!\nめっちゃうま!";
 M.EAT3 = "む~しゃむ~しゃ\nしあわせー";
+M.UNUN1 = "すーぱうんうんたーいむ!\nはじまるよ!";
+M.UNUN2 = "うんうんするよーー!!";
+M.UNUN3 = "うんうんあげるから\nよろこんでたべてねっ!!";
+M.UNUN_END1 = "すっきりー!";
+M.SEARCH_FOOD1 = "ゆゆ??\nたべものさん\nはっけんなのぜ!";
+M.UNUN_SPELL1 = "うんうんくさい!";
+
 
 M.LABEL_YUKKURI = "ゆっくり";
 M.LABEL_HUNGRY = "空腹";
diff --git a/main.js b/main.js
index aa4cbb5..2fecbba 100644 (file)
--- a/main.js
+++ b/main.js
@@ -23,6 +23,7 @@ var HUNGRY_MAX = 100;
 var EResPath = {
        YUKKURI_BASE : './data/yukkuri_base.png',
        YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
+       YUKKURI_UNUN : './data/unun.png',
        YUKKURI_SHADOW : './data/shadow.png',
        MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
        MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
@@ -87,6 +88,10 @@ var EAction = {
        MOVE_TO_EAT_START: 10,
        MOVE_TO_EAT_UNDERWAY: 11,
        MOVE_TO_COMMAND: 12,
+       UNUN_START : 13,
+       UNUN_WAIT : 14,
+       UNUN_SMELL_START : 15,
+       UNUN_SMELL_WAIT : 16,
        NONE: 9999
 };
 var EDirection = {
@@ -99,6 +104,10 @@ var EMsg = {
        EAT: 2,
        GET_UP: 3,
        DEAD: 4,
+       UNUN: 5,
+       UNUN_END: 6,
+       UNUN_SMELL_START: 7,
+       SEARCH_FOOD: 8,
 };
 include("./lang/ja.js");
 window.onload = function(){
@@ -147,11 +156,19 @@ window.onload = function(){
                act : function(){
                        this.observe();
                        switch(this.status){
+                               case EAction.WAIT:
+
+                               break;
                                case EAction.THINK:
                                        if(this.yukkuri.age%2 === 0){
-                                               this.yukkuri.param.yukkuri --;
-                                               this.yukkuri.changeFace();
-                                               this.search();
+                                               if(this.yukkuri.getUnun() >= 80){
+                                                       this.setStatus(EAction.UNUN_START);
+                                               }else{
+                                                       // this.yukkuri.param.yukkuri -= 1;
+                                                       this.yukkuri.changeFace();
+                                                       this.search();
+                                               }
+
                                        }
                                break;
                                case EAction.MOVE_TO_EAT_START:
@@ -174,9 +191,17 @@ window.onload = function(){
                                break;
                                case EAction.EAT_WAIT:
                                break;
+                               case EAction.UNUN_START:
+                                       this.unun_start();
+                               break;
+                               case EAction.UNUN_WAIT:
+                               break;
                                case EAction.MOVE_TO_COMMAND:
                                        this.move_to_command();
                                break;
+                               case EAction.UNUN_SMELL_START:
+                                       this.unun_smell_start();
+                               break;
                        }
                },
 
@@ -204,8 +229,8 @@ window.onload = function(){
                                        this.yukkuri.vy = 0;
                                }else{
                                        // this.isMoving = true;
-                                       var xpos = 150 - (retryCounter * 10);
-                                       var ypos = 150 - (retryCounter * 10);
+                                       var xpos = 150 + rand(40) - (retryCounter * 10);
+                                       var ypos = 150 + rand(40) - (retryCounter * 10);
                                        if(rand(8) === 0){
                                                this.yukkuri.vx = 0;
                                                this.yukkuri.vy = -ypos;
@@ -258,6 +283,8 @@ window.onload = function(){
                                                        this.yukkuri.reverse();
                                                        this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
                                                        mangMsg.output(this.yukkuri,EMsg.WALK);
+                                                       //うんうんくさい対策
+                                                       this.targetNode = null;
                                                }else{
                                                        // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
                                                        this.walk(retryCounter+1);
@@ -301,18 +328,38 @@ window.onload = function(){
                        });
 
                },
+               unun_start: function(){
+                       new UnunEvent({
+                               "action": this,
+                               "myYukkuri": this.yukkuri
+                       });
+               },
+               unun_smell_start: function(){
+                       new UnunSmellEvent({
+                               "action": this,
+                               "myYukkuri": this.yukkuri
+                       });
+               },
                move_to_command: function(){
 
                },
                search : function(){
                        var nodes = ctl.getObjs();
-                       // l = game.rootScene.childNodes.length;
-                       // l = game.rootScene.childNodes.length;
                        l = nodes.length;
-                       // for (var i = 0;  i < l; i++) {
+                       var ununFlg = false;
+
                        for (var key in nodes) {
                                var node = nodes[key];
-                               if (node instanceof Food) {
+                               if (!ununFlg
+                                       && node instanceof Unun
+                                       && !(this.targetNode instanceof Unun)
+                                       && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
+                                       ununFlg = true;
+                                       this.targetNode = node;
+                                       this.setStatus(EAction.UNUN_SMELL_START);
+                                       return;
+                               }
+                               else if (node instanceof Food) {
                                        if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
 
                                                //A yukkuri to go to the food area
@@ -347,6 +394,88 @@ window.onload = function(){
                        };
                }
        });
+       var UnunEvent = enchant.Class.create(Event,{
+               initialize: function (_data){
+                       this.data = _data;
+                       this.yukkuri = _data.myYukkuri;
+                       this.action = _data.action;
+                       this.action.setStatus(EAction.UNUN_WAIT);
+                       mangMsg.output(this.yukkuri, EMsg.UNUN);
+                       this.yukkuri.setFaceImage(EFace.HAPPY2);
+                       var sec = FPS * 3;
+
+                       this.yukkuri.wait(sec, {
+                               "onactionstart": this.onactionstart(this),
+                               "onactiontick": this.onactiontick(this),
+                               "onactionend": this.onactionend(this)
+                       });
+               },
+               onactionstart:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                       };
+               },
+               onactiontick:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                       };
+               },
+               onactionend:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                               self.yukkuri.unun();
+                               self.action.setStatus(EAction.WAIT);
+                               mangMsg.output(self.yukkuri, EMsg.UNUN_END);
+                               new WaitEvent({
+                                       "waitframe": FPS * 1.5,
+                                       "action": self.action,
+                                       "myYukkuri": self.yukkuri
+                               });
+                       };
+               }
+       });
+       var WaitEvent = enchant.Class.create(Event,{
+               initialize: function (_data){
+                       this.data = _data;
+                       this.yukkuri = _data.myYukkuri;
+                       this.action = _data.action;
+                       this.waitframe = _data.waitframe;
+                       this.yukkuri.wait(this.waitframe, {
+                               "onactionstart": this.onactionstart(this),
+                               "onactiontick": this.onactiontick(this),
+                               "onactionend": this.onactionend(this)
+                       });
+               },
+               onactionend:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                               self.action.setStatus(EAction.THINK);
+                       };
+               }
+       });
+       var UnunSmellEvent = enchant.Class.create(Event,{
+               initialize: function (_data){
+                       this.data = _data;
+                       this.yukkuri = _data.myYukkuri;
+                       this.action = _data.action;
+                       this.action.setStatus(EAction.UNUN_SMELL_WAIT);
+                       mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
+                       this.yukkuri.setFaceImage(EFace.CRY1);
+                       var sec = FPS * 3;
+                       this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
+                       this.yukkuri.wait(sec, {
+                               "onactionstart": this.onactionstart(this),
+                               "onactiontick": this.onactiontick(this),
+                               "onactionend": this.onactionend(this)
+                       });
+               },
+               onactionend:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                               self.action.setStatus(EAction.THINK);
+                       };
+               }
+       });
 
        var EatEvent = enchant.Class.create(Event,{
                initialize: function (_data){
@@ -427,7 +556,6 @@ window.onload = function(){
                onactionstart:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               console.log("moveEvent onactionstart");
                                self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
                        };
                },
@@ -504,7 +632,6 @@ window.onload = function(){
                        //一つにつきgiveの値分、hunguryを減少させられる
                        this.give = 40;
                        this.amount = 3;
-                       // backgroundMap.addChild(this);
                        foodGroup.addChild(this);
                        this.addEventListener('enterframe', function(){
                                if(this.amount <= 0){
@@ -519,6 +646,16 @@ window.onload = function(){
                        return this.give;
                }
        });
+       var Unun = enchant.Class.create(ObjSprite,{
+               initialize: function (x, y){
+                       this.classname = "Unun";
+                       ObjSprite.call(this,32,32);
+                       this.image = game.assets[EResPath.YUKKURI_UNUN];
+                       this.x = x;
+                       this.y = y;
+                       backgroundMap.addChild(this);
+               }
+       });
        var Okazari = enchant.Class.create(enchant.Sprite,{
                initialize: function(){
                        this.classname = "Okazari";
@@ -550,8 +687,10 @@ window.onload = function(){
                },
                runEnterframe:function(){
                        this.act();
+                       if(this.isDead())return;
                        this.runYukkuri();
                        this.runHungry();
+                       this.runUnun();
                        this.runSleep();
                },
                reverse:function(){
@@ -602,6 +741,12 @@ window.onload = function(){
                        // this.face.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
                        // this.hear.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
                },
+               getWidth: function(){
+                       return this.width;
+               },
+               getHeight: function(){
+                       return this.height;
+               },
                getX: function(){
                        return this.imgGroup.x;
                },
@@ -644,6 +789,10 @@ window.onload = function(){
                        if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
                        if(this.param.hungry >= 100)this.param.hungry = 100;
                },
+               runUnun: function(){
+                       if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
+                       if(this.param.unun >= 100)this.param.unun = 100;
+               },
                runSleep: function(){
                        if(!this.isSleeping){
                                if(this.age%100 === 0 && this.age !== 0)this.param.sleep++;
@@ -694,6 +843,13 @@ window.onload = function(){
                isKuhuku: function(){
                        return this.param.hungry >= 40;
                },
+               getYukkuri: function(){
+                       return this.param.yukkuri;
+               },
+               setYukkuri: function(yukkuri){
+                       this.param.yukkuri = yukkuri;
+                       if(this.param.yukkuri < 0)this.param.yukkuri = 0;
+               },
                getHungry: function(){
                        return this.param.hungry;
                },
@@ -701,9 +857,27 @@ window.onload = function(){
                        this.param.hungry = hungry;
                        if(this.param.hungry < 0)this.param.hungry = 0;
                },
+               getUnun: function(){
+                       return this.param.unun;
+               },
+               setUnun: function(unun){
+                       this.param.unun = unun;
+                       if(this.param.unun < 0)this.param.unun = 0;
+               },
+
                eat:function(food){
                        food.amount--;
                        this.setHungry(this.param.hungry - food.getGive());
+                       this.setUnun(this.getUnun() + food.getGive() / 4);
+                       this.setYukkuri(this.getYukkuri() + 5);
+               },
+               unun:function(){
+                       if(this.direction == EDirection.RIGHT){
+                               new Unun(this.getX(), this.getY() + this.getHeight()/5 );
+                       }else{
+                               new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
+                       }
+                       this.setUnun(0);
                },
                setBodyImage: function(ebody){
                        var path = this.bodyStatus[ebody];