OSDN Git Service

add Reimu class
authornagoling <>
Thu, 31 Oct 2013 10:22:56 +0000 (19:22 +0900)
committernagomi <nagomi@192.168.1.23>
Thu, 31 Oct 2013 10:22:56 +0000 (19:22 +0900)
main.js

diff --git a/main.js b/main.js
index 3dcd6f3..80ae56a 100644 (file)
--- a/main.js
+++ b/main.js
@@ -32,7 +32,7 @@ var CHARA_WIDTH = 64;
 var CHARA_HEIGHT = 64;
 var GAME_WIDTH = 800;
 var GAME_HEIGHT = 600;
-var FPS = 40;
+var FPS = 20;
 var BASE_FPS = 20;
 var HUNGRY_MAX = 100;
 var MIN = BASE_FPS;
@@ -66,6 +66,26 @@ var EResPath = {
        PLAYER_BADGE : './data/system/player_badge.png',
        // PLACE_TREE : './data/system/rapture.png',
 };
+var EResPathReimu = {
+       getName: function(){
+               return "reimu";
+       },
+       FACE_NORMAL : './data/reimu/face_normal1.png',
+       FACE_TIRED : './data/reimu/face_tired1.png',
+       FACE_ANGRY : './data/reimu/face_angry1.png',
+       FACE_CRY1 : './data/reimu/face_cry1.png',
+       FACE_CRY2 : './data/reimu/face_cry2.png',
+       FACE_EAT1 : './data/reimu/face_eat1.png',
+       FACE_EAT2 : './data/reimu/face_eat2.png',
+       FACE_HAPPY1 : './data/reimu/face_happy1.png',
+       FACE_HAPPY2 : './data/reimu/face_happy2.png',
+       FACE_SLEEP : './data/reimu/face_sleep1.png',
+       HEAR : './data/reimu/hear1.png',
+       OKAZARI : './data/reimu/okazari.png',
+       SUB1 : './data/reimu/sub1.png',
+
+};
+
 var EFace = {
        NORMAL:0,
        TIRED:1,
@@ -304,6 +324,16 @@ window.onload = function(){
        game.fps = FPS;
        var _loadArr = [];
        var i=0;
+       var tmpName = EResPathReimu.getName();
+       i=0;
+       for(var _v in EResPathReimu){
+               if(typeof EResPathReimu[_v] === "function")continue;
+               EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
+               i++;
+       }
+       tmpName = null;
+
+       i=0;
        for(var _v in EResPath){
                _loadArr[i] = EResPath[_v];
                i++;
@@ -459,6 +489,7 @@ window.onload = function(){
                        if((date === EDate.MIDNIGHT || date === EDate.NIGHT)
                                && !this.yukkuri.isSleep()){
                                //sleep
+
                        }
                        else if(date === EDate.EVENING){
                                //QK
@@ -781,7 +812,7 @@ window.onload = function(){
                        }
 
 
-                       if(!yukkuri.isItemsMax()){
+                       if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
                                food = this.getNear(ESearch.FOOD, yukkuri);
                                if(food !== null){
                                        yukkuri.action.targetNode = food;
@@ -789,14 +820,15 @@ window.onload = function(){
                                        return;
                                }
                        }
-                       var searchYukkuri = this.getNear(ESearch.YUKKURI);
+                       var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
                        if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
+                               yukkuri.action.targetNode = searchYukkuri;
                                yukkuri.action.setStatus(EAction.COMMUNICATE_START);
                                return;
                        }
                        if(!yukkuri.isPlace()){
                                var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
-                               if(!searchYukkuri.isOwner()){
+                               if(searchYukkuri != null && !searchYukkuri.isOwner()){
                                        yukkuri.action.targetNode = searchYukkuri;
                                        yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
                                        return;
@@ -869,7 +901,11 @@ window.onload = function(){
                                        yukkuri.setFaceImage(EFace.NORMAL);
                                        yukkuri.tlResume();
                                        // self.action.setStatus(EAction.WAIT);
-                                       self.action.setStatus(EAction.THINK);
+                                       if(this.data.nextStatus !== undefined){
+                                               self.action.setStatus(this.data.nextStatus);
+                                       }else{
+                                               self.action.setStatus(EAction.THINK);
+                                       }
                                }
                        });
                }
@@ -1314,7 +1350,6 @@ window.onload = function(){
                        this.targetYukkuri = _data.targetNode;
                        this.action = _data.action;
                        this.action.setStatus(EAction.COMMUNICATE_WAIT);
-
                        mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
 
                        this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
@@ -1456,7 +1491,7 @@ window.onload = function(){
                                this.image = game.assets[EResPath.GRASS];
                                this.frame = 0;
                                this.give = 10;
-                               this.amount = 20;
+                               this.amount = 2;
                        }
                        this.x = x;
                        this.y = y;
@@ -1592,11 +1627,18 @@ window.onload = function(){
        var Okazari = enchant.Class.create(enchant.Sprite,{
                initialize: function(yukkuri){
                        this.classname = "Okazari";
-                       enchant.Sprite.call(this, 64, 64);
-                       this.image = game.assets[EResPath.OKAZARI];
+                       if(yukkuri.myCode === "REIMU"){
+                               enchant.Sprite.call(this, 80, 32);
+                               this.image = game.assets[EResPathReimu.OKAZARI];
+                               this.x = -CHARA_WIDTH / 2;
+                               this.y = 0;
+                       }else{
+                               enchant.Sprite.call(this, 64, 64);
+                               this.image = game.assets[EResPath.OKAZARI];
+                               this.x = -CHARA_WIDTH / 2;
+                               this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
+                       }
                        this.yukkuri = yukkuri;
-                       this.x = -CHARA_WIDTH / 2;
-                       this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
                },
                getWidth: function(){
                        return this.width;
@@ -2005,6 +2047,26 @@ window.onload = function(){
                clearSearchObject:function(){
                        this.searchObjectMang.clear()
                },
+               setFaceImage: function(eface){
+                       var path = this.faceStatus[eface];
+                       this.face.image = game.assets[path];
+               },
+               myScale: function(_scaleX, _scaleY){
+                       this.face.scale(_scaleX,_scaleY);
+                       if(this.myCode === "REIMU"){
+                               this.okazari.x = -CHARA_WIDTH / 2;
+                               this.okazari.x = -CHARA_WIDTH / 2 - CHARA_WIDTH / 8;
+                               this.okazari.y = -CHARA_HEIGHT / 3 - CHARA_HEIGHT/7;
+                       }else{
+                               this.okazari.x = -CHARA_WIDTH /2;
+                               this.okazari.y = -CHARA_HEIGHT / 2 - CHARA_HEIGHT/6;
+                       }
+
+                       this.okazari.scale(_scaleX,_scaleY);
+                       this.hear.scale(_scaleX,_scaleY);
+                       this.scale(_scaleX,_scaleY);
+                       this.shadow.scale(_scaleX, _scaleY);
+               },
                destruct: function(){
 
                }
@@ -2097,22 +2159,6 @@ window.onload = function(){
                        this.animation();
                        this.action = new Action(this);
                        ctl.addObj(this);
-                       // this.imgGroup.scale(_scaleX,_scaleX);
-                       // this.scale(scale,scale);
-               },
-               myScale: function(_scaleX, _scaleY){
-                       this.face.scale(_scaleX,_scaleY);
-                       this.okazari.x = -32;
-                       this.okazari.y = -32 - this.getWidth()/6;
-                       this.okazari.scale(_scaleX,_scaleY);
-                       this.hear.scale(_scaleX,_scaleY);
-                       this.scale(_scaleX,_scaleY);
-                       this.shadow.scale(_scaleX, _scaleY);
-
-               },
-               setFaceImage: function(eface){
-                       var path = this.faceStatus[eface];
-                       this.face.image = game.assets[path];
                }
        });
        var Player = enchant.Class.create(Marisa,{
@@ -2121,7 +2167,7 @@ window.onload = function(){
                        // },
                        Marisa.call(this, x, y, EGrow.ADULT);
                        this.classname = "Player";
-                       this.cmdQueue = [];
+                       this.cmdQue = [];
                        ctl.setPlayer(this);
                        // this.removeEventListener('enterframe',this.runEnterframe);
                        this.addEventListener('enterframe', function(){
@@ -2166,6 +2212,102 @@ window.onload = function(){
                        });
                }
        });
+       var Reimu = enchant.Class.create(Yukkuri,{
+               initialize: function(x, y, grow){
+                       Yukkuri.call(this,x,y, grow);
+                       this.classname = "Reimu";
+                       this.myCode = "REIMU";
+                       this.myName = "れいむ";
+
+                       // var xml = this.loadParamsXML("./data/marisa/params.xml");
+                       var json = net.load("./data/reimu/params.json");
+                       this.param = json.root.param;
+                       if(this.grow == EGrow.BABY){
+                               this.myName = "れいみゅ";
+                               this.param.range /= 4;
+                       }
+                       else if(this.grow == EGrow.CHILD){
+                               this.param.range /= 3;
+                       }
+                       else if(this.grow == EGrow.SUBADULT){
+                               this.param.range *= 0.8;
+                       }
+                       this.shadow = new enchant.Sprite(64, 64);
+                       this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
+                       this.shadow.x = 0 + this.x;
+                       this.shadow.y = this.getWidth() / 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[EResPathReimu.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] = EResPathReimu.FACE_NORMAL;
+                       this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
+                       this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
+                       this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
+                       this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
+                       this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
+                       this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
+                       this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
+                       this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
+                       this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
+
+
+                       this.hear = new enchant.Sprite(64, 64);
+                       this.hear.image = game.assets[EResPathReimu.HEAR];
+                       this.hear.x = -CHARA_WIDTH / 2;
+                       this.hear.y = -CHARA_HEIGHT / 2;
+
+                       this.sub1 = new enchant.Sprite(64, 64);
+                       this.sub1.image = game.assets[EResPathReimu.SUB1];
+                       this.sub1.x = -CHARA_WIDTH / 2;
+                       this.sub1.y = -CHARA_HEIGHT / 2;
+
+                       this.okazari = new Okazari(this);
+
+                       // this.imgGroup._style.zIndex = 1;
+
+
+                       this.imgGroup.addChild(this.shadow);
+                       this.imgBody.addChild(this.okazari);
+                       this.imgBody.addChild(this);
+                       this.imgBody.addChild(this.face);
+                       this.imgBody.addChild(this.hear);
+                       this.imgBody.addChild(this.sub1);
+                       this.myScale(this.myScaleX, this.myScaleY)
+                       if(this instanceof Player){
+                               // this.myScaleX = 0.5;
+                               // this.myScaleY = 0.5;
+
+                               this.budge = new enchant.Sprite(16, 16);
+                               this.budge.image = game.assets[EResPath.PLAYER_BADGE];
+                               this.imgBody.addChild(this.budge);
+                               this.budge.x -= this.getWidth()/2;
+                               this.budge.y -= this.getHeight()/2;
+                               this.budge.scale(this.myScaleX, this.myScaleX);
+                       }
+                       this.imgGroup.width = this.getWidth();
+                       this.imgGroup.height = this.getHeight();
+                       this.imgGroup.addChild(this.imgBody);
+                       backgroundMap.addChild(this.imgGroup);
+                       this._tweet = new TTweet(148, 64);
+
+                       this.imgGroup.addChild(this._tweet);
+                       this.imgGroup.x = x;
+                       this.imgGroup.y = y;
+
+                       this.animation();
+                       this.action = new Action(this);
+                       ctl.addObj(this);
+               }
+       });
+
        game.onload = function(){
                def.Food = Food;
                def.Place = Place;
@@ -2225,9 +2367,9 @@ window.onload = function(){
                // new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
                // new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
                // new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
-               // new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
+               new Reimu(PALYER_INIT_X + 100, PALYER_INIT_Y + 100, EGrow.ADULT);
                // new Unun(100, 100);
-               new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
+               // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
                var touchX = 0;