OSDN Git Service

yukkuri act to add sleep and food search
authorなごみ <nagoling@gmail.com>
Fri, 20 Sep 2013 15:02:08 +0000 (00:02 +0900)
committerなごみ <nagoling@gmail.com>
Fri, 20 Sep 2013 15:02:08 +0000 (00:02 +0900)
main.js

diff --git a/main.js b/main.js
index d7ccf89..5ab849a 100644 (file)
--- a/main.js
+++ b/main.js
@@ -86,6 +86,7 @@ window.onload = function(){
                        // this.status = EAction.EAT;
                        this.yukkuri = yukkuri;
                        this.isMoving = false;
+                       this.moveEvent = null;
                },
                observe: function(){
                        if(this.yukkuri.isDead()){
@@ -122,7 +123,7 @@ window.onload = function(){
                        }
                },
                move : function(){
-
+                       this.moveEvent.run();
                },
                walk : function(retryCounter){
                        if(retryCounter > 15){
@@ -205,12 +206,14 @@ window.onload = function(){
                        var yukkuri = this.yukkuri;
 
                        if(yukkuri.isSleeping){
-                               if(yukkuri.age%10 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
+                               if(yukkuri.age%4 === 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;
+                                       yukkuri.imgBody.tl.resume();
+                                       yukkuri.imgGroup.tl.resume();
                                }
                        }
                },
@@ -225,21 +228,26 @@ window.onload = function(){
                        // this.yukkuri.imgGroup.tl.removeFromScene();
                },
                search : function(){
-                       if(true)return;
-                       for (var i = 0, l = game.rootScene.childNodes.length; i < l; i++) {
-                               var node = game.rootScene.childNodes[i];
+                       var nodes = ctl.objArray;
+                       // l = game.rootScene.childNodes.length;
+                       // l = game.rootScene.childNodes.length;
+                       l = nodes.length;
+                       for (var i = 0;  i < l; i++) {
+                               var node = nodes[i];
+                                       console.log("name:"+node.classname);
                                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({
+                                               this.moveEvent = new MoveEvent({
                                                        "type": 'food',
                                                        "targetNode": node,
                                                        "myYukkuri": this.yukkuri
                                                });
+                                               return;
                                        }else{
-                                               // console.log("no:");
+                                               console.log("no:");
                                        }
                                }
                        }
@@ -247,13 +255,35 @@ window.onload = function(){
                }
        });
        var MoveEvent = enchant.Class.create({
-               initialize: function (dataObj){
-                       this.move
-               }
+               initialize: function (_data){
+                       this.data = _data;
+                       var yukkuri = this.data.myYukkuri;
+                       var node = this.data.targetNode;
+                       //food distance
+                       if(this.data.type == "food"){
+                               yukkuri.vx = node.x - yukkuri.getX();
+                               yukkuri.vy = node.y - yukkuri.getY();
+                               var frame = 150;
+                               yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame);
+                               
+                               yukkuri.addEventListener(enchant.Event.ACTION_END, function(evt) {
+                                       console.log("end");
+                               });
+
+                               yukkuri.tweet("ゆゆ??\nたべものさんはっけんなのぜ!");
+                       }
+               },
+               run: function(){
+                       if(this.data.type == "food"){
+
+                       }
 
+               }
        });
+
        var Food = enchant.Class.create(enchant.Sprite,{
                initialize: function (type, x, y){
+                       this.classname = "Food";
                        enchant.Sprite.call(this,16,16);
                        this.image = game.assets[EResPath.OBJECT];
                        this.frame = 15;
@@ -261,10 +291,12 @@ window.onload = function(){
                        this.y = y;
                        // this.moveTo(180, 252);
                        backgroundMap.addChild(this);
+                       ctl.objArray.push(this);
                }
        });
        var Okazari = enchant.Class.create(enchant.Sprite,{
                initialize: function(){
+                       this.classname = "Okazari";
                        enchant.Sprite.call(this, 64, 64);
                        this.image = game.assets[EResPath.OKAZARI];
                        this.x = -CHARA_WIDTH / 2;
@@ -273,6 +305,7 @@ window.onload = function(){
        });
        var Yukkuri = enchant.Class.create(enchant.Sprite,{
                initialize: function(x, y){
+                       this.classname = "Yukkuri";
                        this.imgGroup = new Group();
                        this.imgBody = new Group();
                        enchant.Sprite.call(this, 64, 64);
@@ -288,6 +321,7 @@ window.onload = function(){
                runEnterframe:function(){
                        this.runYukkuri();
                        this.runHungry();
+                       this.runSleep();
                },
                reverse:function(){
                        if(this.direction == EDirection.RIGHT){
@@ -303,8 +337,31 @@ window.onload = function(){
                moveTo:function(x, y, time){
                        this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
                },
-               moveBy:function(x, y, time){
-                       this.imgGroup.tl.moveBy(x, y, time, enchant.Easing.SIN_EASEINOUT);
+               moveBy:function(x, y, time, eventFunctions){
+                       // this.imgGroup.tl.moveBy(x, y, time, enchant.Easing.SIN_EASEINOUT);
+                       var self = this;
+                       console.log("moveby");
+                       if(eventFunctions !== undefined){
+                               // for(var func in eventFunctions){
+                               //      eventFunctions[func];
+                               // }
+                       }
+                               this.imgGroup.tl.tween({
+                                       x: function() {
+                                               return self.imgGroup.x + x;
+                                       },
+                                       y: function() {
+                                               return self.imgGroup.y + y;
+                                       },
+                                       time: time,
+                                       easing: enchant.Easing.SIN_EASEINOUT,
+                                       "onactionstart": function(e){
+                                               console.log("action start");
+                                       },
+                                       "onactionend": function(e){
+                                               console.log("actionenddd");
+                                       }
+                               });
 
                },
                act: function(){
@@ -317,6 +374,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();
                },
+               getX: function(){
+                       return this.imgGroup.x;
+               },
+               getY: function(){
+                       return this.imgGroup.y;
+               },
                moveX: function(x){
                        this.imgGroup.x += x;
                        // this.x += x;
@@ -359,6 +422,9 @@ window.onload = function(){
                                if(this.param.sleep >= 100){
                                        this.param.sleep = 100;
                                        this.isSleeping = true;
+                                       this.tweet("zzz...zzz...zzz...");
+                                       this.imgBody.tl.pause();
+                                       this.imgGroup.tl.pause();
                                }
 
                        }
@@ -376,6 +442,7 @@ window.onload = function(){
        var Marisa = enchant.Class.create(Yukkuri,{
                initialize: function(x, y){
                        Yukkuri.call(this,x,y);
+                       this.classname = "Marisa";
 
 
                        // var xml = this.loadParamsXML("./data/marisa/params.xml");
@@ -412,6 +479,7 @@ window.onload = function(){
                        this.imgGroup.y = y;
                        this.animation();
                        this.action = new Action(this);
+                       ctl.objArray.push(this);
 
                }
        });
@@ -420,6 +488,7 @@ window.onload = function(){
                        // this.runEnterframe = function(){
                        // },
                        Marisa.call(this, x, y);
+                       this.classname = "Player";
                        ctl.setPlayer(this);
                        // this.removeEventListener('enterframe',this.runEnterframe);
                        this.addEventListener('enterframe', function(){