OSDN Git Service

Popupとピコハン機能を追加
[yukkurioverwint/YukkuriOverwinter.git] / ctrl.js
1 var Ctrl = enchant.Class.create({
2         initialize: function (){
3                 this.game = null;
4                 this.menuBg = null;
5                 this.currentCommand = ECommand.WORLD_CURSOR;
6                 this.backgroundMap = null;
7                 this.player = null;
8                 this.objArray = {};
9                 this.def = null;
10                 this.objSprite = null;
11                 this.mangTouch = null;
12                 this.time = (HOUR * 24 + HOUR * 6) ;
13                 this.min = 0;
14                 this.hour = 0;
15                 this.day = 0;
16                 // this.popup = new GWindow(game.rootScene,0,0,100,100);
17                 this.popup = new GPopup(game.rootScene,0,0,100,100);
18                 // this.popup = new GWindow(this, {
19                 //      x: 0,
20                 //      y: 0,
21                 //      width: 100,
22                 //      height: 40,
23                 //      color: "#ff0000",
24                 // });
25                 // this.popup.opacity = 0;
26         },
27         calcTime:function(){
28                 // var sec = ctl.time/BASE_FPS;
29                 var sec = ctl.time/BASE_FPS;
30                 this.min = Math.floor(sec % 60);
31                 var _min = sec / 60;
32                 this.hour = Math.floor(_min % 24);
33                 this.day = Math.floor(_min / 24 % 30);
34         },
35         init : function (game){
36                 this.game = game;
37         },
38         getDate : function(){
39                 if(this.hour >= 5 && this.hour < 11)return EDate.MORNING;
40                 if(this.hour >= 11 && this.hour < 13)return EDate.NOON;
41                 if(this.hour >= 13 && this.hour < 17)return EDate.AFTERNOON;
42                 if(this.hour >= 17 && this.hour < 20)return EDate.EVENING;
43                 if(this.hour >= 20 && this.hour < 24)return EDate.NIGHT;
44                 if(this.hour >= 0 && this.hour < 5)return EDate.MIDNIGHT;
45         },
46         setDefined:function(def){
47                 this.def = def;
48         },
49         addObj: function(obj){
50                 this.objArray[obj.id] = obj;
51         },
52         getObjs: function(){
53                 return this.objArray;
54         },
55         removeObj:function(obj){
56                 delete this.objArray[obj.id];
57         },
58         setMenuBg: function (menuBg){
59                 this.menuBg = menuBg;
60         },
61         setBackgroundMap: function(backgroundMap){
62                 this.backgroundMap = backgroundMap;
63         },
64         setPlayer: function(player){
65                 this.player = player;
66         },
67         setTime: function(time){
68                 this.time = time;
69         },
70         setCurrentObjSprite: function(objSprite){
71                 this.objSprite = objSprite;
72         },
73         getCurrentObjSprite: function(objSprite){
74                 return this.objSprite;
75         },
76         isCollision : function (e, node){
77                 var ex = e.x - ctl.backgroundMap.x;
78                 var ey = e.y - ctl.backgroundMap.y;
79                 if(node.getX() <= ex && node.getX() + node.getWidth() >= ex
80                         && node.getY() <= ey && node.getY() + node.getHeight() >= ey){
81                         return true;
82                 }
83                 return false;
84         },
85         /**
86          * [setCurrentCommand description]
87          * @param {ECommand} cmd [description]
88          */
89         setCurrentCommand: function(cmd){
90                 this.currentCommand = cmd;
91         },
92         getCurrentCommand: function(){
93                 return this.currentCommand;
94         }
95 });
96 var CommandIcon = enchant.Class.create(enchant.Sprite,{
97         initialize: function (x, y, ecmd, index){
98                 enchant.Sprite.call(this, x, y);
99                 this.ecmd = ecmd;
100                 this.index = index;
101                 this.text = "";
102         },
103         isCurrent: function(){
104                 return (this.index * 2)%2 !== 0;
105         },
106         setCurrent: function(){
107                 this.frame = (this.index * 2) + 1;
108         },
109         removeCurrent: function(){
110                 this.frame = (this.index * 2);
111         }
112 });
113 var ICON_TEXT = [
114 "クリックアイコンです。\nフィールドのスクロールや\n各オブジェクトのステータスが見れます。",
115 "命令アイコンです。\nプレイヤーゆっくりに\n移動命令を出せます。",
116 "食物アイコンです。\nゆっくりが食べる\n食べ物を設置できます。",
117 "家アイコンです。\nゆっくりが住む事のできる\nプレイスを設置できます。",
118 "ゴミ箱アイコンです。\n配置したオブジェクトを削除できます。",
119 "しつけアイコンです。\nゆっくりに対してアクションが出来ます。",
120 ];
121 var MangIcon = enchant.Class.create({
122         initialize: function (ctl, menuBg){
123                 var self = this;
124                 this.ctl = ctl;
125                 this.cmdIcons = [];
126                 var index = 0;
127                 var POS_NUMBER = 4;
128                 var HEIGHT_TOP_MARGIN = 2;
129                 for (var key in ECommand) {
130                         var value = ECommand[key];
131                         this.cmdIcons[value] = new CommandIcon(ICON_WIDTH, ICON_HEIGHT, value, index);
132                         this.cmdIcons[value].image = this.ctl.game.assets[EResPath.COMMAND];
133                         this.cmdIcons[value].x = ICON_WIDTH * (index%POS_NUMBER) + 5;
134                         var yindex = parseInt(index/POS_NUMBER) + 1;
135                         this.cmdIcons[value].y = ICON_HEIGHT * yindex + HEIGHT_TOP_MARGIN;
136                         this.cmdIcons[value].text = ICON_TEXT[value];
137                         // odd equals current. even equals not current.
138                         this.cmdIcons[value].frame = (this.ctl.getCurrentCommand() == value)? index * 2 + 1: index * 2;
139                         menuBg.addChild(this.cmdIcons[value]);
140                         this.cmdIcons[value].ontouchstart = function(obj){
141                                 // change command icons
142                                 var nowECmd = self.ctl.getCurrentCommand();
143                                 self.cmdIcons[nowECmd].removeCurrent();
144                                 if(!this.isCurrent()){
145                                         this.setCurrent();
146                                 }
147                                 self.ctl.setCurrentCommand(this.index);
148                         };
149                         index++;
150                 }
151         },
152         get: function(commandIndex){
153                 return this.cmdIcons[commandIndex];
154         }
155 });
156 var ATouchEvent = enchant.Class.create({
157         // initialize: function (ctl){
158         //      this.ctl = ctl;
159         // },
160         touchstart: function(e){
161         },
162         touchmove: function(e){
163         },
164         touchend: function(e){
165         }
166 });
167
168 var WorldCursorTouchEvent = enchant.Class.create(ATouchEvent,{
169         initialize: function (ctl){
170                 this.ctl = ctl;
171                 this.touchX = 0;
172                 this.touchY = 0;
173         },
174         touchstart : function(e){
175                 this.touchX = e.x - this.ctl.backgroundMap.x;
176                 this.touchY = e.y - this.ctl.backgroundMap.y;
177                 var tx = this.touchX;
178                 var ty = this.touchY;
179                 var nodes = this.ctl.getObjs();
180
181                 // nodes.sort(ctl.def.nodeSort);
182                 for (var id in nodes) {
183                         var node = nodes[id];
184                         if(node === null || node === undefined)continue;
185                         var nx = node.getX();
186                         var ny = node.getY();
187                         if(node == null)continue;
188                         if(node instanceof Box
189                                 || node instanceof this.ctl.def.Food
190                                 || node instanceof this.ctl.def.Unun
191                                 ){
192                                 continue;
193                         }
194                         if(node instanceof this.ctl.def.Yukkuri){
195                                 nx -= node.getWidth() / 2;
196                                 ny -= node.getHeight() / 2;
197                         }
198                         if(     nx <= tx
199                                 && (nx + node.getWidth()) >= tx
200                                 && ny <= ty
201                                 && (ny + node.getHeight()) >= ty
202                                 ){
203                                 // new BoxLabel(this.ctl,100, e.x, e.y);
204                                 var box = new Box(this.ctl, node, e.x - ctl.backgroundMap.x, e.y - ctl.backgroundMap.y, 200, 200);
205                                 box.drawBox();
206                                 // var menuWindow = new MenuWindow(this.ctl, node, e.x, e.y, 300, 300);
207                                 // menuWindow.draw();
208                                 // new GWindow(game.rootScene,0,0,100,100);
209                                 // ctl.popup.renew(game.rootScene,640,0,100,100);
210                                 // ctl.popup.setText("aaaaaa");
211                                 // ctl.popup.drawText();
212                                 break;
213                         }
214                 }
215
216         },
217         touchmove : function(e){
218                 var backgroundMap = this.ctl.backgroundMap;
219                 var game = this.ctl.game;
220
221                 if(game.touched){
222                         backgroundMap.x = e.x - this.touchX;
223                         if(backgroundMap.x < -EFieldPos.WIDTH)backgroundMap.x = -EFieldPos.WIDTH;
224                         if(backgroundMap.x > 0)backgroundMap.x = 0;
225
226                         backgroundMap.y = e.y - this.touchY;
227                         if(backgroundMap.y < -EFieldPos.HEIGHT)backgroundMap.y = -EFieldPos.HEIGHT;
228                         if(backgroundMap.y > 0)backgroundMap.y = 0;
229                 }
230                 if(e.x > EFieldPos.WIDTH)game.touched = false;
231                 else if(e.x < 30)game.touched = false;
232         },
233         touchend : function(e){
234         }
235 });
236 /**
237  * プレイヤーゆっくりの移動を支持
238  */
239 var WorldTargetTouchEvent = enchant.Class.create(ATouchEvent,{
240         initialize: function (ctl){
241                 this.ctl = ctl;
242                 this.touchX = 0;
243                 this.touchY = 0;
244         },
245         touchstart :function(e){
246                 if(e.x >= 0 && e.x <= EFieldPos.WIDTH){
247                         var backgroundMap = this.ctl.backgroundMap;
248                         addEffect(this.ctl.backgroundMap, -backgroundMap.x + e.x, -backgroundMap.y + e.y);
249                         this.ctl.player.tweet("ゆっくりりかいしたよ!");
250                         // var vx = (-backgroundMap.x + e.x) - this.ctl.player.getX() ;
251                         // var vy = (-backgroundMap.y + e.y) - this.ctl.player.getY() ;
252
253                         //移動先のx,y
254                         //action status
255                         //
256                         ctl.player.cmdQueue.push(new CommandQueueObject({
257                                 touchX:(-backgroundMap.x + e.x),
258                                 touchY:(-backgroundMap.y + e.y),
259                                 date:ctl.getDate(),
260                                 actionStatus:EAction.MOVE_TO_COMMAND
261                         }));
262                         // this.ctl.player.action.setStatus(EAction.MOVE_TO_COMMAND);
263                         // new MoveCommandEvent({
264                         //      "vx": vx,
265                         //      "vy": vy,
266                         //      "action": this.ctl.player.action,
267                         //      "myYukkuri": this.ctl.player
268                         // });
269
270                         // this.ctl.player.tweet("ゆー...いきたくないのぜ");
271                 }
272         }
273 });
274 var WorldAppleTouchEvent = enchant.Class.create(ATouchEvent,{
275         initialize: function (ctl){
276                 this.ctl = ctl;
277                 this.touchX = 0;
278                 this.touchY = 0;
279         },
280         touchstart :function(e){
281                 if(e.x >= 0 && e.x <= EFieldPos.WIDTH){
282                         var backgroundMap = this.ctl.backgroundMap;
283                         var tx = -backgroundMap.x + e.x;
284                         var ty = -backgroundMap.y + e.y;
285                         // new ctl.def.Food("apple", tx, ty);
286                         new ctl.def.Food("grass", tx, ty);
287                 }
288         }
289 });
290 var WorldPlaceTouchEvent = enchant.Class.create(ATouchEvent,{
291         initialize: function (ctl){
292                 this.ctl = ctl;
293                 this.touchX = 0;
294                 this.touchY = 0;
295         },
296         touchstart :function(e){
297                 if(e.x >= 0 && e.x <= EFieldPos.WIDTH){
298                         var backgroundMap = this.ctl.backgroundMap;
299                         var tx = -backgroundMap.x + e.x;
300                         var ty = -backgroundMap.y + e.y;
301                         new ctl.def.Place("tree", tx, ty);
302                 }
303         }
304 });
305
306 var WorldRemoveTouchEvent = enchant.Class.create(ATouchEvent,{
307         initialize: function (ctl){
308                 this.ctl = ctl;
309                 this.touchX = 0;
310                 this.touchY = 0;
311         },
312         touchstart :function(e){
313                 this.touchX = e.x - this.ctl.backgroundMap.x;
314                 this.touchY = e.y - this.ctl.backgroundMap.y;
315                 var tx = this.touchX;
316                 var ty = this.touchY;
317                 var nodes = this.ctl.getObjs();
318                 // nodes.sort(ctl.def.nodeSort);
319                 for (var id in nodes) {
320                         var node = nodes[id];
321                         var nx = node.getX();
322                         var ny = node.getY();
323                         if(node == null)continue;
324                         // if(node instanceof Box
325                         //      || node instanceof this.ctl.def.Food
326                         //      || node instanceof this.ctl.def.Unun
327                         //      ){
328                         //      continue;
329                         // }
330                         if(node instanceof this.ctl.def.Yukkuri){
331                                 nx -= node.getWidth() / 2;
332                                 ny -= node.getHeight() / 2;
333                         }
334                         if(     nx <= tx
335                                 && (nx + node.getWidth()) >= tx
336                                 && ny <= ty
337                                 && (ny + node.getHeight()) >= ty
338                                 ){
339                                 if(node instanceof this.ctl.def.Yukkuri){
340                                         mangMsg.output(node, EMsg.REMOVE_YUKKURI);
341                                         node.setFaceImage(EFace.CRY1);
342                                 }
343                                 else if(node instanceof this.ctl.def.Place){
344                                         node.removeAll();
345                                 }
346                                 else{
347                                         node.removeAll();
348                                         node.undefineAll();
349                                 }
350
351                                 break;
352                         }
353                 }
354         }
355 });
356 var WorldPicoPicoHummerTouchEvent = enchant.Class.create(ATouchEvent,{
357         initialize: function (ctl){
358                 this.ctl = ctl;
359                 this.touchX = 0;
360                 this.touchY = 0;
361         },
362         touchstart :function(e){
363                 this.touchX = e.x - this.ctl.backgroundMap.x;
364                 this.touchY = e.y - this.ctl.backgroundMap.y;
365                 var tx = this.touchX;
366                 var ty = this.touchY;
367                 var nodes = this.ctl.getObjs();
368                 // nodes.sort(ctl.def.nodeSort);
369                 for (var id in nodes) {
370                         var node = nodes[id];
371                         var nx = node.getX();
372                         var ny = node.getY();
373                         if(node == null)continue;
374                         if(!(node instanceof this.ctl.def.Yukkuri)){
375                                 continue;
376                         }
377                         nx -= node.getWidth() / 2;
378                         ny -= node.getHeight() / 2;
379                         if(     nx <= tx
380                                 && (nx + node.getWidth()) >= tx
381                                 && ny <= ty
382                                 && (ny + node.getHeight()) >= ty
383                                 ){
384                                 node.damage(EDamage.PICOHAN);
385
386                                 break;
387                         }
388                 }
389         }
390 });
391
392 var MangTouch = enchant.Class.create({
393         initialize: function (ctl){
394                 this.ctl = ctl;
395                 var cursor = ECommand.WORLD_CURSOR;
396                 this.mang = {};
397                 this.mang[ECommand.WORLD_CURSOR] = new WorldCursorTouchEvent(ctl);
398                 this.mang[ECommand.WORLD_TARGET] = new WorldTargetTouchEvent(ctl);
399                 this.mang[ECommand.WORLD_APPLE] = new WorldAppleTouchEvent(ctl);
400                 this.mang[ECommand.WORLD_PLACE] = new WorldPlaceTouchEvent(ctl);
401                 this.mang[ECommand.WORLD_REMOVE] = new WorldRemoveTouchEvent(ctl);
402                 this.mang[ECommand.WORLD_PICOPICO_HUMMER] = new WorldPicoPicoHummerTouchEvent(ctl);
403                 ctl.mangTouch = this;
404         },
405         get: function(ecmd){
406                 return this.mang[ecmd];
407         }
408 });
409 var MangLabel = enchant.Class.create({
410         initialize: function (ctl, menuBg){
411                 this.ctl = ctl;
412                 var labelGroup = new LabelGroup();
413                 this.START_XPOS = 4;
414                 this.START_YPOS = GAME_HEIGHT / 2;
415                 this.GAUGE_XPOS = 80;
416                 this.menuBg = menuBg;
417                 this.widthArr = [];
418                 this.WIDTH_MARGIN = 4;
419                 this.GAUGE_HEIGHT = 16;
420                 var FONT = "18px 'Times New Roman'";
421                 var COLOR = "#ffffff";
422                 menuBg.image.context.font = FONT;
423                 var self = this;
424                 // this.labels = {};
425                 this.labelParams = {
426                         "yukkuri" : {
427                                 label: null,
428                                 init: function(){
429                                         var TEXT = M.LABEL.YUKKURI;
430                                         var label = new Label(TEXT);
431                                         label.color = COLOR;
432                                         label.font = FONT;
433                                         label.x = self.START_XPOS;
434                                         label.y = self.START_YPOS;
435                                         label.textWidth = menuBg.image.context.measureText(TEXT).width;
436                                         this.label = label;
437                                 },
438                                 draw: function(yukkuriObj){
439                                         //100/maxhp*hp
440                                         var gauge = 100 / yukkuriObj.param.maxYukkuri * yukkuriObj.param.yukkuri;
441                                         self.menuBg.image.context.fillStyle = "#ffffff";
442                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
443                                         self.menuBg.image.context.fillStyle = "#ff0000";
444                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
445                                 }
446                         },
447                         "hungry" : {
448                                 label: null,
449                                 init: function(){
450                                         var TEXT = M.LABEL.HUNGRY;
451                                         var label = new Label(TEXT);
452                                         label.color = COLOR;
453                                         label.font = FONT;
454                                         label.x = self.START_XPOS;
455                                         label.y = self.START_YPOS + 20;
456                                         label.textWidth = menuBg.image.context.measureText(TEXT).width;
457                                         this.label = label;
458                                 },
459                                 draw: function(yukkuriObj){
460                                         var gauge =yukkuriObj.param.hungry;
461                                         self.menuBg.image.context.fillStyle = "#ffffff";
462                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
463                                         self.menuBg.image.context.fillStyle = "#bb7777";
464                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
465                                 }
466                         },
467                         "unun" : {
468                                 label: null,
469                                 init: function(){
470                                         var TEXT = M.LABEL.UNUN;
471                                         var label = new Label(TEXT);
472                                         label.color = COLOR;
473                                         label.font = FONT;
474                                         label.x = self.START_XPOS;
475                                         label.y = self.START_YPOS + 40;
476                                         label.textWidth = menuBg.image.context.measureText(TEXT).width;
477                                         this.label = label;
478                                 },
479                                 draw: function(yukkuriObj){
480                                         var gauge =yukkuriObj.param.unun;
481                                         self.menuBg.image.context.fillStyle = "#ffffff";
482                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
483                                         self.menuBg.image.context.fillStyle = "#bb7777";
484                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
485                                 }
486                         },
487                         "sleep" : {
488                                 label: null,
489                                 init: function(){
490                                         var TEXT = M.LABEL.SLEEP;
491                                         var label = new Label(TEXT);
492                                         label.color = COLOR;
493                                         label.font = FONT;
494                                         label.x = self.START_XPOS;
495                                         label.y = self.START_YPOS + 60;
496                                         label.textWidth = menuBg.image.context.measureText(TEXT).width;
497                                         this.label = label;
498                                 },
499                                 draw: function(yukkuriObj){
500                                         var gauge =yukkuriObj.param.sleep;
501                                         self.menuBg.image.context.fillStyle = "#ffffff";
502                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
503                                         self.menuBg.image.context.fillStyle = "#bb7777";
504                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
505                                 }
506                         },
507                         "stress" : {
508                                 label: null,
509                                 init: function(){
510                                         var TEXT = M.LABEL.STRESS;
511                                         var label = new Label(TEXT);
512                                         label.color = COLOR;
513                                         label.font = FONT;
514                                         label.x = self.START_XPOS;
515                                         label.y = self.START_YPOS + 80;
516                                         label.textWidth = menuBg.image.context.measureText(TEXT).width;
517                                         this.label = label;
518                                 },
519                                 draw: function(yukkuriObj){
520                                         var gauge =yukkuriObj.param.stress;
521                                         self.menuBg.image.context.fillStyle = "#ffffff";
522                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, 100, self.GAUGE_HEIGHT);
523                                         self.menuBg.image.context.fillStyle = "#bb7777";
524                                         self.menuBg.image.context.fillRect(self.GAUGE_XPOS, this.label.y, gauge, self.GAUGE_HEIGHT);
525                                 }
526                         },
527                 };
528
529                 this.menuBg.image.context.fillStyle = '#ff0000';
530                 for(var key in this.labelParams){
531                         var labelObj = this.labelParams[key];
532                         labelObj.init();
533                         labelGroup.addChild(labelObj.label);
534                 }
535                 menuBg.addChild(labelGroup);
536
537                 //datetime
538                 var dateLabel = new Label("時間");
539                 dateLabel.color = COLOR;
540                 dateLabel.font = FONT;
541                 dateLabel.x = self.START_XPOS;
542                 dateLabel.y = 4;
543                 // dateLabel.textWidth = menuBg.image.context.measureText(TEXT).width;
544                 dateLabel.addEventListener("enterframe", function(){
545                                 // console.log("min:" + ctl.min + ":" + ctl.hour + ":" + ctl.day);
546                                 this.text = "時間:" + ctl.day + "日 " + ctl.hour + ":" + ctl.min;
547                 });
548                 menuBg.addChild(dateLabel);
549
550         },
551         draw: function(yukkuriObj){
552                 for(var key in this.labelParams){
553                         var labelObj = this.labelParams[key];
554                         labelObj.draw(yukkuriObj);
555                 }
556         }
557 });
558 var CommandQueueObject = enchant.Class.create({
559         initialize: function (_data){
560                 this.touchX = _data.touchX;
561                 this.touchY = _data.touchY;
562                 this.date = _data.date;
563                 this.actionStatus = _data.actionStatus;
564         }
565 });
566
567 var MangMsg = enchant.Class.create({
568         initialize: function (ctl){
569                 this.ctl = ctl;
570         },
571         output:function(yukkuri, emsg, targetYukkuri){
572                 //var M = yukkuri.getMsg();
573                 var myCode = yukkuri.myCode;
574                 var mySize = yukkuri.mySize;
575                 if(myCode === null || myCode === undefined){
576                         myCode = "BASE";
577                         mySize = "L";
578                 }
579
580                 if(emsg == EMsg.WALK){
581                         if(rand(4) === 0){
582                                 yukkuri.tweet(M.get(myCode,mySize,"WALK1"));
583                         }
584                         else if(rand(4) === 1){
585                                 yukkuri.tweet(M.get(myCode,mySize,"WALK2"));
586                         }
587                         else if(rand(4) === 2){
588                                 yukkuri.tweet(M.get(myCode,mySize,"WALK3"));
589                         }
590                         else if(rand(4) === 3){
591                                 yukkuri.tweet(M.get(myCode,mySize,"WALK4"));
592                         }
593                 }
594                 else if(emsg == EMsg.EAT){
595                         if(rand(3) === 0){
596                                 yukkuri.tweet(M.get(myCode,mySize,"EAT1"));
597                         }
598                         else if(rand(3) === 1){
599                                 yukkuri.tweet(M.get(myCode,mySize,"EAT2"));
600                         }
601                         else if(rand(3) === 2){
602                                 yukkuri.tweet(M.get(myCode,mySize,"EAT3"));
603                         }
604                 }
605                 else if(emsg == EMsg.GET_UP){
606                         yukkuri.tweet(M.get(myCode,mySize,"GET_UP1"));
607                 }
608                 else if(emsg == EMsg.SLEEP){
609                         yukkuri.tweet(M.get(myCode,mySize,"SLEEP1"));
610                 }
611                 else if(emsg == EMsg.DEAD){
612                         yukkuri.tweet(M.get(myCode,mySize,"DEAD1"));
613                 }
614                 else if(emsg == EMsg.UNUN){
615                         if(rand(2) === 0){
616                                 yukkuri.tweet(M.get(myCode,mySize,"UNUN1"));
617                         }else{
618                                 yukkuri.tweet(M.get(myCode,mySize,"UNUN2"));
619                         }
620                 }
621                 else if(emsg == EMsg.UNUN_END){
622                         yukkuri.tweet(M.get(myCode,mySize,"UNUN_END1"));
623                 }
624                 else if(emsg == EMsg.UNUN_SMELL){
625                         yukkuri.tweet(M.get(myCode,mySize,"UNUN_SPELL1"));
626                 }
627                 else if(emsg == EMsg.EAT_FAILED){
628                         yukkuri.tweet(M.get(myCode,mySize,"EAT_FAILED1"));
629                 }
630                 else if(emsg == EMsg.SAY_HELLO){
631
632                         if(yukkuri.getAddress(targetYukkuri) === null){
633                                 yukkuri.tweet(M.get(myCode,mySize,"SAY_HELLO1"));
634                         }else{
635                                 yukkuri.tweet(M.get(myCode,mySize,"SAY_HELLO2"));
636                         }
637                 }
638                 else if(emsg == EMsg.TARGETING_EAT){
639                         yukkuri.tweet(M.get(myCode,mySize,"TARGETING_EAT1"));
640                 }
641                 else if(emsg == EMsg.DECLARE_PLACE){
642                         yukkuri.tweet(M.get(myCode,mySize,"DECLARE_PLACE1"));
643                 }
644                 else if(emsg == EMsg.REHUNT){
645                         yukkuri.tweet(M.get(myCode,mySize,"REHUNT1"));
646                 }
647                 else if(emsg == EMsg.HUNT_ESCAPE){
648                         yukkuri.tweet(M.get(myCode,mySize,"HUNT_ESCAPE1"));
649                 }
650                 else if(emsg == EMsg.MOVE_GOTO_HOME){
651                         yukkuri.tweet(M.get(myCode,mySize,"MOVE_GOTO_HOME1"));
652                 }
653                 else if(emsg == EMsg.YYUYYU){
654                         if(rand(2) === 0){
655                                 yukkuri.tweet(M.get(myCode,mySize,"YYUYYU1"));
656                         }else{
657                                 yukkuri.tweet(M.get(myCode,mySize,"YYUYYU2"));
658                         }
659                 }
660                 else if(emsg == EMsg.HUNTING_MESSAGE){
661                         var num = rand(6) + 1;
662                         yukkuri.tweet(M.get(myCode,mySize,"HUNTING_MESSAGE" + num));
663                 }
664                 else if(emsg == EMsg.LEARN_NO_FOOD_IN_PLACE){
665                         var num = 1;
666                         yukkuri.tweet(M.get(myCode,mySize,"LEARN_NO_FOOD_IN_PLACE" + num));
667                 }
668                 else if(emsg == EMsg.REMOVE_YUKKURI){
669                         var num = 1;
670                         yukkuri.tweet(M.get(myCode,mySize,"REMOVE_YUKKURI" + num));
671                 }
672                 else if(emsg == EMsg.LOST_HOUSE){
673                         var num = 1;
674                         yukkuri.tweet(M.get(myCode,mySize,"LOST_HOUSE" + num));
675                 }
676                 else if(emsg == EMsg.MOVE_TO_HUNTING){
677                         var num = 1;
678                         yukkuri.tweet(M.get(myCode,mySize,"MOVE_TO_HUNTING" + num));
679                 }
680                 else if(emsg == EMsg.DAMAGE){
681                         var num = rand(1) + 1;
682                         yukkuri.tweet(M.get(myCode,mySize,"DAMAGE" + num));
683                 }
684
685         }
686 });
687
688 // var MangLabel = enchant.Class.create({
689 //      initialize: function (ctl, menuBg){
690 //              this.ctl = ctl;
691 //              var labelGroup = new LabelGroup();
692 //              this.START_XPOS = 4;
693 //              this.START_YPOS = GAME_HEIGHT / 2;
694 //              this.menuBg = menuBg;
695 //              this.widthArr = [];
696 //              this.WIDTH_MARGIN = 4;
697 //              var FONT = "14px 'Times New Roman'";
698 //              var COLOR = "#ffffff";
699 //              menuBg.image.context.font = FONT;
700 //              var self = this;
701 //              this.labels = {
702 //                      "yukkuri" : function(){
703 //                              var TEXT = "ゆっくり";
704 //                              var label = new Label(TEXT);
705 //                              label.color = COLOR;
706 //                              label.font = FONT;
707 //                              label.x = self.START_XPOS;
708 //                              label.y = self.START_YPOS;
709 //                              label.textWidth = menuBg.image.context.measureText(TEXT).width;
710 //                      },
711 //                      "hungry" : function(){
712 //                              var TEXT = "空腹";
713 //                              var label = new Label(TEXT);
714 //                              label.color = COLOR;
715 //                              label.font = FONT;
716 //                              label.x = self.START_XPOS;
717 //                              label.y = self.START_YPOS + 20;
718 //                              label.textWidth = menuBg.image.context.measureText(TEXT).width;
719 //                              return label;
720 //                      },
721 //              };
722
723 //              this.labels["yukkuri"]();
724 //              console.log(this.labels["yukkuri"]().textWidth);
725 //              // for(var key in this.labels){
726 //              //      console.log(key);
727 //              //      var label = this.labels[key]();
728 //              //      // labelGroup.addChild(label);
729 //              // }
730 //              // var width = this.widthArr['yukkuri'];
731 //              // this.menuBg.image.context.fillStyle = '#ff0000';
732 //              // this.menuBg.image.context.fillRect(this.START_XPOS + width, this.START_YPOS, 100, 30);
733 //              // menuBg.addChild(labelGroup);
734 //      },
735 //      draw: function(){
736 //              label = this.labels[key]();
737 //              this.menuBg.image.context.fillStyle = '#ff0000';
738 //              this.menuBg.image.context.fillRect(label.x, label.y, 100, 14);
739 //      }
740 // });
741