TTweet = enchant.Class.create(enchant.Sprite, {
- initialize : function(w, h) {
- this.lifetime = 0;
- enchant.Sprite.call(this, w, h + TTweet.TAIL);
- this.image = new Surface(w, h + TTweet.TAIL);
- var t = TTweet.TAIL;
- var s = TTweet.SIZE;
- var c = TTweet.CURVE;
- this.outCurve = {
- lt : {x: 0, y: t},
- rt : {x: w, y: t},
- rd : {x: w, y:h+t},
- ld : {x: 0, y:h+t}
- };
- this.inCurve = {
- lt : {x: 0+s, y: t+s},
- rt : {x: w-s, y: t+s},
- rd : {x: w-s, y:h+t-s},
- ld : {x: 0+s, y:h+t-s}
- };
- this.image.context.font = "12px 'Times New Roman'";
- this.addEventListener('enterframe', function(){
- if((this.age % 15) == 0){
- this.lifetime--;
- }
- if(this.lifetime <= 0){
- this.lifetime = 0;
- this.opacity = 0;
- }
- });
- },
- reDraw : function() {
- var c = TTweet.CURVE;
- var o = this.outCurve;
- with(this.image.context) {
- fillStyle = 'black';
- strokeStyle = 'black';
- beginPath();
- moveTo(o.lt.x, o.lt.y+c);
- quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
- lineTo(o.rt.x-c, o.rt.y);
- quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
- lineTo(o.rd.x, o.rd.y-c);
- quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
- lineTo(o.ld.x+c, o.ld.y);
- quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
- // しっぽ
- // var _height = 100;
- // lineTo(this.width/2-4,_height + TTweet.TAIL);
- // lineTo(this.width/2,_height + 0);
- // lineTo(this.width/2+4,_height + TTweet.TAIL);
- closePath();
- fill();
- stroke();
- };
- this.clear();
- },
- clear : function() {
- var c = TTweet.CURVE;
- var o = this.outCurve;
- var i = this.inCurve;
- with(this.image.context) {
- // 抜く
- fillStyle = 'white';
- beginPath();
- moveTo(i.lt.x, o.lt.y+c);
- quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
- lineTo(o.rt.x-c, i.rt.y);
- quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
- lineTo(i.rd.x, o.rd.y-c);
- quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
- lineTo(o.ld.x+c, i.ld.y);
- quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
- closePath();
- fill();
- };
- },
- text : function(text, x, y) {
- this.clear();
- this.opacity = 1;
+ initialize : function(w, h) {
+ this.lifetime = 0;
+ enchant.Sprite.call(this, w, h + TTweet.TAIL);
+ this.image = new Surface(w, h + TTweet.TAIL);
+ var t = TTweet.TAIL;
+ var s = TTweet.SIZE;
+ var c = TTweet.CURVE;
+ this.outCurve = {
+ lt : {x: 0, y: t},
+ rt : {x: w, y: t},
+ rd : {x: w, y:h+t},
+ ld : {x: 0, y:h+t}
+ };
+ this.inCurve = {
+ lt : {x: 0+s, y: t+s},
+ rt : {x: w-s, y: t+s},
+ rd : {x: w-s, y:h+t-s},
+ ld : {x: 0+s, y:h+t-s}
+ };
+ this.image.context.font = "12px 'Times New Roman'";
+ this.addEventListener('enterframe', function(){
+ if((this.age % 15) == 0){
+ this.lifetime--;
+ }
+ if(this.lifetime <= 0){
+ this.lifetime = 0;
+ this.opacity = 0;
+ }
+ });
+ },
+ reDraw : function() {
+ var c = TTweet.CURVE;
+ var o = this.outCurve;
+ with(this.image.context) {
+ fillStyle = 'black';
+ strokeStyle = 'black';
+ beginPath();
+ moveTo(o.lt.x, o.lt.y+c);
+ quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
+ lineTo(o.rt.x-c, o.rt.y);
+ quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
+ lineTo(o.rd.x, o.rd.y-c);
+ quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
+ lineTo(o.ld.x+c, o.ld.y);
+ quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
+ // しっぽ
+ // var _height = 100;
+ // lineTo(this.width/2-4,_height + TTweet.TAIL);
+ // lineTo(this.width/2,_height + 0);
+ // lineTo(this.width/2+4,_height + TTweet.TAIL);
+ closePath();
+ fill();
+ stroke();
+ };
+ this.clear();
+ },
+ clear : function() {
+ var c = TTweet.CURVE;
+ var o = this.outCurve;
+ var i = this.inCurve;
+ with(this.image.context) {
+ // 抜く
+ fillStyle = 'white';
+ beginPath();
+ moveTo(i.lt.x, o.lt.y+c);
+ quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
+ lineTo(o.rt.x-c, i.rt.y);
+ quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
+ lineTo(i.rd.x, o.rd.y-c);
+ quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
+ lineTo(o.ld.x+c, i.ld.y);
+ quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
+ closePath();
+ fill();
+ };
+ },
+ text : function(text, x, y) {
+ this.clear();
+ this.opacity = 0.8;
- this.reDraw();
- with(this.image.context) {
- // var size = measureText(text);
- fillStyle = 'black';
- textAlign = 'center';
- textBaseline = 'middle';
- this.x = x;
- this.y = y;
- // fillText(text,this.width/2,this.height/2);
- // console.log(size);
- // this.width = size;
- // console.log(this.width);
- // this.reDraw();
- this.fillTextLine(text,this.width/2,this.height/2);
- }
- this.lifetime = 7;
+ this.reDraw();
+ with(this.image.context) {
+ // var size = measureText(text);
+ fillStyle = 'black';
+ textAlign = 'center';
+ textBaseline = 'middle';
+ this.x = x;
+ this.y = y;
+ // fillText(text,this.width/2,this.height/2);
+ // console.log(size);
+ // this.width = size;
+ // console.log(this.width);
+ // this.reDraw();
+ this.fillTextLine(text,this.width/2,this.height/2);
+ }
+ this.lifetime = 7;
- },
- fillTextLine : function(text, x, y) {
- var textList = text.split("\n");
- var lineHeight = this.image.context.measureText("あ").width + 2;
- var self = this;
- textList.forEach(function(text, i) {
- self.image.context.fillText(text, x, y + lineHeight * i);
- });
- },
+ },
+ fillTextLine : function(text, x, y) {
+ var textList = text.split("\n");
+ var lineHeight = this.image.context.measureText("あ").width + 2;
+ var self = this;
+ textList.forEach(function(text, i) {
+ self.image.context.fillText(text, x, y + lineHeight * i);
+ });
+ },
});
UNUN_SMELL_WAIT : 16,
SLEEP_START : 17,
SLEEP_WAIT : 18,
+ COMMUNICATE_START : 19,
NONE: 9999
};
var EDirection = {
UNUN_END: 6,
UNUN_SMELL_START: 7,
SEARCH_FOOD: 8,
+ EAT_FAILED: 9,
};
include("./lang/ja.js");
window.onload = function(){
case EAction.UNUN_SMELL_START:
this.unun_smell_start();
break;
+ case EAction.COMMUNICATE_START:
+ this.communicate_start();
+ break;
+
}
+ this.yukkuri.reverse();
},
move_to_eat_start : function(){
"myYukkuri": this.yukkuri
});
},
+ communicate_start:function(){
+ new CommunicationEvent({
+ "type": 'greeting',
+ "targetNode": this.targetNode,
+ "action": this,
+ "myYukkuri": this.yukkuri
+ });
+ },
move_to_command: function(){
},
//not hunbry or not food.
}
}
+ // else if(node instanceof Yukkuri){
+ // if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
+ // this.targetNode = node;
+ // this.setStatus(EAction.COMMUNICATE_START);
+
+ // return;
+ // }
+
+ // }
}
this.status = EAction.WALK;
}
this.food = _data.targetNode;
this.action = _data.action;
this.action.setStatus(EAction.EAT_WAIT);
- mangMsg.output(this.yukkuri, EMsg.EAT);
- this.yukkuri.setFaceImage(EFace.EAT2);
- // var sec = FPS * (this.yukkuri.param.hungry/10 + 3);
- var sec = FPS * 3;
+ var sec = BASE_FPS * 3;
+ if(this.yukkuri.eat(this.food)){
+ mangMsg.output(this.yukkuri, EMsg.EAT);
+ this.yukkuri.setFaceImage(EFace.EAT2);
+ }else{
+ sec = BASE_FPS * 6;
+ mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
+ this.yukkuri.setFaceImage(EFace.CRY2);
+ }
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;
- self.yukkuri.eat(self.food);
- };
- },
- onactiontick:function(self){
- return function(e){
- if(typeof e === "undefined")return;
- };
- },
onactionend:function(self){
return function(e){
if(typeof e === "undefined")return;
if(this.data.type == "food"){
this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
yukkuri.vx = node.x - yukkuri.getX();
- yukkuri.vy = node.y - yukkuri.getY();
+ yukkuri.vy = node.y - 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, {
"onactionstart": this.onactionstart(this),
};
}
});
+ var CommunicationEvent = enchant.Class.create(Event,{
+ initialize: function (_data){
+ this.data = _data;
+ this.yukkuri = _data.myYukkuri;
+ this.food = _data.targetNode;
+ this.action = _data.action;
+ this.action.setStatus(EAction.EAT_WAIT);
+ mangMsg.output(this.yukkuri, EMsg.EAT);
+ this.yukkuri.setFaceImage(EFace.EAT2);
+
+ // var sec = FPS * (this.yukkuri.param.hungry/10 + 3);
+ 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;
+ self.yukkuri.eat(self.food);
+ };
+ },
+ onactiontick:function(self){
+ return function(e){
+ if(typeof e === "undefined")return;
+ };
+ },
+ onactionend:function(self){
+ return function(e){
+ 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);
+ }
+ };
+ }
+ });
var ObjSprite = enchant.Class.create(enchant.Sprite,{
initialize: function (w, h){
},
eat:function(food){
- food.amount--;
- this.setHungry(this.param.hungry - food.getGive());
- this.setUnun(this.getUnun() + food.getGive() / 4);
- this.setYukkuri(this.getYukkuri() + 5);
+ if(food.amount > 0){
+ food.amount--;
+ this.setHungry(this.param.hungry - food.getGive());
+ this.setUnun(this.getUnun() + food.getGive() / 4);
+ this.setYukkuri(this.getYukkuri() + 5);
+ return true;
+ }else{
+ this.setYukkuri(this.getYukkuri() - 5);
+ return false;
+ }
},
unun:function(){
if(this.direction == EDirection.RIGHT){
this.moveY(10);
}
///////////////////////////////////////////////
- this.reverse();
+ // this.reverse();
// if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
// console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
// }else{