var GAME_WIDTH = 800;
var GAME_HEIGHT = 600;
var FPS = 20;
+var BASE_FPS = 20;
var HUNGRY_MAX = 100;
var EResPath = {
};
var EAction = {
WAIT : 0,
- SLEEP : 1,
HUNT : 3,
THINK : 4,
WALK : 5,
UNUN_WAIT : 14,
UNUN_SMELL_START : 15,
UNUN_SMELL_WAIT : 16,
+ SLEEP_START : 17,
+ SLEEP_WAIT : 18,
NONE: 9999
};
var EDirection = {
this.isMoving = false;
this.targetNode = null;
},
+ getStatus: function(){
+ return this.status;
+ },
setStatus: function(eaction){
this.status = eaction;
},
if(this.yukkuri.isDead()){
this.status = EAction.DEAD;
}
- else if(this.yukkuri.isSleep()){
- this.status = EAction.SLEEP;
- }
+ // else if(this.yukkuri.isSleep()){
+ // this.status = EAction.SLEEP;
+ // }
},
act : function(){
break;
case EAction.THINK:
if(this.yukkuri.age%2 === 0){
- if(this.yukkuri.getUnun() >= 80){
+ if(this.yukkuri.isSleep()){
+ this.setStatus(EAction.SLEEP_START);
+ }
+ else if(this.yukkuri.getUnun() >= 80){
this.setStatus(EAction.UNUN_START);
}else{
// this.yukkuri.param.yukkuri -= 1;
case EAction.WALK:
this.walk(0);
break;
- case EAction.SLEEP:
- this.sleep();
+ case EAction.SLEEP_START:
+ this.sleep_start();
+ break;
+ case EAction.SLEEP_WAIT:
break;
case EAction.DEAD:
this.dead();
}
}
},
- sleep: function(){
- var yukkuri = this.yukkuri;
-
- if(yukkuri.isSleeping){
- if(yukkuri.age%4 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
- if(yukkuri.param.sleep <= 0){
- yukkuri.param.sleep = 0;
- yukkuri.isSleeping = false;
- mangMsg.output(yukkuri, EMsg.GET_UP);
- this.status = EAction.THINK;
- yukkuri.imgBody.tl.resume();
- yukkuri.imgGroup.tl.resume();
- yukkuri.animation();
- yukkuri.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
- }
- }
+ sleep_start: function(){
+ new SleepEvent({
+ "action": this,
+ "myYukkuri": this.yukkuri
+ });
},
dead : function(){
console.log("dead");
};
}
});
+ var SleepEvent = enchant.Class.create(Event,{
+ initialize: function (_data){
+ this.data = _data;
+ this.yukkuri = _data.myYukkuri;
+ this.action = _data.action;
+
+ mangMsg.output(this.yukkuri, EMsg.SLEEP);
+ this.action.setStatus(EAction.SLEEP_WAIT);
+ this.yukkuri.setFaceImage(EFace.SLEEP);
+ this.yukkuri.tlPause();
+ var sec = FPS * 3;
+ // this.yukkuri.enterframe(function(){
+ // console.log("enterfmrae");
+ // });
+ var self = this;
+ this.yukkuri.addEventListener('enterframe', function() {
+ var yukkuri = self.yukkuri;
+ if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
+ if(yukkuri.param.sleep <= 0){
+ yukkuri.param.sleep = 0;
+ self.action.setStatus(EAction.WAIT);
+ mangMsg.output(self.yukkuri, EMsg.GET_UP);
+ self.yukkuri.setFaceImage(EFace.NORMAL);
+ yukkuri.tlResume();
+ this.removeEventListener("enterframe",arguments.callee);
+ self.action.setStatus(EAction.THINK);
+ }
+ });
+ },
+ onactionstart:function(self){
+ return function(e){
+ if(typeof e === "undefined")return;
+ console.log("astart");
+ };
+ },
+ onactiontick:function(self){
+ return function(e){
+ if(typeof e === "undefined")return;
+ };
+ },
+ onactionend:function(self){
+ return function(e){
+ if(typeof e === "undefined")return;
+ console.log("enddd");
+ };
+ }
+
+ // initialize: function (_data){
+ // console.log("init");
+ // this.data = _data;
+ // this.yukkuri = _data.myYukkuri;
+ // this.action = _data.action;
+ // this.action.setStatus(EAction.SLEEP_WAIT);
+ // mangMsg.output(this.yukkuri, EMsg.SLEEP);
+ // this.yukkuri.setFaceImage(EFace.SLEEP);
+ // this.yukkuri.tlPause();
+
+ // var sec = BASE_FPS * 1;
+ // console.log("sec:"+ sec);
+ // this.yukkuri.wait(sec, {
+ // "onactionstart": this.onactionstart(this),
+ // "onactiontick": this.onactiontick(this),
+ // "onactionend": this.onactionend(this)
+ // });
+ // },
+ // onactionstart:function(self){
+ // return function(e){
+ // console.log("start");
+ // if(typeof e === "undefined")return;
+ // };
+ // },
+ // onactiontick:function(self){
+ // return function(e){
+ // if(typeof e === "undefined")return;
+ // console.log("tick");
+ // var yukkuri = self.yukkuri;
+ // if(yukkuri.age%4 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
+ // if(yukkuri.param.sleep <= 0){
+ // yukkuri.param.sleep = 0;
+ // }
+ // };
+ // },
+ // onactionend:function(self){
+ // return function(e){
+ // if(typeof e === "undefined")return;
+ // self.action.setStatus(EAction.WAIT);
+ // self.yukkuri.setFaceImage(EFace.NORMAL);
+ // mangMsg.output(self.yukkuri, EMsg.GET_UP);
+ // yukkuri.tlResume();
+ // new WaitEvent({
+ // "waitframe": FPS * 1.5,
+ // "action": self.action,
+ // "myYukkuri": self.yukkuri
+ // });
+ // };
+ // }
+ });
+
var UnunEvent = enchant.Class.create(Event,{
initialize: function (_data){
this.data = _data;
this.action.setStatus(EAction.EAT_WAIT);
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;
if(this.param.unun >= 100)this.param.unun = 100;
},
runSleep: function(){
- if(!this.isSleeping){
- if(this.age%100 === 0 && this.age !== 0)this.param.sleep++;
+ if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
+ if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
if(this.param.sleep >= 100){
this.param.sleep = 100;
- this.isSleeping = true;
- mangMsg.output(this, EMsg.SLEEP);
-
- this.imgBody.tl.pause();
- this.imgGroup.tl.pause();
- this.imgBody.tl.clear();
- this.imgGroup.tl.clear();
- this.face.image = game.assets[EResPath.MARISA_FACE_SLEEP];
-
}
-
}
},
changeFace: function(){
return this.param.range;
},
isSleep: function(){
- return this.isSleeping;
+ return this.param.sleep >= 100;
},
isDead: function(){
return this.param.yukkuri <= 0;
var path = this.bodyStatus[ebody];
this.image = game.assets[path];
},
+ tlPause:function(){
+ this.imgBody.tl.pause();
+ this.imgGroup.tl.pause();
+ this.imgBody.tl.clear();
+ this.imgGroup.tl.clear();
+ },
+ tlResume: function(){
+ this.imgBody.tl.resume();
+ this.imgGroup.tl.resume();
+ this.animation();
+ },
destruct: function(){
}
// var food = new def.Food("apple", 200, 250);
backgroundMap.addChild(foodGroup);
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);
var touchX = 0;
game.rootScene.addEventListener('touchstart', function (e) {