From b965b8416308d5ffa907aad5c8c03974cdbe3c35 Mon Sep 17 00:00:00 2001 From: nagoling <> Date: Tue, 1 Oct 2013 09:41:59 +0900 Subject: [PATCH] tweet opacty 0.8/add event to eat failed --- class.js | 208 ++++++++++++++++++++++++++++++------------------------------- ctrl.js | 3 + lang/ja.js | 2 +- main.js | 111 ++++++++++++++++++++++++++------- 4 files changed, 196 insertions(+), 128 deletions(-) diff --git a/class.js b/class.js index d4eb673..5f98af4 100644 --- a/class.js +++ b/class.js @@ -1,110 +1,110 @@ 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); + }); + }, }); diff --git a/ctrl.js b/ctrl.js index 0b68943..e7a6b9d 100644 --- a/ctrl.js +++ b/ctrl.js @@ -378,6 +378,9 @@ var MangMsg = enchant.Class.create({ else if(emsg == EMsg.UNUN_SMELL){ yukkuri.tweet(M.UNUN_SPELL1); } + else if(emsg == EMsg.EAT_FAILED){ + yukkuri.tweet(M.EAT_FAILED1); + } } diff --git a/lang/ja.js b/lang/ja.js index 217e4eb..944e3ca 100644 --- a/lang/ja.js +++ b/lang/ja.js @@ -16,7 +16,7 @@ M.UNUN3 = "うんうんあげるから\nよろこんでたべてねっ!!"; M.UNUN_END1 = "すっきりー!"; M.SEARCH_FOOD1 = "ゆゆ??\nたべものさん\nはっけんなのぜ!"; M.UNUN_SPELL1 = "うんうんくさい!"; - +M.EAT_FAILED1 = "どぼじで\nたべものさん\nないのおおおおお!?"; M.LABEL_YUKKURI = "ゆっくり"; M.LABEL_HUNGRY = "空腹"; diff --git a/main.js b/main.js index ae211ae..79f1e32 100644 --- a/main.js +++ b/main.js @@ -94,6 +94,7 @@ var EAction = { UNUN_SMELL_WAIT : 16, SLEEP_START : 17, SLEEP_WAIT : 18, + COMMUNICATE_START : 19, NONE: 9999 }; var EDirection = { @@ -110,6 +111,7 @@ var EMsg = { UNUN_END: 6, UNUN_SMELL_START: 7, SEARCH_FOOD: 8, + EAT_FAILED: 9, }; include("./lang/ja.js"); window.onload = function(){ @@ -213,7 +215,12 @@ 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(){ @@ -342,6 +349,14 @@ window.onload = function(){ "myYukkuri": this.yukkuri }); }, + communicate_start:function(){ + new CommunicationEvent({ + "type": 'greeting', + "targetNode": this.targetNode, + "action": this, + "myYukkuri": this.yukkuri + }); + }, move_to_command: function(){ }, @@ -373,6 +388,15 @@ window.onload = 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; } @@ -534,29 +558,21 @@ window.onload = function(){ 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; @@ -590,10 +606,11 @@ window.onload = function(){ 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), @@ -657,6 +674,48 @@ window.onload = function(){ }; } }); + 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){ @@ -904,10 +963,16 @@ window.onload = function(){ }, 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){ @@ -1039,7 +1104,7 @@ window.onload = function(){ 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{ -- 2.11.0