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 = {
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,
//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);
}
else if(this.yukkuri.getUnun() >= 80){
this.setStatus(EAction.UNUN_START);
- }else{
+ }
+ else{
// this.yukkuri.param.yukkuri -= 1;
this.yukkuri.changeFace();
this.search();
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();
});
},
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(){
},
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){
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;
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){
}
});
/**
- * 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();
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;
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);
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);
// }
// this.y += 10;;
// }
// });
-
+ },
+ setOwner: function(yukkuri){
+ this.owner = yukkuri;
+ },
+ isOwner: function(){
+ return this.owner !== null;
}
});
var Unun = enchant.Class.create(ObjSprite,{
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];
}
});
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();
},
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;
}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;
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 );
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;
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(){
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)){
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) {