OSDN Git Service

add is sleeping to action
authornagomi <nagomi@192.168.1.23>
Fri, 20 Sep 2013 08:47:04 +0000 (17:47 +0900)
committernagomi <nagomi@192.168.1.23>
Fri, 20 Sep 2013 08:47:04 +0000 (17:47 +0900)
main.js

diff --git a/main.js b/main.js
index 72c3440..d7ccf89 100644 (file)
--- a/main.js
+++ b/main.js
@@ -52,6 +52,7 @@ var EAction = {
        THINK : 4,
        WALK : 5,
        DEAD: 6,
+       MOVE: 7
 };
 var EDirection = {
        LEFT : 0,
@@ -86,11 +87,17 @@ window.onload = function(){
                        this.yukkuri = yukkuri;
                        this.isMoving = false;
                },
-               act : function(){
-                       // console.log(this.yukkuri);
+               observe: function(){
                        if(this.yukkuri.isDead()){
                                this.status = EAction.DEAD;
                        }
+                       if(this.yukkuri.isSleep()){
+                               this.status = EAction.SLEEP;
+                       }
+
+               },
+               act : function(){
+                       this.observe();
                        switch(this.status){
                                case EAction.THINK:
                                        // this.status = EAction.WALK;
@@ -99,15 +106,24 @@ window.onload = function(){
                                                this.search();
                                        }
                                break;
+                               case EAction.MOVE:
+                                       this.move();
+                               break;
                                //Random Walk
                                case EAction.WALK:
                                        this.walk(0);
                                break;
+                               case EAction.SLEEP:
+                                       this.sleep();
+                               break;
                                case EAction.DEAD:
                                        this.dead();
                                break;
                        }
                },
+               move : function(){
+
+               },
                walk : function(retryCounter){
                        if(retryCounter > 15){
                                retryCounter = 0;
@@ -185,6 +201,19 @@ window.onload = function(){
                                }
                        }
                },
+               sleep: function(){
+                       var yukkuri = this.yukkuri;
+
+                       if(yukkuri.isSleeping){
+                               if(yukkuri.age%10 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
+                               if(yukkuri.param.sleep <= 0){
+                                       yukkuri.param.sleep = 0;
+                                       yukkuri.isSleeping = false;
+                                       yukkuri.tweet("ゆっくりおきるよ!");
+                                       this.status = EAction.THINK;
+                               }
+                       }
+               },
                dead : function(){
                        this.yukkuri.tweet("もっとゆっくりしたかった…");
                        this.yukkuri.imgBody.tl.clear();
@@ -196,20 +225,32 @@ window.onload = function(){
                        // this.yukkuri.imgGroup.tl.removeFromScene();
                },
                search : function(){
-                       this.status =  EAction.WALK;
                        if(true)return;
                        for (var i = 0, l = game.rootScene.childNodes.length; i < l; i++) {
                                var node = game.rootScene.childNodes[i];
                                if (node instanceof Food) {
 
                                        if(this.yukkuri.within(node, this.yukkuri.range)){
-                                               // console.log("yes:");
+                                               //A yukkuri to go to the food area
+                                               this.status = EAction.MOVE;
+                                               new MoveEvent({
+                                                       "type": 'food',
+                                                       "targetNode": node,
+                                                       "myYukkuri": this.yukkuri
+                                               });
                                        }else{
                                                // console.log("no:");
                                        }
                                }
                        }
+                       this.status =  EAction.WALK;
+               }
+       });
+       var MoveEvent = enchant.Class.create({
+               initialize: function (dataObj){
+                       this.move
                }
+
        });
        var Food = enchant.Class.create(enchant.Sprite,{
                initialize: function (type, x, y){
@@ -242,6 +283,7 @@ window.onload = function(){
                        this.image = game.assets[EResPath.YUKKURI_BASE];
                        this.direction = EDirection.RIGHT;
                        this.addEventListener('enterframe', this.runEnterframe);
+                       this.isSleeping = false;
                },
                runEnterframe:function(){
                        this.runYukkuri();
@@ -311,6 +353,19 @@ window.onload = function(){
                        if(this.age%100 === 0 && this.age !== 0)this.param.hungry++;
                        if(this.param.hungry >= 100)this.param.hungry = 100;
                },
+               runSleep: function(){
+                       if(!this.isSleeping){
+                               if(this.age%100 === 0 && this.age !== 0)this.param.sleep++;
+                               if(this.param.sleep >= 100){
+                                       this.param.sleep = 100;
+                                       this.isSleeping = true;
+                               }
+
+                       }
+               },
+               isSleep: function(){
+                       return this.isSleeping;
+               },
                isDead: function(){
                        return this.param.yukkuri <= 0;
                },