OSDN Git Service

add to face image for yukkuri
authornagoling <>
Thu, 26 Sep 2013 10:44:13 +0000 (19:44 +0900)
committernagomi <nagomi@192.168.1.23>
Thu, 26 Sep 2013 10:44:13 +0000 (19:44 +0900)
ctrl.js
main.js

diff --git a/ctrl.js b/ctrl.js
index 86026c9..fb52c2f 100644 (file)
--- a/ctrl.js
+++ b/ctrl.js
@@ -325,7 +325,36 @@ var MangLabel = enchant.Class.create({
 
        }
 });
+var MangMsg = enchant.Class.create({
+       initialize: function (ctl){
+               this.ctl = ctl;
+       },
+       output:function(yukkuri, emsg){
+               if(emsg == EMsg.WALK){
+                       if(rand(3)%3 === 0){
+                               yukkuri.tweet("ゆっ!ゆっ!\nゆっくりすすむよっ!");
+                       }
+                       else if(rand(3)%3 === 1){
+                               yukkuri.tweet("ゆっくり、ゆっくりー!");
+                       }
+                       else if(rand(3)%3 === 2){
+                               yukkuri.tweet("かもしかのようなあんよで\nゆっくりすすむのぜ!");
+                       }
+               }
+               else if(emsg == EMsg.EAT){
+                       if(rand(3)%3 === 0){
+                               yukkuri.tweet("む~しゃむ~しゃ!\nそれなり~");
+                       }
+                       else if(rand(3)%3 === 1){
+                               yukkuri.tweet("む~しゃむ~しゃ!\nめっちゃうま!");
+                       }
+                       else if(rand(3)%3 === 2){
+                               yukkuri.tweet("む~しゃむ~しゃ\nしあわせー");
+                       }
+               }
 
+       }
+});
 
 // var MangLabel = enchant.Class.create({
 //     initialize: function (ctl, menuBg){
diff --git a/main.js b/main.js
index e083038..b19c057 100644 (file)
--- a/main.js
+++ b/main.js
@@ -5,6 +5,7 @@ var ctl = null;
 var mangIcon = null;
 var mangTouch = null;
 var mangLabel = null;
+var mangMsg = null;
 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
 var net = new Net();
 //////////////////////////////////////
@@ -16,7 +17,7 @@ var CHARA_WIDTH = 64;
 var CHARA_HEIGHT = 64;
 var GAME_WIDTH = 800;
 var GAME_HEIGHT = 600;
