OSDN Git Service

add to declare place event.
authornagoling <>
Tue, 8 Oct 2013 06:24:05 +0000 (15:24 +0900)
committernagomi <nagomi@192.168.1.23>
Tue, 8 Oct 2013 06:24:05 +0000 (15:24 +0900)
data/command.png
init.js
lang/ja.js
main.js

index 9cd8c5c..8eaecd8 100644 (file)
Binary files a/data/command.png and b/data/command.png differ
diff --git a/init.js b/init.js
index 5520868..06314d9 100644 (file)
--- a/init.js
+++ b/init.js
@@ -15,6 +15,8 @@ function guid() {
        };
        return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
 }
+
+
 /** 一回のタップで発生するエフェクトの数 */
 var EFFECT_NUM = 1;
 
index d28c4b6..b97dad4 100644 (file)
@@ -17,8 +17,10 @@ M.UNUN_END1 = "すっきりー!";
 M.SEARCH_FOOD1 = "ゆゆ??\nたべものさん\nはっけんなのぜ!";
 M.UNUN_SPELL1 = "うんうんくさい!";
 M.EAT_FAILED1 = "どぼじで\nたべものさん\nないのおおおおお!?";
-M.GREETING1 = "まりさはまりさだよ!\nゆっくりしていってね!";
-M.GREETING2 = "ゆっくりしていってね!";
+M.SAY_HELLO1 = "まりさはまりさだよ!\nゆっくりしていってね!";
+M.SAY_HELLO2 = "ゆっくりしていってね!";
+M.TARGETING_EAT1 = "ゆゆ??\nたべものさん\nはっけんなのぜ!";
+M.DECLARE_PLACE1 = "ここをまりさの\nゆっくりぷれいすにするよ!";
 
 
 M.LABEL_YUKKURI = "ゆっくり";
diff --git a/main.js b/main.js
index 6a12e67..1ed5b20 100644 (file)
--- a/main.js
+++ b/main.js
@@ -104,6 +104,11 @@ var EAction = {
        COMMUNICATE_START : 19,
        COMMUNICATE_WAIT: 20,
        COMMUNICATE_RECV: 21,
+       MOVE_TO_PLACE_START_HOMELESS: 22,
+       MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
+       DECLARE_PLACE_HOMELESS: 24,
+       MOVE_TO_HUNT_START: 25,
+       THINK_SCHEDULE: 26,
        NONE: 9999
 };
 var EDirection = {
@@ -121,7 +126,9 @@ var EMsg = {
        UNUN_SMELL_START: 7,
        SEARCH_FOOD: 8,
        EAT_FAILED: 9,
-       GREETING: 10,
+       SAY_HELLO: 10,
+       TARGETING_EAT : 11,
+       DECLARE_PLACE: 12,
 };
 var EWalkAnimation = {
        START: 0,
@@ -155,7 +162,6 @@ window.onload = function(){
        //init game
        var def = new Object();
        var foodGroup = new Group();
-       // var placeGroup = new Group();
        var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
        var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
        var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
@@ -213,7 +219,8 @@ window.onload = function(){
                                                }
                                                else if(this.yukkuri.getUnun() >= 80){
                                                        this.setStatus(EAction.UNUN_START);
-                                               }else{
+                                               }
+                                               else{
                                                        // this.yukkuri.param.yukkuri -= 1;
                                                        this.yukkuri.changeFace();
                                                        this.search();
@@ -261,6 +268,12 @@ window.onload = function(){
                                break;
                                case EAction.COMMUNICATE_RECV:
                                break;
+                               case EAction.MOVE_TO_PLACE_START_HOMELESS:
+                                       this.move_to_place_start_homeless();
+                               break;
+                               case EAction.DECLARE_PLACE_HOMELESS:
+                                       this.declare_place_homeless();
+                               break;
 
                        }
                        this.yukkuri.reverse();
@@ -390,13 +403,27 @@ window.onload = function(){
                        });
                },
                communicate_start:function(){
-                       new ComFirstSendEvent({
+                       new ComSayHelloSendEvent({
                                "type": 'greeting',
                                "targetNode": this.targetNode,
                                "action": this,
                                "myYukkuri": this.yukkuri
                        });
                },
+               move_to_place_start_homeless:function(){
+                       new MoveToPlaceStartHomelessEvent({
+                               "targetNode": this.targetNode,
+                               "action": this,
+                               "myYukkuri": this.yukkuri
+                       });
+               },
+               declare_place_homeless:function(){
+                       new DeclarePlaceHomelessEvent({
+                               "targetNode": this.targetNode,
+                               "action": this,
+                               "myYukkuri": this.yukkuri
+                       });
+               },
                move_to_command: function(){
 
                },
@@ -436,16 +463,20 @@ window.onload = function(){
                                                return;
                                        }
                                }
+                               else if(node instanceof Place){
+                                       if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
+                                               console.log("place!");
+                                               this.targetNode = node;
+                                               this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
+                                               return;
+                                       }
+                               }
                        }
                        this.status =  EAction.WALK;
                }
        });
        var Event = enchant.Class.create({
                initialize: function (_data){
-                       this.progress = null;
-               },
-               setProgress: function(progress){
-                       this.progress = progress;
                },
                onactionstart:function(self){
                        return function(e){
@@ -522,21 +553,9 @@ window.onload = function(){
                        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;
@@ -665,7 +684,8 @@ window.onload = function(){
                onactionstart:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
+                               mangMsg.output(EMsg.TARGETING_EAT);
+                               // self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
                        };
                },
                onactiontick:function(self){
@@ -718,18 +738,17 @@ window.onload = function(){
                }
        });
        /**
-        * First contact to send communication .
+        * Say hello contact to send communication .
         */
-       var ComFirstSendEvent = enchant.Class.create(Event,{
+       var ComSayHelloSendEvent = enchant.Class.create(Event,{
                initialize: function (_data){
                        this.data = _data;
                        this.yukkuri = _data.myYukkuri;
                        this.targetYukkuri = _data.targetNode;
                        this.action = _data.action;
                        this.action.setStatus(EAction.COMMUNICATE_WAIT);
-                       this.setProgress("start");
-                       mangMsg.output(this.yukkuri, EMsg.GREETING);
-                       // this.targetYukkuri.recvCommunication(this.yukkuri, this);
+
+                       mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
 
                        this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
                        this.targetYukkuri.tlPause();
@@ -748,32 +767,27 @@ window.onload = function(){
                onactiontick:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               self.setProgress("tick");
                        };
                },
                onactionend:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               self.setProgress("end");
-                               new ComFirstRecvEvent({
+                               new ComSayHelloRecvEvent({
                                        "type": 'greeting',
                                        "targetNode": self.yukkuri,
                                        "action": self.targetYukkuri.action,
                                        "myYukkuri": self.targetYukkuri
                                });
-
-                               // self.targetYukkuri.recvCommunication(self.yukkuri, self);
                        };
                }
        });
-       var ComFirstRecvEvent = enchant.Class.create(Event,{
+       var ComSayHelloRecvEvent = enchant.Class.create(Event,{
                initialize: function (_data){
                        this.data = _data;
                        this.yukkuri = _data.myYukkuri;
                        this.targetYukkuri = _data.targetNode;
                        this.action = _data.action;
-                       this.setProgress("start");
-                       mangMsg.output(this.yukkuri, EMsg.GREETING);
+                       mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
                        this.yukkuri.addAddress(this.targetYukkuri);
                        this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
 
@@ -786,25 +800,77 @@ window.onload = function(){
                onactiontick:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               self.setProgress("tick");
                        };
                },
                onactionend:function(self){
                        return function(e){
                                if(typeof e === "undefined")return;
-                               self.setProgress("end");
                                self.action.setStatus(EAction.THINK);
 
                                self.yukkuri.action.setStatus(EAction.THINK);
                                self.yukkuri.animation();
                                self.targetYukkuri.action.setStatus(EAction.THINK);
                                self.targetYukkuri.animation();
-                               // self.targetYukkuri.recvCommunication(self.yukkuri, self);
                        };
                }
        });
+       var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
+               initialize: function (_data){
+                       this.data = _data;
+                       this.yukkuri = this.data.myYukkuri;
+                       this.action = this.data.action;
+
+                       var yukkuri = this.yukkuri;
+                       var node = this.data.targetNode;
+
+                       this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
+                       yukkuri.vx = node.x + node.width /2  - yukkuri.getX();
+                       yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
+                       var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
+                       var frame = distance + distance/5 + 1;
+                       yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
+                       yukkuri.reverse();
+
+                       yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
+                               "onactionend": this.onactionend(this)
+                       });
+               },
+               onactionend:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                               self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
+                               self.data = null;
+                               self.yukkuri = null;
+                               self.action = null;
+                       };
+               }
+       });
+       var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
+               initialize: function (_data){
+                       this.data = _data;
+                       this.yukkuri = _data.myYukkuri;
+                       this.place = _data.targetNode;
+                       this.action = _data.action;
+                       this.action.setStatus(EAction.WAIT);
+
 
+                       var sec = BASE_FPS * 3;
+                       this.yukkuri.declarePlace(this.place);
+                       this.place.setOwner(this.yukkuri);
+                       mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
 
+                       this.yukkuri.setFaceImage(EFace.NORMAL);
+                       this.yukkuri.wait(sec, {
+                               "onactionend": this.onactionend(this)
+                       });
+               },
+               onactionend:function(self){
+                       return function(e){
+                               if(typeof e === "undefined")return;
+                               self.action.setStatus(EAction.THINK);
+                       };
+               }
+       });
        var ObjSprite = enchant.Class.create(enchant.Sprite,{
                initialize: function (w, h){
                        enchant.Sprite.call(this, w, h);
@@ -848,12 +914,9 @@ window.onload = function(){
                        this.image = game.assets[EResPath.PLACE_TREE];
                        this.x = x - this.width / 2;
                        this.y = y - this.height / 2;
-                       // placeGroup.addChild(this);
                        backgroundMap.addChild(this);
-
+                       this.owner = null;
                        // this.addEventListener('enterframe', function(){
-
-
                        //      if(this.age%10 === 0 && this.age !== 0){
                        //              console.log("x/y " + this.x + "/" + this.y);
                        //      }
@@ -870,7 +933,12 @@ window.onload = function(){
                        //              this.y += 10;;
                        //      }
                        // });
-
+               },
+               setOwner: function(yukkuri){
+                       this.owner = yukkuri;
+               },
+               isOwner: function(){
+                       return this.owner !== null;
                }
        });
        var Unun = enchant.Class.create(ObjSprite,{
@@ -898,6 +966,17 @@ window.onload = function(){
                        this.yukkuri = yukkuri;
                        this.isGreeting = false;
                        this.greetingWaitFrame = 0;
+                       this.comMatrix = {
+                               "beginSayHello" : false,
+                               "sayHello" : false,
+                       };
+                       this.evtHash = {};
+               },
+               set:function(key, value){
+                       this.comMatrix[key] = value;
+               },
+               get:function(key){
+                       return this.comMatrix[key];
                }
        });
 
@@ -921,6 +1000,7 @@ window.onload = function(){
                        this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
                        this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
                        this.walkAnimationStatus = EWalkAnimation.END;
+                       this.place = null;
                },
                runEnterframe:function(){
                        this.act();
@@ -973,6 +1053,7 @@ window.onload = function(){
                },
                animation: function(){
                        if(this.walkAnimationStatus == EWalkAnimation.END){
+                               this.imgBody.y = 0;
                                this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
                                        "onactionstart": function(e){
                                                this.walkAnimationStatus = EWalkAnimation.START;
@@ -988,11 +1069,6 @@ window.onload = function(){
                        }else{
                                this.imgBody.tl.loop();
                        }
-                       // this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING)
-                       // this.imgBody.tl.moveByEx(0, 5, 10, enchant.Easing.SWING);
-                       // this.imgBody.tl.loop();
-                       // this.moveBy(0, -5, 10).moveBy(0, 5, 10).loop();
-
                },
                getWidth: function(){
                        return this.width;
@@ -1133,6 +1209,13 @@ window.onload = function(){
                                return false;
                        }
                },
+               declarePlace: function(place){
+                       this.place = place;
+               },
+               isPlace: function(){
+                       return this.place !== null;
+               },
+
                unun:function(){
                        if(this.direction == EDirection.RIGHT){
                                new Unun(this.getX(), this.getY() + this.getHeight()/5 );
@@ -1167,33 +1250,6 @@ window.onload = function(){
                                senderYukkuri.direction = EDirection.LEFT;
                        }
                },
-               // recvCommunication: function(senderYukkuri, event){
-               //      if(event instanceof ComFirstSendEvent){
-               //              if(event.progress == "start"){
-               //                      this.action.setStatus(EAction.COMMUNICATE_RECV);
-               //                      this.tlPause();
-               //                      this.syncDirection(senderYukkuri);
-
-               //              }
-               //              else if(event.progress == "end"){
-               //                      new ComFirstRecvEvent({
-               //                              "type": 'greeting',
-               //                              "targetNode": senderYukkuri,
-               //                              "action": this.action,
-               //                              "myYukkuri": this
-               //                      });
-               //              }
-               //      }
-               //      if(event instanceof ComFirstRecvEvent){
-               //              if(event.progress == "end"){
-               //                      senderYukkuri.action.setStatus(EAction.THINK);
-               //                      senderYukkuri.animation();
-               //                      this.action.setStatus(EAction.THINK);
-               //                      this.animation();
-               //              }
-               //      }
-
-               // },
                isCommunication: function(yukkuri){
                        if(this.addressBook[yukkuri.id] === undefined) return true;
                        if(this.addressBook[yukkuri.id].isGreeting) return false;
@@ -1203,6 +1259,7 @@ window.onload = function(){
                        this.addressBook[yukkuri.id] = new Address(yukkuri);
                },
                getAddress: function(yukkuri){
+                       if(this.addressBook[yukkuri.id] === undefined)return null;
                        return this.addressBook[yukkuri.id];
                },
                destruct: function(){
@@ -1296,23 +1353,21 @@ window.onload = function(){
                                this.act();
                                ///////////////////////////////////////////////
                                //Action pattern  debug
-                               // if(game.input.left){
-                               //      // this.changeFace(EResPath.MARISA_FACE_TIRED);
-                               //      this.moveX(-10);
-                               //      this.direction = EDirection.LEFT;
-                               // }
-                               // if(game.input.right){
-                               //      this.moveX(10);
-                               //      this.direction = EDirection.RIGHT;
-                               // }
-                               // if(game.input.up){
-                               //      this.moveY(-10);
-                               //      this.tweet("ゆっくりしていってね!");
-
-                               // }
-                               // if(game.input.down){
-                               //      this.moveY(10);
-                               // }
+                               if(game.input.left){
+                                       // this.changeFace(EResPath.MARISA_FACE_TIRED);
+                                       this.moveX(-10);
+                                       this.direction = EDirection.LEFT;
+                               }
+                               if(game.input.right){
+                                       this.moveX(10);
+                                       this.direction = EDirection.RIGHT;
+                               }
+                               if(game.input.up){
+                                       this.moveY(-10);
+                               }
+                               if(game.input.down){
+                                       this.moveY(10);
+                               }
                                ///////////////////////////////////////////////
                                // this.reverse();
                                // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
@@ -1382,7 +1437,8 @@ window.onload = function(){
                backgroundMap.addChild(foodGroup);
                // backgroundMap.addChild(placeGroup);
                var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
-               new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y);
+               new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
+               // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
                var touchX = 0;
 
                game.rootScene.addEventListener('touchstart', function (e) {