-var FPS = 15;
+var FPS = 20;
 var HUNGRY_MAX = 100;
 
 var EResPath = {
@@ -38,7 +39,18 @@ var EResPath = {
        COMMAND : './data/command.png',
        OKAZARI : './data/okazari.png',
 };
-
+var EFace = {
+       NORMAL:0,
+       TIRED:1,
+       ANGRY:2,
+       CRY1:3,
+       CRY2:4,
+       EAT1:5,
+       EAT2:6,
+       HAPPY1:7,
+       HAPPY2:8,
+       SLEEP:9,
+};
 var ECommand = {
        WORLD_CURSOR: 0,
        WORLD_TARGET: 1,
@@ -75,7 +87,11 @@ var EDirection = {
        LEFT : 0,
        RIGHT: 1,
 };
-
+var EMsg = {
+       WALK: 0,
+       SLEEP: 1,
+       EAT: 2,
+};
 window.onload = function(){
        //init game
        var def = new Object();
@@ -122,7 +138,8 @@ window.onload = function(){
                        this.observe();
                        switch(this.status){
                                case EAction.THINK:
-                                       if(this.yukkuri.age%6 === 0){
+                                       if(this.yukkuri.age%2 === 0){
+                                               this.yukkuri.changeFace();
                                                this.search();
                                        }
                                break;
@@ -229,6 +246,7 @@ window.onload = function(){
                                                        this.isMoving = true;
                                                        this.yukkuri.reverse();
                                                        this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
+                                                       mangMsg.output(this.yukkuri,EMsg.WALK);
                                                }else{
                                                        // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
                                                        this.walk(retryCounter+1);
@@ -324,7 +342,10 @@ window.onload = function(){
                        this.food = _data.targetNode;
                        this.action = _data.action;
                        this.action.setStatus(EAction.EAT_WAIT);
-                       this.yukkuri.tweet("む~しゃむ~しゃ!");
+                       this.yukkuri.tweet("む~しゃむ~しゃ!それなり~");
+                       mangMsg.output(this.yukkuri, EMsg.EAT);
+                       this.yukkuri.setFaceImage(EFace.EAT2);
+                       // this.yukkuri.image = game.assets[EResPath.MARISA_];
 
                        // var sec = FPS * (this.yukkuri.param.hungry/10 + 3);
                        var sec = FPS * 3;
@@ -351,6 +372,7 @@ window.onload = function(){
                                if(typeof e === "undefined")return;
                                if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
                                        self.action.setStatus(EAction.THINK);
+                                       self.yukkuri.setFaceImage(EFace.NORMAL);
                                }else{
                                        self.action.setStatus(EAction.EAT_START);
                                }
@@ -498,8 +520,10 @@ window.onload = function(){
                initialize: function(x, y){
                        ObjSprite.call(this, 64, 64);
                        this.classname = "Yukkuri";
-                       this.imgGroup = new Group();
-                       this.imgBody = new Group();
+                       this.imgGroup = new SpriteGroup();
+                       this.imgBody = new SpriteGroup();
+                       this.imgGroup.id = guid();
+                       this.imgBody.id = guid();
                        this.x = -CHARA_WIDTH / 2;
                        this.y = -CHARA_HEIGHT / 2;
                        this.vx = 0;
@@ -581,9 +605,9 @@ window.onload = function(){
                        // this.shadow.y += y;
                        // this._tweet.y += y;
                },
-               changeFace: function(erespath){
-                       this.face.image = game.assets[erespath];
-               },
+               // changeFace: function(erespath){
+               //      this.face.image = game.assets[erespath];
+               // },
                loadParamsXML: function(url){
                        var http = new JKL.ParseXML( url );
                        return http.parse();
@@ -622,6 +646,23 @@ window.onload = function(){
 
                        }
                },
+               changeFace: function(){
+                       if(this.param.yukkuri >= 80){
+                               this.setFaceImage(EFace.HAPPY1);
+                       }
+                       else if(this.param.yukkuri >= 50){
+                               this.setFaceImage(EFace.NORMAL);
+                       }
+                       else if(this.param.yukkuri >= 30){
+                               this.setFaceImage(EFace.TIRED);
+                       }
+                       else if(this.param.yukkuri >= 10){
+                               this.setFaceImage(EFace.CRY1);
+                       }
+                       else if(this.param.yukkuri >= 1){
+                               this.setFaceImage(EFace.CRY2);
+                       }
+               },
                getRange: function(){
                        return this.param.range;
                },
@@ -665,18 +706,40 @@ window.onload = function(){
                        this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
                        this.shadow.x = 0 + this.x;
                        this.shadow.y = CHARA_HEIGHT / 16 + this.x;
+                       this.shadow.image._element.style.zIndex = 2;
+
+                       this._style.zIndex = 5;
 
                        this.face = new enchant.Sprite(64, 64);
                        this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
                        this.face.x = -CHARA_WIDTH / 2;
                        this.face.y = -CHARA_HEIGHT / 2;
+                       this.face._style.zIndex = 0;
+
+                       this.faceStatus ={};
+                       this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
+                       this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
+                       this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
+                       this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
+                       this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
+                       this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
+                       this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
+                       this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
+                       this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
+                       this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
+
 
                        this.hear = new enchant.Sprite(64, 64);
                        this.hear.image = game.assets[EResPath.MARISA_HEAR];
                        this.hear.x = -CHARA_WIDTH / 2;
                        this.hear.y = -CHARA_HEIGHT / 2;
+                       this.hear._style.zIndex = 0;
 
                        this.okazari = new Okazari();
+                       this.okazari.image._element.style.zIndex = 1;
+
+                       // this.imgGroup._style.zIndex = 1;
+
                        this.imgGroup.addChild(this.shadow);
                        this.imgBody.addChild(this);
                        this.imgBody.addChild(this.face);
@@ -685,6 +748,7 @@ window.onload = function(){
                        this.imgGroup.addChild(this.imgBody);
                        backgroundMap.addChild(this.imgGroup);
                        this._tweet = new TTweet(148, 64);
+                       this._tweet.image._element.style.zIndex = 20;
 
                        this.imgGroup.addChild(this._tweet);
                        this.imgGroup.x = x;
@@ -693,6 +757,10 @@ window.onload = function(){
                        this.action = new Action(this);
                        this.id = guid();
                        ctl.addObj(this);
+               },
+               setFaceImage: function(eface){
+                       var path = this.faceStatus[eface];
+                       this.face.image = game.assets[path];
                }
        });
        var Player = enchant.Class.create(Marisa,{
@@ -711,22 +779,22 @@ window.onload = function(){
 
                                ///////////////////////////////////////////////
                                //Action pattern for 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);
+                                       this.tweet("ゆっくりしていってね!");
+                               }
+                               if(game.input.down){
+                                       this.moveY(10);
+                               }
                                ///////////////////////////////////////////////
                                this.reverse();
                                // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
@@ -746,6 +814,7 @@ window.onload = function(){
        game.onload = function(){
                def.Food = Food;
                mangTouch = new MangTouch(ctl);
+               mangMsg = new MangMsg(ctl);
                ctl.setDefined(def);
                backgroundMap.image = game.assets[EResPath.MAP0];
                backgroundMap.loadData(_mapData);
@@ -806,6 +875,27 @@ window.onload = function(){
                //main frame
                        mangLabel.draw(player);
                });
+
+               this.addEventListener('enterframe', function(){
+                       //The priority processing of display instead of z-index
+                       backgroundMap.childNodes.sort(
+                               function(a,b){
+                                       if(typeof a.id === "undefined" && typeof b.id === "undefined"){
+                                               return 0;
+                                       }
+                                       else if(typeof a.id === "undefined"){
+                                               return -1;
+                                       }
+                                       else if(typeof b.id === "undefined"){
+                                               return 1;
+                                       }
+                                       if(a.y < b.y)return -1;
+                                       if(a.y > b.y)return 1;
+                                       return 0;
+                               }
+                       );
+               });
+
        };
        game.start();
 };