OSDN Git Service

移動命令コマンド追加
[yukkurioverwint/YukkuriOverwinter.git] / main.js
1 enchant();
2 //////////////////////////////////////
3 /*
4     CanvasLayer初期化後にcanvasのコンテキストを操作する
5 */
6 // var initCanvas = CanvasLayer.prototype.initialize;
7
8 // CanvasLayer.prototype.initialize = function() {
9 //     initCanvas.call(this);
10 //     console.log("canvas");
11
12 //     // 拡大時の処理をNearest Neighbor方式に切り替え
13 //     // ただしChromeとFireFoxでのみ動作
14 //     this.context.imageSmoothingEnabled = false;
15 //     this.context.webkitImageSmoothingEnabled = false;
16 //     this.context.mozImageSmoothingEnabled = false;
17 // };
18 //global
19 var ctl = null;
20 var mangIcon = null;
21 var mangTouch = null;
22 var mangLabel = null;
23 var mangMsg = null;
24 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
25 var net = new Net();
26 //////////////////////////////////////
27 //define
28 //////////////////////////////////////
29 var PALYER_INIT_X = 100;
30 var PALYER_INIT_Y = 100;
31 var CHARA_WIDTH = 64;
32 var CHARA_HEIGHT = 64;
33 var GAME_WIDTH = 800;
34 var GAME_HEIGHT = 600;
35 var FPS = 20;
36 var BASE_FPS = 20;
37 var HUNGRY_MAX = 100;
38 var TIME_SPEED = 4;
39 var MIN = BASE_FPS;
40 var HOUR = MIN * 60;
41 // var DAY = HOUR * 24;
42 var DAY = HOUR ;
43 var GAME_START_TIME = HOUR * 6;
44 //48x48 best?
45 var ICON_WIDTH = 48;
46 var ICON_HEIGHT = 48;
47
48 var EResPath = {
49         YUKKURI_BASE : './data/yukkuri_base.png',
50         YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
51         YUKKURI_UNUN : './data/unun.png',
52         YUKKURI_SHADOW : './data/shadow.png',
53         MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
54         MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
55         MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
56         MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
57         MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
58         MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
59         MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
60         MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
61         MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
62         MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
63         MARISA_HEAR : './data/marisa/hear1.png',
64         MARISA_OKAZARI : './data/marisa/okazari.png',
65         OBJECT : './data/object.png',
66         MAP0 : './data/map0.png',
67         COMMAND : './data/command.png',
68         PLACE_TREE : './data/system/place_tree.png',
69         GRASS : './data/system/grass.png',
70         PLAYER_BADGE : './data/system/player_badge.png',
71         // PLACE_TREE : './data/system/rapture.png',
72 };
73 var EResPathReimu = {
74         getName: function(){
75                 return "reimu";
76         },
77         FACE_NORMAL : './data/reimu/face_normal1.png',
78         FACE_TIRED : './data/reimu/face_tired1.png',
79         FACE_ANGRY : './data/reimu/face_angry1.png',
80         FACE_CRY1 : './data/reimu/face_cry1.png',
81         FACE_CRY2 : './data/reimu/face_cry2.png',
82         FACE_EAT1 : './data/reimu/face_eat1.png',
83         FACE_EAT2 : './data/reimu/face_eat2.png',
84         FACE_HAPPY1 : './data/reimu/face_happy1.png',
85         FACE_HAPPY2 : './data/reimu/face_happy2.png',
86         FACE_SLEEP : './data/reimu/face_sleep1.png',
87         HEAR : './data/reimu/hear1.png',
88         OKAZARI : './data/reimu/okazari.png',
89         SUB1 : './data/reimu/sub1.png',
90
91 };
92
93 var EFace = {
94         NORMAL:0,
95         TIRED:1,
96         ANGRY:2,
97         CRY1:3,
98         CRY2:4,
99         EAT1:5,
100         EAT2:6,
101         HAPPY1:7,
102         HAPPY2:8,
103         SLEEP:9,
104 };
105 var EBody = {
106         NORMAL: 0,
107         DEAD: 1,
108 };
109
110 var ECommand = {
111         WORLD_CURSOR: 0,
112         WORLD_TARGET: 1,
113         WORLD_APPLE: 2,
114         WORLD_PLACE: 3,
115 };
116
117 var EMenuPos = {
118         X : 600,
119         Y : 0,
120         WIDTH : 200,
121         HEIGHT : GAME_HEIGHT,
122 };
123 //width:200px;
124 var EFieldPos = {
125         X : 0,
126         Y : 0,
127         WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
128         HEIGHT: GAME_HEIGHT,
129 };
130 var EAction = {
131         WAIT : 0,
132         HUNT : 3,
133         THINK : 4,
134         WALK : 5,
135         DEAD: 6,
136         EAT_START : 8,
137         EAT_WAIT : 9,
138         MOVE_TO_EAT_START: 10,
139         MOVE_TO_EAT_UNDERWAY: 11,
140         MOVE_TO_COMMAND: 12,
141         UNUN_START : 13,
142         UNUN_WAIT : 14,
143         UNUN_SMELL_START : 15,
144         UNUN_SMELL_WAIT : 16,
145         SLEEP_START : 17,
146         SLEEP_WAIT : 18,
147         COMMUNICATE_START : 19,
148         COMMUNICATE_WAIT: 20,
149         COMMUNICATE_RECV: 21,
150         MOVE_TO_PLACE_START_HOMELESS: 22,
151         MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
152         DECLARE_PLACE_HOMELESS: 24,
153         MOVE_TO_HUNT_START: 25,
154         THINK_SCHEDULE: 26,
155         HUNT_START: 27,
156         MOVE_GOTO_HOME: 28,
157         IN_HOME: 29,
158         THINK_IN_HOME: 30,
159         EAT_IN_HOME: 31,
160         NONE: 9999
161 };
162 var EDirection = {
163         LEFT : 0,
164         RIGHT: 1,
165 };
166 var EMsg = {
167         WALK: 0,
168         SLEEP: 1,
169         EAT: 2,
170         GET_UP: 3,
171         DEAD: 4,
172         UNUN: 5,
173         UNUN_END: 6,
174         UNUN_SMELL: 7,
175         SEARCH_FOOD: 8,
176         EAT_FAILED: 9,
177         SAY_HELLO: 10,
178         TARGETING_EAT : 11,
179         DECLARE_PLACE: 12,
180         HUNT: 13,
181         REHUNT: 14,
182         HUNT_ESCAPE: 15,
183         YYUYYU: 16,
184         MOVE_GOTO_HOME:17,
185         HUNTING_MESSAGE:18,
186         LEARN_NO_FOOD_IN_PLACE:19,
187 };
188 var EWalkAnimation = {
189         START: 0,
190         END: 1,
191 };
192 var EGrow = {
193         ADULT : 0,
194         SUBADULT : 1,
195         CHILD : 2,
196         BABY : 3,
197 };
198 var EDate = {
199         MORNING : 0,
200         NOON : 1,
201         AFTERNOON : 2,
202         EVENING : 3,
203         NIGHT : 4,
204         MIDNIGHT : 5
205 };
206 var ESearch = {
207         UNUN: 0,
208         FOOD: 1,
209         YUKKURI: 2,
210         PLACE: 3
211 };
212 var EFood = {
213         BAD : 0,
214         NORMAL : 1,
215         GREAT : 2
216 };
217 var EExSkill = {
218         NO_FOOD_IN_PLACE : 1,
219         KEKKAI : 2,
220 };
221 var EMemory = {
222         FOOD_IN_PLACE : 1,
223 };
224 var ObjSprite = enchant.Class.create(enchant.Sprite,{
225         initialize: function (w, h){
226                 enchant.Sprite.call(this, w, h);
227                 this.id = guid();
228                 ctl.addObj(this);
229                                 // // new BoxLabel(this.ctl,100, e.x, e.y);
230                                 // var box = new Box(this.ctl, 200, 200);
231                                 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
232         },
233         getStatusForDisplay: function (){
234                 return "";
235         },
236         getX: function(){
237                 return this.x;
238         },
239         getY: function(){
240                 return this.y;
241         },
242         getWidth: function(){
243                 return this.width;
244         },
245         getHeight: function(){
246                 return this.height;
247         },
248         removeAll: function(){
249                 this.remove();
250                 ctl.removeObj(this);
251         }
252 });
253
254
255 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
256         var params = {
257                 x: function() {
258                         return this.x + x;
259                 },
260                 y: function() {
261                         return this.y + y;
262                 },
263                 time: time,
264                 easing: easing
265         };
266         //-Event register [onactionstart,onactiontick,onactionend]
267         if(eventFunctions !== undefined){
268                 for(var key in eventFunctions){
269                         params[key] = eventFunctions[key];
270                 }
271         }
272         return this.tween(params);
273 };
274 function plusFrameScale(frame, scale){
275         return (frame/2) * (1 - scale)
276 }
277
278
279
280 include("./lang/ja.js");
281 window.onload = function(){
282         var nodeSort = function (a, b){
283                 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
284                         return 0;
285                 }
286                 else if(typeof a.id === "undefined"){
287                         return -1;
288                 }
289                 else if(typeof b.id === "undefined"){
290                         return 1;
291                 }
292                 var ay = a.y;
293                 var by = b.y;
294                 if(a instanceof Box && b instanceof Box){
295                         return 0;
296                 }
297                 if(a instanceof Box){
298                         return 1;
299                 }
300                 if(b instanceof Box){
301                         return -1;
302                 }
303                 if(a instanceof SpriteGroup){
304                         ay = a.y;
305                         ay += a.height/2;
306                 }
307                 if(b instanceof SpriteGroup){
308                         by = b.y;
309                         by += b.height /2;
310                 }
311
312                 if(a instanceof Place){
313                         ay += Math.round(a.height * 0.7);
314                 }
315                 if(b instanceof Place){
316                         by += Math.round(b.height * 0.7);
317                 }
318
319                 if(ay < by)return -1;
320                 else if(ay > by)return 1;
321                 if(a.id < b.id)return -1;
322                 else if(a.id > b.id)return 1;
323                 return 0;
324
325         }
326
327         //init game
328         var def = new Object();
329         var foodGroup = new Group();
330         var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
331         var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
332         var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
333         var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
334         var game = new Game(GAME_WIDTH, GAME_HEIGHT);
335         game.fps = FPS;
336         var _loadArr = [];
337         var i=0;
338         var tmpName = EResPathReimu.getName();
339         i=0;
340         for(var _v in EResPathReimu){
341                 if(typeof EResPathReimu[_v] === "function")continue;
342                 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
343                 i++;
344         }
345         tmpName = null;
346
347         i=0;
348         for(var _v in EResPath){
349                 _loadArr[i] = EResPath[_v];
350                 i++;
351         }
352         game.preload(_loadArr);
353         var MapGroup = enchant.Class.mixClasses(Map, Group,true);
354         var backgroundMap = new MapGroup(16, 16);
355         include("./class.js");
356         include("./ctrl.js");
357         ctl = new Ctrl();
358         ctl.init(game);
359         ctl.setBackgroundMap(backgroundMap);
360         var Action = enchant.Class.create({
361                 initialize: function (yukkuri){
362                         this.status = EAction.THINK;
363                         this.yukkuri = yukkuri;
364                         this.isMoving = false;
365                         this.targetNode = null;
366                 },
367                 getStatus: function(){
368                         return this.status;
369                 },
370                 setStatus: function(eaction){
371                         this.status = eaction;
372                 },
373                 observe: function(){
374                         if(this.yukkuri.isDead()){
375                                 this.status = EAction.DEAD;
376                         }
377                         // else if(this.yukkuri.isSleep()){
378                         //      this.status = EAction.SLEEP;
379                         // }
380
381                 },
382                 act : function(){
383
384                         this.observe();
385                         switch(this.status){
386                                 case EAction.WAIT:
387                                         this.waitCnt++;
388                                         if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
389                                                 this.waitCnt = 0;
390                                                 this.setStatus(EAction.THINK);
391                                                 console.log("wait cnt end");
392                                         }
393                                 break;
394                                 case EAction.THINK_IN_HOME:
395                                         this.waitCnt = 0;
396                                         this.search();
397                                         this.think_in_home();
398                                 break;
399                                 case EAction.EAT_IN_HOME:
400                                         this.eat_in_home();
401                                 break;
402                                 case EAction.THINK:
403                                         this.waitCnt = 0;
404                                         if(this.yukkuri.age%2 === 0){
405                                                 this.yukkuri.changeFace();
406                                                 this.search();
407                                                 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
408                                         }
409                                 break;
410                                 case EAction.MOVE_TO_EAT_START:
411                                         this.move_to_eat_start();
412                                 break;
413                                 case EAction.MOVE_TO_EAT_UNDERWAY:
414                                 break;
415                                 //Random Walk
416                                 case EAction.WALK:
417                                         this.walk(0);
418                                 break;
419                                 case EAction.SLEEP_START:
420                                         this.sleep_start();
421                                 break;
422                                 case EAction.SLEEP_WAIT:
423                                 break;
424                                 case EAction.DEAD:
425                                         this.dead();
426                                 break;
427                                 case EAction.EAT_START:
428                                         this.eat_start();
429                                 break;
430                                 case EAction.EAT_WAIT:
431                                 break;
432                                 case EAction.UNUN_START:
433                                         this.unun_start();
434                                 break;
435                                 case EAction.UNUN_WAIT:
436                                 break;
437                                 case EAction.MOVE_TO_COMMAND:
438                                         this.move_to_command();
439                                 break;
440                                 case EAction.UNUN_SMELL_START:
441                                         this.unun_smell_start();
442                                 break;
443                                 case EAction.COMMUNICATE_START:
444                                         this.communicate_start();
445                                 break;
446                                 case EAction.COMMUNICATE_WAIT:
447                                 break;
448                                 case EAction.COMMUNICATE_RECV:
449                                 break;
450                                 case EAction.MOVE_TO_PLACE_START_HOMELESS:
451                                         this.move_to_place_start_homeless();
452                                 break;
453                                 case EAction.DECLARE_PLACE_HOMELESS:
454                                         this.declare_place_homeless();
455                                 break;
456                                 case EAction.MOVE_TO_HUNT_START:
457                                         this.move_to_hunt_start();
458                                 break;
459                                 case EAction.HUNT_START:
460                                         this.hunt_start();
461                                 break;
462                                 case EAction.MOVE_GOTO_HOME:
463                                         this.move_goto_home();
464                                 break;
465                                 case EAction.IN_HOME:
466                                         this.in_home();
467                                 break;
468
469                         }
470                         this.yukkuri.reverse();
471                 },
472                 // thinkHavePlace: function(){
473                 //      var date = ctl.getDate();
474                 //      if(this.yukkuri.isPlaceRange()){
475                 //      }else{
476                 //              //ゆっくりプレイスの範囲外
477                 //              if(date === EDate.EVENING
478                 //                      || date === EDate.NIGHT
479                 //                      || date === EDate.MIDNIGHT
480                 //                      ){
481                 //                      this.setStatus(EAction.MOVE_GOTO_HOME);
482                 //                      return;
483                 //              }
484                 //              else if(date === EDate.EVENING){
485                 //                      // if(this.yukkuri.isItemsMax()){
486                 //                      //      this.setStatus(EAction.IN_HOME);
487                 //                      // }
488                 //                      // else{
489                 //                      //      this.setStatus(EAction.MOVE_TO_HUNT_START);
490                 //                      // }
491                 //              }
492                 //      }
493                 //      if(this.yukkuri.isVeryKuhuku()){
494                 //              //食べ物探したい
495
496                 //              //なかったら
497                 //              this.setStatus(EAction.MOVE_GOTO_HOME);
498                 //      }
499                 //      else if(this.yukkuri.isSleep()){
500                 //              this.setStatus(EAction.SLEEP_START);
501                 //      }
502                 //      else if(this.yukkuri.getUnun() >= 80){
503                 //              this.setStatus(EAction.UNUN_START);
504                 //      }
505                 //      else{
506                 //              this.yukkuri.changeFace();
507                 //              this.search();
508                 //      }
509                 // },
510                 think_in_home: function(){
511                         var date = ctl.getDate();
512                         if((date === EDate.MIDNIGHT)
513                                 && !this.yukkuri.isSleep()
514                                 && !this.yukkuri.isVeryKuhuku()
515                                 ){
516                                 new SleepEvent({
517                                         "action": this,
518                                         "nextStatus":EAction.THINK_IN_HOME,
519                                         "myYukkuri": this.yukkuri
520                                 });
521                                 return;
522                         }
523                         else if(date === EDate.EVENING){
524                                 //QK
525                         }
526                         else if(this.yukkuri.isVeryKuhuku() && this.yukkuri.getPlace().isFood()){
527                                 this.setStatus(EAction.EAT_IN_HOME);
528                         }
529                         else{
530                                 //marisa is hunting move
531                                 if(this.yukkuri.beforeHuntingFood !== null){
532                                         new MoveToHuntEvent({
533                                                 "type": 'food',
534                                                 "targetNode": this.yukkuri.beforeHuntingFood,
535                                                 "action": this,
536                                                 "myYukkuri": this.yukkuri
537                                         });
538                                         return;
539                                 }else{
540                                         this.setStatus(EAction.WALK);
541                                 }
542                         }
543                 },
544                 eat_in_home: function(){
545                         new EatInHomeEvent({
546                                 "targetNode": this.yukkuri.getPlace(),
547                                 "action": this,
548                                 "myYukkuri": this.yukkuri
549                         });
550                 },
551                 move_to_eat_start : function(){
552                         new MoveToEatEvent({
553                                 "type": 'food',
554                                 "targetNode": this.targetNode,
555                                 "action": this,
556                                 "myYukkuri": this.yukkuri
557                         });
558                 },
559                 walkNew: function(){
560
561                 },
562                 walk : function(retryCounter){
563                         if(retryCounter > 15){
564                                 retryCounter = 0;
565                                 this.status = EAction.NONE;
566                                 console.log("retryCount over");
567                                 return;
568                         }
569                         if(this.yukkuri.imgGroup.tl.queue.length === 0){
570                                 var frame = 200;
571                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
572                                 if(this.isMoving){
573                                         this.isMoving = false;
574                                         this.status = EAction.THINK;
575                                         this.yukkuri.vx = 0;
576                                         this.yukkuri.vy = 0;
577                                 }else{
578                                         var xpos = 150 + rand(40) - (retryCounter * 10);
579                                         var ypos = 150 + rand(40) - (retryCounter * 10);
580                                         if(rand(8) === 0){
581                                                 this.yukkuri.vx = 0;
582                                                 this.yukkuri.vy = -ypos;
583                                         }
584                                         else if(rand(8) == 1){
585                                                 this.yukkuri.vx = xpos;
586                                                 this.yukkuri.vy = -ypos;
587                                                 this.yukkuri.direction = EDirection.RIGHT;
588                                         }
589                                         else if(rand(8) == 2){
590                                                 this.yukkuri.vx = xpos;
591                                                 this.yukkuri.vy = 0;
592                                                 this.yukkuri.direction = EDirection.RIGHT;
593                                         }
594                                         else if(rand(8) == 3){
595                                                 this.yukkuri.vx = xpos;
596                                                 this.yukkuri.vy = ypos;
597                                                 this.yukkuri.direction = EDirection.RIGHT;
598                                         }
599                                         else if(rand(8) == 4){
600                                                 this.yukkuri.vx = 0;
601                                                 this.yukkuri.vy = ypos;
602                                         }
603                                         else if(rand(8) == 5){
604                                                 this.yukkuri.vx = -xpos;
605                                                 this.yukkuri.vy = ypos;
606                                                 this.yukkuri.direction = EDirection.LEFT;
607                                         }
608                                         else if(rand(8) == 6){
609                                                 this.yukkuri.vx = -xpos;
610                                                 this.yukkuri.vy = 0;
611                                                 this.yukkuri.direction = EDirection.LEFT;
612                                         }
613                                         else if(rand(8) == 7){
614                                                 this.yukkuri.vx = -xpos;
615                                                 this.yukkuri.vy = -ypos;
616                                                 this.yukkuri.direction = EDirection.LEFT;
617                                         }
618                                         if (this.yukkuri.vx || this.yukkuri.vy) {
619                                                 var map = ctl.backgroundMap;
620                                                 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
621                                                 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
622                                                 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
623                                                 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
624                                                 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
625                                                         // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
626                                                         // console.log("X:" + this.yukkuri.moveX);
627                                                         // console.log("Y:" + this.yukkuri.moveY);
628                                                         this.isMoving = true;
629                                                         this.yukkuri.reverse();
630                                                         this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
631                                                         mangMsg.output(this.yukkuri,EMsg.WALK);
632                                                         //うんうんくさい対策
633                                                         this.targetNode = null;
634                                                 }else{
635                                                         // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
636                                                         this.walk(retryCounter+1);
637                                                 }
638                                         }
639                                 }
640                         }
641                 },
642                 sleep_start: function(){
643                         new SleepEvent({
644                                 "action": this,
645                                 "myYukkuri": this.yukkuri
646                         });
647                 },
648                 dead : function(){
649                         mangMsg.output(this.yukkuri, EMsg.DEAD);
650                         this.yukkuri.tlPause();
651                         this.yukkuri.setBodyImage(EBody.DEAD);
652                 },
653                 eat_start: function(){
654                         new EatEvent({
655                                 "type": 'eat',
656                                 "targetNode": this.targetNode,
657                                 "action": this,
658                                 "myYukkuri": this.yukkuri
659                         });
660
661                 },
662                 unun_start: function(){
663                         new UnunEvent({
664                                 "action": this,
665                                 "myYukkuri": this.yukkuri
666                         });
667                 },
668                 unun_smell_start: function(){
669                         new UnunSmellEvent({
670                                 "action": this,
671                                 "myYukkuri": this.yukkuri
672                         });
673                 },
674                 communicate_start:function(){
675                         new ComSayHelloSendEvent({
676                                 "type": 'greeting',
677                                 "targetNode": this.targetNode,
678                                 "action": this,
679                                 "myYukkuri": this.yukkuri
680                         });
681                 },
682                 move_to_place_start_homeless:function(){
683                         new MoveToPlaceStartHomelessEvent({
684                                 "targetNode": this.targetNode,
685                                 "action": this,
686                                 "myYukkuri": this.yukkuri
687                         });
688                 },
689                 declare_place_homeless:function(){
690                         new DeclarePlaceHomelessEvent({
691                                 "targetNode": this.targetNode,
692                                 "action": this,
693                                 "myYukkuri": this.yukkuri
694                         });
695                 },
696                 move_to_hunt_start:function(){
697                         new MoveToHuntEvent({
698                                 "type": 'food',
699                                 "targetNode": this.targetNode,
700                                 "action": this,
701                                 "myYukkuri": this.yukkuri
702                         });
703                 },
704                 hunt_start:function(){
705                         new HuntStartEvent({
706                                 "type": 'food',
707                                 "targetNode": this.targetNode,
708                                 "action": this,
709                                 "myYukkuri": this.yukkuri
710                         });
711                 },
712                 move_goto_home:function(){
713                         var place = this.yukkuri.getPlace();
714                         new MoveGotoHomeEvent({
715                                 "type": 'hunt_end',
716                                 "targetNode": place,
717                                 "action": this,
718                                 "myYukkuri": this.yukkuri
719                         });
720                 },
721                 in_home:function(){
722                         var place = this.yukkuri.getPlace();
723                         new InHomeEvent({
724                                 "type": 'hunt_end',
725                                 "targetNode": place,
726                                 "action": this,
727                                 "myYukkuri": this.yukkuri
728                         });
729                 },
730                 move_to_command: function(){
731                         var obj = this.yukkuri.searchObjectMang.currentCmdObject;
732                         new MoveToCommandEvent({
733                                 "action": this,
734                                 "cmdObject": obj,
735                                 "myYukkuri": this.yukkuri
736                         });
737
738                 },
739                 search: function(){
740                         this.yukkuri.clearSearchObject();
741                         var nodes = ctl.getObjs();
742                         l = nodes.length;
743                         var ununFlg = false;
744                         for (var key in nodes) {
745                                 var node = nodes[key];
746                                 if(this.yukkuri.id === node.id)continue;
747                                 //うんうん臭いを検索
748                                 if (
749                                         node instanceof Unun
750                                         && !(this.targetNode instanceof Unun)
751                                         && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
752
753                                         this.yukkuri.addSearchObject(ESearch.UNUN, node);
754                                 }
755                                 //食べ物を検索
756                                 else if (node instanceof Food && node.amount > 0) {
757                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
758                                                 this.yukkuri.addSearchObject(ESearch.FOOD, node);
759                                         }
760                                 }
761                                 //ゆっくりを検索
762                                 else if(node instanceof Yukkuri){
763                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
764                                                 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
765                                         }
766                                 }
767                                 //ゆっくりプレイスを検索
768                                 else if(node instanceof Place){
769                                         if(this.yukkuri instanceof Player){
770                                         }
771                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
772                                                 this.yukkuri.addSearchObject(ESearch.PLACE, node);
773                                         }
774                                 }
775                         }
776                         this.status =  EAction.WALK;
777                 }
778         });
779 /**
780  * Range範囲内のObjSprを管理する
781  * 注意!:ゆっくりプレイスを持って入るもののみ使用される
782  * @param  {[type]} )
783  * @return {[type]}
784  */
785         var SearchObjectMang = enchant.Class.create({
786                 initialize: function (){
787                         this.init();
788                         this.currentCmdObject = null;
789                 },
790                 init:function(){
791                         this.datas = [];
792                         for(var key in ESearch){
793                                 var esearch = ESearch[key];
794                                 this.datas[esearch] = [];
795                         }
796                 },
797                 add :function(esearch, node){
798                         this.datas[esearch].push(node);
799                 },
800                 clear :function(){
801                         for(var key in ESearch){
802                                 var esearch = ESearch[key];
803                                 this.datas[esearch].length = 0;
804                         }
805                         // this.datas.length = 0;
806                         // this.init();
807                 },
808                 get:function (esearch){
809                         return this.datas[esearch];
810                 },
811                 getNear:function (esearch, yukkuri){
812                         var objects = this.datas[esearch];
813                         var nearDistance = null;
814                         var ret = null;
815                         for(var i=0;i<objects.length;i++){
816                                 var object = objects[i];
817                                 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
818                                 if(nearDistance === null || nearDistance > nowDistance){
819                                         nearDistance = nowDistance;
820                                         ret = object;
821                                 }
822                         }
823                         return ret;
824                 },
825                 callEvent: function(yukkuri){
826                         if(yukkuri.cmdQueue.length !== 0){
827                                 this.currentCmdObject = yukkuri.cmdQueue.shift();
828                                 yukkuri.action.setStatus(EAction.MOVE_TO_COMMAND);
829                                 return;
830                         }
831
832                         if(yukkuri.isItemsMax() && yukkuri.isPlace()){
833                                 yukkuri.action.targetNode = yukkuri.getPlace();
834                                 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
835                                 return;
836                         }
837                         if(yukkuri.isVeryKuhuku()){
838                                 //エサを探す
839                                 var foods = this.get(ESearch.FOOD);
840                                 if(foods.length > 0){
841                                         var foods = this.get(ESearch.FOOD);
842                                         food = this.getNear(ESearch.FOOD, yukkuri);
843                                         if(food !== null){
844                                                 yukkuri.action.targetNode = food;
845                                                 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
846                                                 return;
847                                         }
848                                 }
849                                 if(yukkuri.getMemory(EMemory.FOOD_IN_PLACE) === 0 && yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
850                                         yukkuri.action.setStatus(EAction.WALK);
851                                         return;
852                                 }
853
854                                 if(foods.length === 0 && yukkuri.isPlace()){
855                                         //家があるなら家に帰宅
856                                         yukkuri.action.targetNode = yukkuri.getPlace();
857                                         yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
858                                         return;
859                                 }else{
860                                 }
861                         }
862
863                         if(yukkuri.isSleep()){
864                                 yukkuri.action.setStatus(EAction.SLEEP_START);
865                                 return;
866                         }
867
868                         else if(yukkuri.getUnun() >= 80){
869                                 yukkuri.action.setStatus(EAction.UNUN_START);
870                                 return;
871                         }
872
873
874                         if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
875                                 food = this.getNear(ESearch.FOOD, yukkuri);
876                                 if(food !== null){
877                                         yukkuri.action.targetNode = food;
878                                         yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
879                                         return;
880                                 }
881                         }
882                         ununs = this.get(ESearch.UNUN);
883                         if(ununs.length !== 0){
884                                 yukkuri.action.targetNode = yukkuri.getPlace();
885                                 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
886                                 return;
887                         }
888                         var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
889                         if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
890                                 yukkuri.action.targetNode = searchYukkuri;
891                                 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
892                                 return;
893                         }
894                         if(!yukkuri.isPlace()){
895                                 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
896                                 if(searchYukkuri != null && !searchYukkuri.isOwner()){
897                                         yukkuri.action.targetNode = searchYukkuri;
898                                         yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
899                                         return;
900                                 }
901                         }
902                         yukkuri.action.setStatus(EAction.WALK);
903
904                 }
905
906         });
907         var Event = enchant.Class.create({
908                 initialize: function (_data){
909                         this.guid = guid();
910                 },
911                 onactionstart:function(self){
912                         return this._onactionstart;
913                 },
914                 _onactionstart:function(e){
915                         if(typeof e === "undefined")return;
916                 },
917                 onactiontick:function(self){
918                         return function(e){
919                                 if(typeof e === "undefined")return;
920                         };
921                 },
922                 onactionend:function(self){
923                         return function(e){
924                                 if(typeof e === "undefined")return;
925                         };
926                 }
927         });
928         var WalkEvent = enchant.Class.create(Event,{
929                 initialize: function (_data){
930                         this.data = _data;
931                         this.yukkuri = _data.myYukkuri;
932                         this.action = _data.action;
933
934                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
935                         this.action.setStatus(EAction.SLEEP_WAIT);
936                         this.yukkuri.setFaceImage(EFace.SLEEP);
937                         this.yukkuri.tlPause();
938                         var self = this;
939                         this.yukkuri.addEventListener('enterframe', function() {
940                                 var yukkuri = self.yukkuri;
941                                 self.run();
942                         });
943                 },
944                 run : function(){
945
946                 }
947         });
948         var SleepEvent = enchant.Class.create(Event,{
949                 initialize: function (_data){
950                         this.data = _data;
951                         this.yukkuri = _data.myYukkuri;
952                         this.action = _data.action;
953
954                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
955                         this.action.setStatus(EAction.SLEEP_WAIT);
956                         this.yukkuri.setFaceImage(EFace.SLEEP);
957                         this.yukkuri.tlPause();
958                         var sec = FPS * 3;
959                         var self = this;
960                         this.yukkuri.addEventListener('enterframe', function() {
961                                 var yukkuri = self.yukkuri;
962                                 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
963                                 if(yukkuri.param.sleep <= 0){
964                                         yukkuri.param.sleep = 0;
965                                         this.removeEventListener("enterframe",arguments.callee);
966                                         mangMsg.output(self.yukkuri, EMsg.GET_UP);
967                                         yukkuri.setFaceImage(EFace.NORMAL);
968                                         yukkuri.tlResume();
969                                         // self.action.setStatus(EAction.WAIT);
970                                         if(self.data.nextStatus !== undefined){
971                                                 self.action.setStatus(self.data.nextStatus);
972                                         }else{
973                                                 self.action.setStatus(EAction.THINK);
974                                         }
975                                 }
976                         });
977                 }
978         });
979
980         var UnunEvent = enchant.Class.create(Event,{
981                 initialize: function (_data){
982                         this.data = _data;
983                         this.yukkuri = _data.myYukkuri;
984                         this.action = _data.action;
985                         this.action.setStatus(EAction.UNUN_WAIT);
986                         mangMsg.output(this.yukkuri, EMsg.UNUN);
987                         this.yukkuri.setFaceImage(EFace.HAPPY2);
988                         var sec = FPS * 3;
989
990                         this.yukkuri.wait(sec, {
991                                 "onactionend": this.onactionend(this)
992                         });
993                 },
994                 onactionend:function(self){
995                         return function(e){
996                                 if(typeof e === "undefined")return;
997                                 self.yukkuri.unun();
998                                 self.action.setStatus(EAction.WAIT);
999                                 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
1000                                 new WaitEvent({
1001                                         "waitframe": FPS * 1.5,
1002                                         "action": self.action,
1003                                         "myYukkuri": self.yukkuri
1004                                 });
1005                         };
1006                 }
1007         });
1008         var WaitEvent = enchant.Class.create(Event,{
1009                 initialize: function (_data){
1010                         this.data = _data;
1011                         this.yukkuri = _data.myYukkuri;
1012                         this.action = _data.action;
1013                         this.waitframe = _data.waitframe;
1014                         this.yukkuri.wait(this.waitframe, {
1015                                 "onactionstart": this.onactionstart(this),
1016                                 "onactiontick": this.onactiontick(this),
1017                                 "onactionend": this.onactionend(this)
1018                         });
1019                 },
1020                 onactionend:function(self){
1021                         return function(e){
1022                                 if(typeof e === "undefined")return;
1023                                 self.action.setStatus(EAction.THINK);
1024                         };
1025                 }
1026         });
1027         var UnunSmellEvent = enchant.Class.create(Event,{
1028                 initialize: function (_data){
1029                         this.data = _data;
1030                         this.yukkuri = _data.myYukkuri;
1031                         this.action = _data.action;
1032                         this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1033                         mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1034                         this.yukkuri.setFaceImage(EFace.CRY1);
1035                         var sec = FPS * 3;
1036                         this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1037                         this.yukkuri.wait(sec, {
1038                                 "onactionend": this.onactionend(this)
1039                         });
1040                 },
1041                 onactionend:function(self){
1042                         return function(e){
1043                                 if(typeof e === "undefined")return;
1044                                 self.action.setStatus(EAction.WALK);
1045                         };
1046                 }
1047         });
1048
1049         var EatEvent = enchant.Class.create(Event,{
1050                 initialize: function (_data){
1051                         this.data = _data;
1052                         this.yukkuri = _data.myYukkuri;
1053                         this.food = _data.targetNode;
1054                         this.action = _data.action;
1055                         this.action.setStatus(EAction.EAT_WAIT);
1056
1057
1058                         var sec = BASE_FPS * 3;
1059                         if(this.yukkuri.eat(this.food)){
1060                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1061                                 this.yukkuri.setFaceImage(EFace.EAT2);
1062                         }else{
1063                                 sec = BASE_FPS * 6;
1064                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1065                                 this.yukkuri.setFaceImage(EFace.CRY2);
1066                         }
1067                         this.yukkuri.wait(sec, {
1068                                 "onactionend": this.onactionend(this)
1069                         });
1070                 },
1071                 onactionend:function(self){
1072                         return function(e){
1073                                 if(typeof e === "undefined")return;
1074                                 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1075                                         self.action.setStatus(EAction.THINK);
1076                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1077                                 }else{
1078                                         self.action.setStatus(EAction.EAT_START);
1079                                 }
1080                         };
1081                 }
1082         });
1083         /**
1084          * Move Event
1085          * -When yukkuri find Food.
1086          * @param  _data
1087          * type: "food"
1088          * targetNode: enchant.Node
1089          * action:Action
1090          * myYukkuri:Yukkuri
1091          */
1092         var MoveToEatEvent = enchant.Class.create(Event,{
1093                 initialize: function (_data){
1094                         this.data = _data;
1095                         this.yukkuri = this.data.myYukkuri;
1096                         this.action = this.data.action;
1097
1098                         var yukkuri = this.yukkuri;
1099                         var node = this.data.targetNode;
1100                         //food distance
1101                         if(this.data.type == "food"){
1102                                 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1103                                 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1104                                 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1105                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1106                                 var frame = distance + distance/5 + 1;
1107                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1108                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1109                                 yukkuri.reverse();
1110
1111                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1112                                         "onactionstart": this.onactionstart(this),
1113                                         "onactiontick": this.onactiontick(this),
1114                                         "onactionend": this.onactionend(this)
1115                                 });
1116                         }
1117                 },
1118                 onactionstart:function(self){
1119                         return function(e){
1120                                 if(typeof e === "undefined")return;
1121                                 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1122                         };
1123                 },
1124                 onactiontick:function(self){
1125                         return function(e){
1126                                 if(typeof e === "undefined")return;
1127                         };
1128                 },
1129                 onactionend:function(self){
1130                         return function(e){
1131                                 if(typeof e === "undefined")return;
1132                                 self.action.setStatus(EAction.EAT_START);
1133                         };
1134                 }
1135         });
1136         var MoveToHuntEvent = enchant.Class.create(Event,{
1137                 initialize: function (_data){
1138                         this.data = _data;
1139                         this.yukkuri = this.data.myYukkuri;
1140                         this.action = this.data.action;
1141
1142                         var yukkuri = this.yukkuri;
1143                         var node = this.data.targetNode;
1144                         var nodeX = node.x;
1145                         var nodeY = node.y;
1146                         var nodeWidth = node.width;
1147                         var nodeHeight = node.height;
1148                         node = null;
1149
1150                         //food distance
1151                         if(this.data.type == "food"){
1152                                 this.action.setStatus(EAction.WAIT);
1153                                 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1154                                 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1155                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1156                                 var frame = distance + distance/5 + 1;
1157                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1158                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1159                                 yukkuri.reverse();
1160                                 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1161
1162                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1163                                         "onactionend": this.onactionend(this)
1164                                 });
1165                         }
1166                 },
1167                 onactionend:function(self){
1168                         return function(e){
1169                                 if(typeof e === "undefined")return;
1170                                 self.action.setStatus(EAction.HUNT_START);
1171                         };
1172                 }
1173         });
1174         var HuntStartEvent = enchant.Class.create(Event,{
1175                 initialize: function (_data){
1176                         Event.call(this, _data);
1177                         this.initCnt = 0;
1178                         this.data = _data;
1179                         this.yukkuri = _data.myYukkuri;
1180                         this.food = _data.targetNode;
1181                         this.action = _data.action;
1182                         this.action.setStatus(EAction.WAIT);
1183                         this.huntingStatus = "hunting";
1184                         this.tick = 0;
1185                         this.yukkuri.beforeHuntingFood = this.food;
1186                         var sec = BASE_FPS * 8;
1187                         if(this.yukkuri.hunt(this.food)){
1188                                 this.huntingStatus = "hunting";
1189                                 mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1190                                 this.yukkuri.setFaceImage(EFace.HAPPY1);
1191                         }else{
1192                                 if(this.yukkuri.isItemsMax()){
1193                                         sec = 1;
1194                                         this.huntingStatus = "return";
1195                                         // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1196                                         this.yukkuri.setFaceImage(EFace.NORMAL);
1197                                 }else{
1198                                         sec = BASE_FPS * 3;
1199                                         this.huntingStatus = "cry";
1200                                         mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1201                                         this.yukkuri.setFaceImage(EFace.CRY2);
1202                                 }
1203                         }
1204
1205                         this.yukkuri.wait(sec, {
1206                                 "onactiontick": this.onactiontick(this),
1207                                 "onactionend": this.onactionend(this)
1208                         });
1209                 },
1210                 onactiontick:function(self){
1211                         return function(e){
1212                                 if(typeof e === "undefined")return;
1213                                 self.tick++;
1214                                 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1215                                         if(this.age%(BASE_FPS * 5) == 0){
1216                                                 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1217                                                 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1218                                         }
1219                                 }
1220                         };
1221                 },
1222                 onactionend:function(self){
1223                         return function(e){
1224                                 if(typeof e === "undefined")return;
1225                                 if(self.huntingStatus == "hunting"){
1226                                         if(self.yukkuri.isItemsMax()){
1227                                                 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1228                                                 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1229                                         }else{
1230                                                 self.action.setStatus(EAction.HUNT_START);
1231                                         }
1232                                 }
1233                                 else if(self.huntingStatus == "return"){
1234                                         self.action.setStatus(EAction.MOVE_GOTO_HOME);
1235                                 }
1236                                 else if(self.huntingStatus === "cry"){
1237                                         // self.action.setStatus(EAction.THINK);
1238                                         self.action.setStatus(EAction.WALK);
1239                                 }
1240                                 self.release();
1241                         };
1242                 },
1243                 release:function(){
1244                         this.action = null;
1245                         this.yukkuri = null;
1246                         this.food = null;
1247                         this.data = null;
1248                 }
1249         });
1250         var MoveGotoHomeEvent = enchant.Class.create(Event,{
1251                 initialize: function (_data){
1252                         this.data = _data;
1253                         this.yukkuri = this.data.myYukkuri;
1254                         this.action = this.data.action;
1255
1256                         var yukkuri = this.yukkuri;
1257                         var place = this.data.targetNode;
1258                         //food distance
1259                         if(this.data.type == "hunt_end"){
1260                                 this.action.setStatus(EAction.WAIT);
1261                                 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1262                                 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1263                                 // console.log("place.x:" + place.x);
1264                                 // console.log("place.y:" + place.y);
1265                                 // console.log("yukkuri.getX():" + yukkuri.getX());
1266                                 // console.log("yukkuri.getY():" + yukkuri.getY());
1267                                 // console.log("yukkuri.vx:" + yukkuri.vx);
1268                                 // console.log("yukkuri.vy:" + yukkuri.vy);
1269                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1270                                 var frame = distance + distance/2 + 1 ;
1271                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1272                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1273                                 yukkuri.reverse();
1274                                 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1275
1276                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1277                                         "onactiontick": this.onactiontick(this),
1278                                         "onactionend": this.onactionend(this)
1279                                 });
1280                         }
1281                 },
1282                 onactiontick:function(self){
1283                         return function(e){
1284                                 if(typeof e === "undefined")return;
1285                                 if(this.age%(BASE_FPS * 5) == 0){
1286                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1287                                 }
1288                         };
1289                 },
1290                 onactionend:function(self){
1291                         return function(e){
1292                                 if(typeof e === "undefined")return;
1293                                 self.action.setStatus(EAction.IN_HOME);
1294                                 self.release();
1295                         };
1296                 },
1297                 release:function(){
1298                         this.action = null;
1299                         this.yukkuri = null;
1300                         this.data = null;
1301                 }
1302         });
1303         var InHomeEvent = enchant.Class.create(Event,{
1304                 initialize: function (_data){
1305                         this.data = _data;
1306                         this.yukkuri = this.data.myYukkuri;
1307                         this.action = this.data.action;
1308
1309                         var yukkuri = this.yukkuri;
1310                         var place = this.data.targetNode;
1311
1312                         if(yukkuri.isVeryKuhuku()){
1313                                 if(place.isFood()){
1314                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1315                                         this.action.setStatus(EAction.EAT_IN_HOME);
1316                                         return;
1317                                 }else{
1318                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1319                                         //experience skill
1320                                         if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1321                                                 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1322                                                 this.action.setStatus(EAction.THINK);
1323                                                 return;
1324                                         }else{
1325                                                 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1326                                                 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1327                                         }
1328
1329                                 }
1330                         }
1331                         this.action.setStatus(EAction.WAIT);
1332                         var items = this.yukkuri.getItems();
1333                         if(items.length > 0){
1334                                 place.setItems(items);
1335                         }else{
1336
1337                         }
1338                         var sec = BASE_FPS * 10;
1339                         if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1340                         this.yukkuri.wait(sec, {
1341                                 "onactiontick": this.onactiontick(this),
1342                                 "onactionend": this.onactionend(this)
1343                         });
1344                 },
1345                 onactiontick:function(self){
1346                         return function(e){
1347                                 if(typeof e === "undefined")return;
1348                                 if(this.age%(BASE_FPS * 5) == 0){
1349                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1350                                 }
1351                         };
1352                 },
1353                 onactionend:function(self){
1354                         return function(e){
1355                                 if(typeof e === "undefined")return;
1356                                 self.action.setStatus(EAction.THINK_IN_HOME);
1357                         };
1358                 }
1359         });
1360         var EatInHomeEvent = enchant.Class.create(Event,{
1361                 initialize: function (_data){
1362                         this.data = _data;
1363                         this.yukkuri = _data.myYukkuri;
1364                         this.place = _data.targetNode;
1365                         this.action = _data.action;
1366                         this.action.setStatus(EAction.EAT_WAIT);
1367
1368                         var sec = BASE_FPS * 3;
1369                         var foodHash = this.place.getFoodHash();
1370                         if(foodHash !== false && this.yukkuri.eat(foodHash)){
1371                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1372                                 this.yukkuri.setFaceImage(EFace.EAT2);
1373                         }else{
1374                                 sec = BASE_FPS * 6;
1375                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1376                                 this.yukkuri.setFaceImage(EFace.CRY2);
1377                         }
1378
1379                         this.yukkuri.wait(sec, {
1380                                 "onactionend": this.onactionend(this)
1381                         });
1382                 },
1383                 onactionend:function(self){
1384                         return function(e){
1385                                 if(typeof e === "undefined")return;
1386                                 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1387                                         self.action.setStatus(EAction.EAT_IN_HOME);
1388
1389                                         // new EatInHomeEvent({
1390                                         //      "targetNode": self.place,
1391                                         //      "action": self.action,
1392                                         //      "myYukkuri": self.yukkuri
1393                                         // });
1394                                 }else{
1395                                         self.action.setStatus(EAction.THINK_IN_HOME);
1396                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1397                                 }
1398                         };
1399                 }
1400         });
1401
1402
1403         var MoveToCommandEvent = enchant.Class.create(Event,{
1404                 initialize: function (_data){
1405                         this.data = _data;
1406                         this.yukkuri = this.data.myYukkuri;
1407                         this.action = this.data.action;
1408                         // this.vx = this.data.cmdObject.vx;
1409                         // this.vy = this.data.cmdObject.vy;
1410                         // var vx = (-backgroundMap.x + e.x) - this.ctl.player.getX() ;
1411
1412
1413                         var yukkuri = this.yukkuri;
1414                         this.action.status = EAction.WAIT;
1415                         yukkuri.vx = this.data.cmdObject.touchX - this.yukkuri.getX();
1416                         yukkuri.vy = this.data.cmdObject.touchY - this.yukkuri.getY();
1417                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1418                         var frame = distance + distance/2 + 1;
1419                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1420
1421                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1422
1423                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1424                                 "onactiontick": this.onactiontick(this),
1425                                 "onactionend": this.onactionend(this)
1426                         });
1427                 },
1428                 onactiontick:function(self){
1429                         return function(e){
1430                                 if(typeof e === "undefined")return;
1431                         };
1432                 },
1433                 onactionend:function(self){
1434                         return function(e){
1435                                 if(typeof e === "undefined")return;
1436                                 self.action.setStatus(EAction.THINK);
1437                         };
1438                 }
1439         });
1440         /**
1441          * Say hello contact to send communication .
1442          */
1443         var ComSayHelloSendEvent = enchant.Class.create(Event,{
1444                 initialize: function (_data){
1445                         this.data = _data;
1446                         this.yukkuri = _data.myYukkuri;
1447                         this.targetYukkuri = _data.targetNode;
1448                         this.action = _data.action;
1449                         this.action.setStatus(EAction.COMMUNICATE_WAIT);
1450                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1451
1452
1453                         this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1454                         this.targetYukkuri.tlPause();
1455                         this.yukkuri.tlPause();
1456                         this.yukkuri.syncDirection(this.targetYukkuri);
1457
1458                         this.yukkuri.addAddress(this.targetYukkuri);
1459                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1460
1461                         var sec = BASE_FPS * 2;
1462                         this.yukkuri.wait(sec, {
1463                                 "onactiontick": this.onactiontick(this),
1464                                 "onactionend": this.onactionend(this)
1465                         });
1466                 },
1467                 onactiontick:function(self){
1468                         return function(e){
1469                                 if(typeof e === "undefined")return;
1470                         };
1471                 },
1472                 onactionend:function(self){
1473                         return function(e){
1474                                 if(typeof e === "undefined")return;
1475                                 new ComSayHelloRecvEvent({
1476                                         "type": 'greeting',
1477                                         "targetNode": self.yukkuri,
1478                                         "action": self.targetYukkuri.action,
1479                                         "myYukkuri": self.targetYukkuri
1480                                 });
1481                         };
1482                 }
1483         });
1484         var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1485                 initialize: function (_data){
1486                         this.data = _data;
1487                         this.yukkuri = _data.myYukkuri;
1488                         this.targetYukkuri = _data.targetNode;
1489                         this.action = _data.action;
1490                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1491                         this.yukkuri.addAddress(this.targetYukkuri);
1492                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1493
1494                         var sec = BASE_FPS * 2;
1495                         this.yukkuri.wait(sec, {
1496                                 "onactiontick": this.onactiontick(this),
1497                                 "onactionend": this.onactionend(this)
1498                         });
1499                 },
1500                 onactiontick:function(self){
1501                         return function(e){
1502                                 if(typeof e === "undefined")return;
1503                         };
1504                 },
1505                 onactionend:function(self){
1506                         return function(e){
1507                                 if(typeof e === "undefined")return;
1508                                 self.action.setStatus(EAction.THINK);
1509
1510                                 self.yukkuri.action.setStatus(EAction.THINK);
1511                                 self.yukkuri.animation();
1512                                 self.targetYukkuri.action.setStatus(EAction.THINK);
1513                                 self.targetYukkuri.animation();
1514                         };
1515                 }
1516         });
1517         var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1518                 initialize: function (_data){
1519                         this.data = _data;
1520                         this.yukkuri = this.data.myYukkuri;
1521                         this.action = this.data.action;
1522
1523                         var yukkuri = this.yukkuri;
1524                         var node = this.data.targetNode;
1525
1526                         this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1527                         yukkuri.vx = node.x + node.width /2  - yukkuri.getX();
1528                         yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1529                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1530                         var frame = distance + distance/5 + 1;
1531                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1532
1533                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1534                         yukkuri.reverse();
1535
1536                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1537                                 "onactionend": this.onactionend(this)
1538                         });
1539                 },
1540                 onactionend:function(self){
1541                         return function(e){
1542                                 if(typeof e === "undefined")return;
1543                                 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1544                                 self.data = null;
1545                                 self.yukkuri = null;
1546                                 self.action = null;
1547                         };
1548                 }
1549         });
1550         var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1551                 initialize: function (_data){
1552                         this.data = _data;
1553                         this.yukkuri = _data.myYukkuri;
1554                         this.place = _data.targetNode;
1555                         this.action = _data.action;
1556                         this.action.setStatus(EAction.WAIT);
1557
1558
1559                         var sec = BASE_FPS * 3;
1560                         this.yukkuri.declarePlace(this.place);
1561                         this.place.setOwner(this.yukkuri);
1562                         mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1563
1564                         this.yukkuri.setFaceImage(EFace.NORMAL);
1565                         this.yukkuri.wait(sec, {
1566                                 "onactionend": this.onactionend(this)
1567                         });
1568                 },
1569                 onactionend:function(self){
1570                         return function(e){
1571                                 if(typeof e === "undefined")return;
1572                                 self.action.setStatus(EAction.THINK);
1573                         };
1574                 }
1575         });
1576
1577         var Food = enchant.Class.create(ObjSprite,{
1578                 initialize: function (type, x, y){
1579                         this.classname = "Food";
1580                         //一つにつきgiveの値分、hunguryを減少させられる
1581                         if(type == "apple"){
1582                                 ObjSprite.call(this,16,16);
1583                                 this.image = game.assets[EResPath.OBJECT];
1584                                 this.frame = 15;
1585                                 this.give = 40;
1586                                 this.amount = 3;
1587                         }else if(type == "grass"){
1588                                 ObjSprite.call(this,64,64);
1589                                 this.image = game.assets[EResPath.GRASS];
1590                                 this.frame = 0;
1591                                 this.give = 10;
1592                                 this.amount = 20;
1593                         }
1594                         this.x = x;
1595                         this.y = y;
1596                         foodGroup.addChild(this);
1597                         this.addEventListener('enterframe', function(){
1598                                 if(this.amount <= 0){
1599                                         this.removeAll();
1600                                 }
1601                         });
1602                 },
1603                 getAmount: function(){
1604                         return this.amount;
1605                 },
1606                 getGive: function(){
1607                         return this.give;
1608                 }
1609         });
1610         var Place = enchant.Class.create(ObjSprite,{
1611                 initialize: function (type, x, y){
1612                         ObjSprite.call(this,128,128);
1613                         this.image = game.assets[EResPath.PLACE_TREE];
1614                         this.x = x - this.width / 2;
1615                         this.y = y - this.height / 2;
1616                         backgroundMap.addChild(this);
1617                         this.owner = null;
1618                         this.foods = [];
1619                         for(var key in EFood){
1620                                 var efood = EFood[key];
1621                                 this.foods[efood] = 0;
1622                         }
1623                         // this.addEventListener('enterframe', function(){
1624                         //      if(this.age%10 === 0 && this.age !== 0){
1625                         //              console.log("x/y " + this.x + "/" + this.y);
1626                         //      }
1627                         //      if(game.input.left){
1628                         //              this.x -= 10;;
1629                         //      }
1630                         //      if(game.input.right){
1631                         //              this.x += 10;;
1632                         //      }
1633                         //      if(game.input.up){
1634                         //              this.y -= 10;;
1635                         //      }
1636                         //      if(game.input.down){
1637                         //              this.y += 10;;
1638                         //      }
1639                         // });
1640                 },
1641                 getStatusForDisplay: function(){
1642                         var ret = "";
1643                         var ownerId = "なし";
1644                         if(this.owner == null)ownerId = "なし";
1645                         else ownerId = this.owner.id;
1646                         ret += "プレイスID " + this.id + "\n";
1647                         ret += "オーナーID " + ownerId + "\n";
1648                         ret += "食料うめぇ  " + this.foods[EFood.GREAT] + "\n";
1649                         ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1650                         ret += "食料にがにが  " + this.foods[EFood.BAD] + "\n";
1651                         return ret;
1652                 },
1653                 setItems:function(items){
1654                         var len = items.length;
1655                         for(var i=0; i<len; i++){
1656                                 var item = items[i];
1657                                 if(item instanceof Food){
1658                                         this.foods[EFood.NORMAL]++;
1659                                 }
1660                         }
1661                         items.length = 0;
1662                 },
1663                 isFood:function(){
1664                         var ret = 0;
1665                         for(var key in EFood){
1666                                 var efood = EFood[key];
1667                                 ret += this.foods[efood];
1668                         }
1669                         return ret !== 0;
1670                 },
1671                 getFoodHash:function(){
1672                         if(this.foods[EFood.GREAT] !== 0){
1673                                 this.foods[EFood.GREAT]--;
1674                                 return {give:20,yukkuri:15,unun:20};
1675                         }
1676                         else if(this.foods[EFood.NORMAL] !== 0){
1677                                 this.foods[EFood.NORMAL]--;
1678                                 return {give:10,yukkuri:5,unun:10};
1679                         }
1680                         else if(this.foods[EFood.BAD] !== 0){
1681                                 this.foods[EFood.BAD]--;
1682                                 return {give:10,yukkuri:-2,unun:10};
1683                         }
1684                         return false;
1685                 },
1686                 setOwner: function(yukkuri){
1687                         this.owner = yukkuri;
1688                 },
1689                 isOwner: function(){
1690                         return this.owner !== null;
1691                 }
1692         });
1693         var Unun = enchant.Class.create(ObjSprite,{
1694                 initialize: function (x, y){
1695                         this.classname = "Unun";
1696                         ObjSprite.call(this,32,32);
1697                         this.image = game.assets[EResPath.YUKKURI_UNUN];
1698                         this.x = x;
1699                         this.y = y;
1700                         backgroundMap.addChild(this);
1701                         this.lifetime = 30 * 24 * 3;
1702                         this.addEventListener('enterframe', this.runEnterframe(this));
1703                         // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1704
1705                 },
1706                 runEnterframe:function(self){
1707                         return function(e){
1708                                 if(typeof e === "undefined")return;
1709                                 if(this.age%BASE_FPS === 0 && this.age !== 0){
1710                                         self.lifetime--;
1711                                         if(self.lifetime <= 0){
1712                                                 this.parentNode.removeChild(this);
1713                                                 ctl.backgroundMap.removeChild(this);
1714                                                 ctl.removeObj(this);
1715                                                 self.image = null;
1716                                         }
1717                                 }
1718
1719                         };
1720                 }
1721                 // runEnterframe: function(){
1722                 //      console.log("enterframe:" + this.id);
1723                 // }
1724         });
1725         var Okazari = enchant.Class.create(enchant.Sprite,{
1726                 initialize: function(yukkuri){
1727                         this.classname = "Okazari";
1728                         if(yukkuri.myCode === "REIMU"){
1729                                 enchant.Sprite.call(this, 80, 32);
1730                                 this.image = game.assets[EResPathReimu.OKAZARI];
1731                                 this.x = -CHARA_WIDTH / 2 - 1;
1732                                 this.y = 0;
1733                         }else{
1734                                 enchant.Sprite.call(this, 64, 64);
1735                                 this.image = game.assets[EResPath.MARISA_OKAZARI];
1736                                 this.x = -CHARA_WIDTH / 2;
1737                                 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1738                         }
1739                         this.yukkuri = yukkuri;
1740                 },
1741                 getWidth: function(){
1742                         return this.width;
1743                         // return this.width * this.yukkuri.myScaleX;
1744                 },
1745                 getHeight: function(){
1746                         return this.height;
1747                         // return this.height * this.yukkuri.myScaleY;
1748                 }
1749         });
1750         var Address = enchant.Class.create({
1751                 initialize: function(yukkuri){
1752                         this.friendlyLv = 1;
1753                         this.yukkuri = yukkuri;
1754                         this.isGreeting = false;
1755                         this.greetingWaitFrame = 0;
1756                         this.comMatrix = {
1757                                 "beginSayHello" : false,
1758                                 "sayHello" : false,
1759                         };
1760                         this.evtHash = {};
1761                 },
1762                 set:function(key, value){
1763                         this.comMatrix[key] = value;
1764                 },
1765                 get:function(key){
1766                         return this.comMatrix[key];
1767                 }
1768         });
1769
1770         var Yukkuri = enchant.Class.create(ObjSprite,{
1771                 initialize: function(x, y, grow){
1772                         ObjSprite.call(this, 64, 64);
1773                         this.searchObjectMang = new SearchObjectMang();
1774                         this.grow = grow;
1775                         //base plyaer only
1776                         this.cmdQueue = [];
1777                         this.myCode = "YUKKURI";
1778                         this.myName = "ゆっくり";
1779                         this.beforeHuntingFood = null;
1780                         if(grow == EGrow.ADULT){
1781                                 this.myScaleX = 1;
1782                                 this.myScaleY = 1;
1783                                 this.mySize = "L";
1784                         }
1785                         else if(grow == EGrow.SUBADULT){
1786                                 this.myScaleX = 0.8;
1787                                 this.myScaleY = 0.8;
1788                                 this.mySize = "M";
1789                         }
1790                         else if(grow == EGrow.CHILD){
1791                                 this.myScaleX = 0.6;
1792                                 this.myScaleY = 0.6;
1793                                 this.mySize = "S";
1794                         }
1795                         else if(grow == EGrow.BABY){
1796                                 this.myScaleX = 0.3;
1797                                 this.myScaleY = 0.3;
1798                                 this.mySize = "SS";
1799                         }
1800
1801                         // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1802                         this.classname = "Yukkuri";
1803                         this.addressBook = {};
1804                         this.imgGroup = new SpriteGroup();
1805                         this.imgBody = new SpriteGroup();
1806                         this.imgGroup.id = guid();
1807                         this.imgBody.id = guid();
1808                         this.x = -CHARA_WIDTH / 2;
1809                         this.y = -CHARA_HEIGHT / 2;
1810                         this.vx = 0;
1811                         this.vy = 0;
1812                         this.image = game.assets[EResPath.YUKKURI_BASE];
1813                         this.direction = EDirection.RIGHT;
1814                         this.addEventListener('enterframe', this.runEnterframe);
1815                         this.bodyStatus ={};
1816                         this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1817                         this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1818                         this.walkAnimationStatus = EWalkAnimation.END;
1819                         this.place = null;
1820                         this.items = [];
1821                         this.actionQueue = [];
1822                         this.exLvHash = {};
1823                         this.exValueHash = {};
1824                         this.memoryHash = {};
1825                         for(var _v in EExSkill){
1826                                 var key = EExSkill[_v];
1827                                 this.exLvHash[key] = 0;
1828                                 this.exValueHash[key] = 0;
1829                         }
1830
1831                 },
1832                 runEnterframe:function(){
1833                         // try{
1834                                 this.act();
1835                                 if(this.isDead())return;
1836                                 this.runYukkuri();
1837                                 this.runHungry();
1838                                 this.runUnun();
1839                                 this.runSleep();
1840                                 this.runAddress();
1841                         // }catch(e){
1842                         //      console.log(e);
1843                         // }
1844                 },
1845                 reverse:function(){
1846                         if(this.direction == EDirection.RIGHT){
1847                                 this.imgBody.scaleX = 1;
1848                         }
1849                         else if(this.direction == EDirection.LEFT){
1850                                 this.imgBody.scaleX = -1;
1851                         }
1852                 },
1853                 tweet:function(text){
1854                         text = text.replace(/%name%/g, this.myName);
1855                         this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1856                 },
1857                 moveTo:function(x, y, time){
1858                         this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1859                 },
1860                 moveBy:function(x, y, time, eventFunctions){
1861                         var self = this;
1862                         var params = {
1863                                 x: function() {
1864                                         return self.imgGroup.x + x;
1865                                 },
1866                                 y: function() {
1867                                         return self.imgGroup.y + y;
1868                                 },
1869                                 time: time,
1870                                 easing: enchant.Easing.SIN_EASEINOUT
1871                         };
1872                         //-Event register [onactionstart,onactiontick,onactionend]
1873                         if(eventFunctions !== undefined){
1874                                 for(var key in eventFunctions){
1875                                         params[key] = eventFunctions[key];
1876                                 }
1877                         }
1878                         return this.imgGroup.tl.tween(params);
1879                 },
1880                 wait:function(frame, eventFunctions){
1881                         this.moveBy(0,1,frame,eventFunctions);
1882                 },
1883                 act: function(){
1884                         this.action.act();
1885                 },
1886                 animation: function(){
1887
1888                         var frame = 10;
1889                         frame -= plusFrameScale(frame, this.getMyScale()) / 2;
1890                         var move = 5;
1891                         move -= plusFrameScale(move, this.getMyScale());
1892                         if(this.walkAnimationStatus == EWalkAnimation.END){
1893                                 this.imgBody.y = 0;
1894                                 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1895                                         "onactionstart": function(e){
1896                                                 this.walkAnimationStatus = EWalkAnimation.START;
1897                                         }
1898                                 })
1899                                 .moveByEx(0, move, frame, enchant.Easing.SWING,
1900                                 {
1901                                         "onactionend": function(e){
1902                                                 this.walkAnimationStatus = EWalkAnimation.END;
1903                                         }
1904                                 }).loop();
1905
1906                         }else{
1907                                 this.imgBody.tl.loop();
1908                         }
1909                 },
1910                 getMyScale: function(){
1911                         return (this.myScaleX + this.myScaleY) / 2;
1912                 },
1913                 getWidth: function(){
1914                         return this.width * this.myScaleX;
1915                 },
1916                 getHeight: function(){
1917                         return this.height * this.myScaleY;
1918                 },
1919                 getX: function(){
1920                         return this.imgGroup.x;
1921                 },
1922                 getY: function(){
1923                         return this.imgGroup.y;
1924                 },
1925                 moveX: function(x){
1926                         this.imgGroup.x += x;
1927                         // this.x += x;
1928                         // this.shadow.x += x;
1929                         // this._tweet.x += x;
1930                 },
1931                 moveY: function(y){
1932                         this.imgGroup.y += y;
1933                         // this.y += y;
1934                         // this.shadow.y += y;
1935                         // this._tweet.y += y;
1936                 },
1937                 // changeFace: function(erespath){
1938                 //      this.face.image = game.assets[erespath];
1939                 // },
1940                 loadParamsXML: function(url){
1941                         var http = new JKL.ParseXML( url );
1942                         return http.parse();
1943                 },
1944                 runYukkuri: function(){
1945                         if(this.param.hungry > 70){
1946                                 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1947                                         this.param.yukkuri -= 1;
1948                                 }
1949                         }
1950                         else if(this.param.hungry < 10){
1951                                 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1952                         }
1953
1954                         if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1955                         else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1956                 },
1957                 runHungry: function(){
1958                         if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1959                         if(this.param.hungry >= 100)this.param.hungry = 100;
1960                 },
1961                 runUnun: function(){
1962                         if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1963                         if(this.param.unun >= 100)this.param.unun = 100;
1964                 },
1965                 runSleep: function(){
1966                         if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1967                                 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1968                                 if(this.param.sleep >= 100){
1969                                         this.param.sleep = 100;
1970                                 }
1971                         }
1972                 },
1973                 runAddress: function(){
1974                         for(var key in this.addressBook){
1975                                 var address = this.addressBook[key];
1976                                 //挨拶時間。24時間に1度だけ。
1977                                 if(address.isGreeting){
1978                                         address.greetingWaitFrame++;
1979                                         if(address.greetingWaitFrame >= DAY){
1980                                                 address.greetingWaitFrame = 0;
1981                                                 address.isGreeting = false;
1982                                         }
1983                                 }
1984                         }
1985                 },
1986                 changeFace: function(){
1987                         if(this.param.yukkuri >= 80){
1988                                 this.setFaceImage(EFace.HAPPY1);
1989                         }
1990                         else if(this.param.yukkuri >= 50){
1991                                 this.setFaceImage(EFace.NORMAL);
1992                         }
1993                         else if(this.param.yukkuri >= 30){
1994                                 this.setFaceImage(EFace.TIRED);
1995                         }
1996                         else if(this.param.yukkuri >= 10){
1997                                 this.setFaceImage(EFace.CRY1);
1998                         }
1999                         else if(this.param.yukkuri >= 1){
2000                                 this.setFaceImage(EFace.CRY2);
2001                         }
2002                 },
2003                 getRange: function(){
2004                         return this.param.range;
2005                 },
2006                 isSleep: function(){
2007                         return this.param.sleep >= 100;
2008                 },
2009                 isDead: function(){
2010                         return this.param.yukkuri <= 0;
2011                 },
2012                 isManpuku: function(){
2013                         return this.param.hungry <= 20;
2014                 },
2015                 isKuhuku: function(){
2016                         return this.param.hungry >= 40;
2017                 },
2018                 isVeryKuhuku: function(){
2019                         return this.param.hungry >= 80;
2020                 },
2021                 getYukkuri: function(){
2022                         return this.param.yukkuri;
2023                 },
2024                 setYukkuri: function(yukkuri){
2025                         this.param.yukkuri = yukkuri;
2026                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2027                 },
2028                 getHungry: function(){
2029                         return this.param.hungry;
2030                 },
2031                 setHungry: function(hungry){
2032                         this.param.hungry = hungry;
2033                         if(this.param.hungry < 0)this.param.hungry = 0;
2034                 },
2035                 getUnun: function(){
2036                         return this.param.unun;
2037                 },
2038                 setUnun: function(unun){
2039                         this.param.unun = unun;
2040                         if(this.param.unun < 0)this.param.unun = 0;
2041                 },
2042
2043                 eat:function(food){
2044                         if(food instanceof Food){
2045                                 //Food object case
2046                                 if(food.amount > 0){
2047                                         food.amount--;
2048                                         this.setHungry(this.param.hungry - food.getGive());
2049                                         this.setUnun(this.getUnun() + food.getGive() / 4);
2050                                         this.setYukkuri(this.getYukkuri() + 5);
2051                                         return true;
2052                                 }else{
2053                                         this.setYukkuri(this.getYukkuri() - 5);
2054                                         return false;
2055                                 }
2056                         }else{
2057                                 //hash case
2058                                 if(food != null){
2059                                         this.setHungry(this.param.hungry - food.give);
2060                                         this.setUnun(this.getUnun() + food.unun);
2061                                         this.setYukkuri(this.getYukkuri() + food.yukkuri);
2062                                         return true;
2063                                 }else{
2064                                         return false;
2065                                 }
2066                         }
2067                 },
2068                 hunt:function(food){
2069                         if(food.amount > 0){
2070                                 if(!this.isItemsMax()){
2071                                         food.amount--;
2072                                         this.items.push(food);
2073                                         this.setYukkuri(this.getYukkuri() + 1);
2074                                         return true;
2075                                 }
2076                         }
2077                         return false;
2078                 },
2079                 declarePlace: function(place){
2080                         this.place = place;
2081                 },
2082                 getPlace:function(){
2083                         return this.place;
2084                 },
2085                 isPlace: function(){
2086                         return this.place !== null;
2087                 },
2088
2089                 unun:function(){
2090                         if(this.direction == EDirection.RIGHT){
2091                                 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2092                         }else{
2093                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2094                         }
2095                         this.setUnun(0);
2096                 },
2097                 setBodyImage: function(ebody){
2098                         var path = this.bodyStatus[ebody];
2099                         this.image = game.assets[path];
2100                 },
2101                 tlPause:function(){
2102                         // this.imgBody.tl.pause();
2103                         // this.imgGroup.tl.pause();
2104                         this.imgBody.tl.clear();
2105                         this.imgGroup.tl.clear();
2106                         this.imgBody.tl.unloop();
2107                         this.imgGroup.tl.unloop();
2108                         this.imgBody.y = 0;
2109
2110                 },
2111                 tlResume: function(){
2112                         // this.imgBody.tl.resume();
2113                         // this.imgGroup.tl.resume();
2114                         this.animation();
2115                 },
2116                 syncDirection:function(senderYukkuri){
2117                         if(this.getX() > senderYukkuri.getX()){
2118                                 this.direction = EDirection.LEFT;
2119                                 senderYukkuri.direction = EDirection.RIGHT;
2120                         }else{
2121                                 this.direction = EDirection.RIGHT;
2122                                 senderYukkuri.direction = EDirection.LEFT;
2123                         }
2124                 },
2125                 isCommunication: function(yukkuri){
2126                         if(this.addressBook[yukkuri.id] === undefined) return true;
2127                         if(this.addressBook[yukkuri.id].isGreeting) return false;
2128                         return true;
2129                 },
2130                 addAddress: function(yukkuri){
2131                         this.addressBook[yukkuri.id] = new Address(yukkuri);
2132                 },
2133                 getAddress: function(yukkuri){
2134                         if(this.addressBook[yukkuri.id] === undefined)return null;
2135                         return this.addressBook[yukkuri.id];
2136                 },
2137                 getStatusForDisplay: function (){
2138                         var ret = "";
2139                         var placeId = (this.place==null)?"無し" : this.place.id;
2140                         ret += "ID " + this.id + "\n";
2141                         ret += "プレイス  " + placeId + "\n";
2142                         ret += "ゆっくり  " + this.getYukkuri() + "\n";
2143                         ret += "空腹  " + this.getHungry() + "\n";
2144                         ret += "うんうん  " + this.getUnun() + "\n";
2145                         ret += "もちもの  " + this.items.length + "\n";
2146                         ret += "debug  " + this.action.status + "\n";
2147                         return ret;
2148                 },
2149                 isItemsMax:function(){
2150                         return this.items.length >= this.param.items_max;
2151                 },
2152                 getItems:function(){
2153                         return this.items;
2154                 },
2155                 addSearchObject:function(esearch, node){
2156                         this.searchObjectMang.add(esearch, node)
2157                 },
2158                 clearSearchObject:function(){
2159                         this.searchObjectMang.clear()
2160                 },
2161                 setFaceImage: function(eface){
2162                         var path = this.faceStatus[eface];
2163                         this.face.image = game.assets[path];
2164                 },
2165                 myScale: function(_scaleX, _scaleY){
2166                         this.face.scale(_scaleX,_scaleY);
2167                         if(this.myCode === "REIMU"){
2168                                 this.okazari.x = -this.okazari.width / 2;
2169                                 this.okazari.y = -CHARA_HEIGHT  / 2 + (this.okazari.height * (1 - _scaleY)) / 2;
2170                         }else{
2171                                 this.okazari.x = -CHARA_WIDTH /2;
2172                                 this.okazari.y = -CHARA_HEIGHT / 2 - (CHARA_HEIGHT * _scaleY)/6;
2173                         }
2174                         if(this.sub1 != null){
2175                                 this.sub1.scale(_scaleX,_scaleY);
2176                         }
2177
2178                         this.okazari.scale(_scaleX,_scaleY);
2179                         this.hear.scale(_scaleX,_scaleY);
2180                         this.scale(_scaleX,_scaleY);
2181                         this.shadow.scale(_scaleX, _scaleY);
2182                 },
2183                 send: function(targetYukkuri, object, callback){
2184                         targetYukkuri.recv(object, callback);
2185                 },
2186                 recv: function(object, callback){
2187                         this.actionQueue.push({
2188                                 object : object,
2189                                 actionStatus : EAction.COMMUNICATE_RECV,
2190                                 callback: callback
2191                         });
2192                 },
2193                 addExValue: function(eexskill, plus){
2194                         this.exValueHash[eexskill] += plus;
2195                         if(this.exValueHash[eexskill] >= 100){
2196                                 this.exLvHash[eexskill] = 1;
2197                         }
2198                 },
2199                 getExValue: function(eexskill){
2200                         return this.exValueHash[eexskill];
2201                 },
2202                 getExSkill: function(eexskill){
2203                         return this.exLvHash[eexskill];
2204                 },
2205
2206                 setMemory: function(ememory, value){
2207                         this.memoryHash[ememory] = value;
2208                 },
2209                 getMemory: function(ememory){
2210                         return this.memoryHash[ememory];
2211                 },
2212                 destruct: function(){
2213
2214                 }
2215         });
2216         var Marisa = enchant.Class.create(Yukkuri,{
2217                 initialize: function(x, y, grow){
2218                         Yukkuri.call(this,x,y, grow);
2219                         this.classname = "Marisa";
2220                         this.myCode = "MARISA";
2221                         this.myName = "まりさ";
2222
2223                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2224                         // var json = net.load("./data/marisa/params.json");
2225                         // this.param = json.root.param;
2226                         this.param = new MarisaParam();
2227                         if(this.grow == EGrow.BABY){
2228                                 this.myName = "まりちゃ";
2229                                 this.param.range /= 4;
2230                         }
2231                         else if(this.grow == EGrow.CHILD){
2232                                 this.param.range /= 3;
2233                         }
2234                         else if(this.grow == EGrow.SUBADULT){
2235                                 this.param.range *= 0.8;
2236                         }else{
2237                         }
2238                         this.shadow = new enchant.Sprite(64, 64);
2239                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2240                         this.shadow.x = 0 + this.x;
2241                         this.shadow.y = this.getWidth() / 16 + this.x;
2242
2243                         this._style.zIndex = 5;
2244
2245                         this.face = new enchant.Sprite(64, 64);
2246                         this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2247                         this.face.x = -CHARA_WIDTH / 2;
2248                         this.face.y = -CHARA_HEIGHT / 2;
2249
2250                         this.faceStatus ={};
2251                         this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2252                         this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2253                         this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2254                         this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2255                         this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2256                         this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2257                         this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2258                         this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2259                         this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2260                         this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2261
2262
2263                         this.hear = new enchant.Sprite(64, 64);
2264                         this.hear.image = game.assets[EResPath.MARISA_HEAR];
2265                         this.hear.x = -CHARA_WIDTH / 2;
2266                         this.hear.y = -CHARA_HEIGHT / 2;
2267
2268                         this.okazari = new Okazari(this);
2269
2270
2271
2272                         this.imgGroup.addChild(this.shadow);
2273                         this.imgBody.addChild(this);
2274                         this.imgBody.addChild(this.face);
2275                         this.imgBody.addChild(this.hear);
2276                         this.imgBody.addChild(this.okazari);
2277                         this.myScale(this.myScaleX, this.myScaleY)
2278                         if(this instanceof Player){
2279                                 // this.myScaleX = 0.5;
2280                                 // this.myScaleY = 0.5;
2281
2282                                 this.budge = new enchant.Sprite(16, 16);
2283                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2284                                 this.imgBody.addChild(this.budge);
2285                                 this.budge.x -= this.getWidth()/2;
2286                                 this.budge.y -= this.getHeight()/2;
2287                                 this.budge.scale(this.myScaleX, this.myScaleX);
2288                         }
2289                         this.imgGroup.width = this.getWidth();
2290                         this.imgGroup.height = this.getHeight();
2291                         this.imgGroup.addChild(this.imgBody);
2292                         backgroundMap.addChild(this.imgGroup);
2293                         this._tweet = new TTweet(148, 64);
2294
2295                         this.imgGroup.addChild(this._tweet);
2296                         this.imgGroup.x = x;
2297                         this.imgGroup.y = y;
2298
2299                         this.animation();
2300                         this.action = new Action(this);
2301                         ctl.addObj(this);
2302                 }
2303         });
2304         var Player = enchant.Class.create(Marisa,{
2305                 initialize: function(x, y){
2306                         // this.runEnterframe = function(){
2307                         // },
2308                         Marisa.call(this, x, y, EGrow.ADULT);
2309                         this.classname = "Player";
2310                         ctl.setPlayer(this);
2311                         // this.removeEventListener('enterframe',this.runEnterframe);
2312                         this.addEventListener('enterframe', function(){
2313
2314
2315                                 if(this.age%10 === 0 && this.age !== 0){
2316                                         // console.log("palyer:" + this.age);
2317                                 }
2318                                 // this.act();
2319                                 ///////////////////////////////////////////////
2320                                 //Action pattern  debug
2321                                 if(game.input.left){
2322                                         // this.changeFace(EResPath.MARISA_FACE_TIRED);
2323                                         this.moveX(-10);
2324                                         this.direction = EDirection.LEFT;
2325                                 }
2326                                 if(game.input.right){
2327                                         this.moveX(10);
2328                                         this.direction = EDirection.RIGHT;
2329                                 }
2330                                 if(game.input.up){
2331                                         this.moveY(-10);
2332                                 }
2333                                 if(game.input.down){
2334                                         this.moveY(10);
2335                                 }
2336
2337                                 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2338                                 ///////////////////////////////////////////////
2339                                 // this.reverse();
2340                                 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2341                                 //      console.log("hit:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.height/2) );
2342                                 // }else{
2343                                 //      console.log("not:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.image.height/2));
2344                                 // }
2345                                 //- Display the circle of search range.
2346                                 // fieldBg.image.clear();
2347                                 // fieldBg.image.context.beginPath();
2348                                 // fieldBg.image.context.fillStyle = '#ff0000';
2349                                 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2350                                 // fieldBg.image.context.fill();
2351                         });
2352                 }
2353         });
2354         var Reimu = enchant.Class.create(Yukkuri,{
2355                 initialize: function(x, y, grow){
2356                         Yukkuri.call(this,x,y, grow);
2357                         this.classname = "Reimu";
2358                         this.myCode = "REIMU";
2359                         this.myName = "れいむ";
2360
2361                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2362                         // var json = net.load("./data/reimu/params.json");
2363                         // this.param = json.root.param;
2364                         this.param = new ReimuParam();
2365                         if(this.grow == EGrow.BABY){
2366                                 this.myName = "れいみゅ";
2367                                 this.param.range /= 4;
2368                         }
2369                         else if(this.grow == EGrow.CHILD){
2370                                 this.param.range /= 3;
2371                         }
2372                         else if(this.grow == EGrow.SUBADULT){
2373                                 this.param.range *= 0.8;
2374                         }
2375                         this.shadow = new enchant.Sprite(64, 64);
2376                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2377                         this.shadow.x = 0 + this.x;
2378                         this.shadow.y = this.getWidth() / 16 + this.x;
2379                         this.shadow.image._element.style.zIndex = 2;
2380
2381                         this._style.zIndex = 5;
2382
2383                         this.face = new enchant.Sprite(64, 64);
2384                         this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2385                         this.face.x = -CHARA_WIDTH / 2;
2386                         this.face.y = -CHARA_HEIGHT / 2;
2387                         this.face._style.zIndex = 0;
2388
2389                         this.faceStatus ={};
2390                         this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2391                         this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2392                         this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2393                         this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2394                         this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2395                         this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2396                         this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2397                         this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2398                         this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2399                         this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2400
2401
2402                         this.hear = new enchant.Sprite(64, 64);
2403                         this.hear.image = game.assets[EResPathReimu.HEAR];
2404                         this.hear.x = -CHARA_WIDTH / 2;
2405                         this.hear.y = -CHARA_HEIGHT / 2;
2406
2407                         this.sub1 = new enchant.Sprite(64, 64);
2408                         this.sub1.image = game.assets[EResPathReimu.SUB1];
2409                         this.sub1.x = -CHARA_WIDTH / 2;
2410                         this.sub1.y = -CHARA_HEIGHT / 2;
2411
2412                         this.okazari = new Okazari(this);
2413
2414                         // this.imgGroup._style.zIndex = 1;
2415
2416
2417                         this.imgGroup.addChild(this.shadow);
2418                         this.imgBody.addChild(this.okazari);
2419                         this.imgBody.addChild(this);
2420                         this.imgBody.addChild(this.face);
2421                         this.imgBody.addChild(this.hear);
2422                         this.imgBody.addChild(this.sub1);
2423                         this.myScale(this.myScaleX, this.myScaleY)
2424                         if(this instanceof Player){
2425                                 // this.myScaleX = 0.5;
2426                                 // this.myScaleY = 0.5;
2427
2428                                 this.budge = new enchant.Sprite(16, 16);
2429                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2430                                 this.imgBody.addChild(this.budge);
2431                                 this.budge.x -= this.getWidth()/2;
2432                                 this.budge.y -= this.getHeight()/2;
2433                                 this.budge.scale(this.myScaleX, this.myScaleX);
2434                         }
2435                         this.imgGroup.width = this.getWidth();
2436                         this.imgGroup.height = this.getHeight();
2437                         this.imgGroup.addChild(this.imgBody);
2438                         backgroundMap.addChild(this.imgGroup);
2439                         this._tweet = new TTweet(148, 64);
2440
2441                         this.imgGroup.addChild(this._tweet);
2442                         this.imgGroup.x = x;
2443                         this.imgGroup.y = y;
2444
2445                         this.animation();
2446                         this.action = new Action(this);
2447                         ctl.addObj(this);
2448                         this.exLvHash[EExSkill.KEKKAI] = 1;
2449                         this.exValueHash[EExSkill.KEKKAI] = 100;
2450                 }
2451         });
2452
2453         game.onload = function(){
2454                 def.Food = Food;
2455                 def.Unun = Unun;
2456                 def.Place = Place;
2457                 def.ObjSprite = ObjSprite;
2458                 def.Yukkuri = Yukkuri;
2459                 def.nodeSort = nodeSort;
2460                 mangTouch = new MangTouch(ctl);
2461                 mangMsg = new MangMsg(ctl);
2462                 ctl.setDefined(def);
2463                 backgroundMap.image = game.assets[EResPath.MAP0];
2464                 backgroundMap.loadData(_mapData);
2465                 backgroundMap.collisionData = _collisionData;
2466
2467                 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2468                 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2469                 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2470                 fieldBg.image = fieldSurface;
2471                 fieldBg.x = 0;
2472                 fieldBg.y = 0;
2473
2474                 windowFront.image = windowSurface;
2475                 windowFront.x = 0;
2476                 windowFront.y = 0;
2477                 windowFront.opacity = 0.5;
2478
2479                 windowSurface.context.fillStyle = '#000';
2480                 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2481
2482
2483                 menuSurface.context.fillStyle = '#000';
2484                 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2485                 menuBg.image = menuSurface;
2486                 menuBg.x = EMenuPos.X;
2487                 menuBg.y = EMenuPos.Y;
2488                 backgroundMap.addChild(fieldBg);
2489                 mangIcon = new MangIcon(ctl, menuBg);
2490
2491                 game.rootScene.addChild(backgroundMap);
2492                 game.rootScene.addChild(windowFront);
2493                 game.rootScene.addChild(menuBg);
2494
2495                 // var labelGroup = new LabelGroup();
2496                 mangLabel = new MangLabel(ctl, menuBg);
2497                 // var info = new Label("ゆっくり");
2498                 // info.color = "#ffffff";
2499                 // info.font = "14px 'Times New Roman'";
2500                 // info.x = 4;
2501                 // info.y = GAME_HEIGHT / 2;
2502                 // labelGroup.addChild(info);
2503                 // menuBg.addChild(labelGroup);
2504
2505
2506                 // var food = new def.Food("apple", 200, 250);
2507                 backgroundMap.addChild(foodGroup);
2508                 // backgroundMap.addChild(placeGroup);
2509                 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2510                 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2511                 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2512                 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2513                 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
2514                 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2515                 new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
2516                 new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);
2517                 new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
2518                 // new Unun(100, 100);
2519                 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2520                 var touchX = 0;
2521
2522
2523                 game.rootScene.addEventListener('touchstart', function (e) {
2524                         game.touched = true;
2525                         var mang = mangTouch.get(ctl.getCurrentCommand());
2526                         mang.touchstart(e);
2527                 });
2528                 game.rootScene.addEventListener('touchmove', function (e) {
2529                         var mang = mangTouch.get(ctl.getCurrentCommand());
2530                         mang.touchmove(e);
2531                 });
2532                 game.rootScene.addEventListener('touchend', function (e) {
2533                         var mang = mangTouch.get(ctl.getCurrentCommand());
2534                         mang.touchend(e);
2535                         game.touched = false;
2536                 });
2537
2538
2539                 game.rootScene.addEventListener('enterframe', function(){
2540                         //main frame
2541                         mangLabel.draw(player);
2542                         if(this.age%BASE_FPS == 0 ){
2543                                 ctl.calcTime();
2544                         }
2545                         ctl.time += TIME_SPEED;
2546                 });
2547                 this.addEventListener('enterframe', function(){
2548                         //The priority processing of display instead of z-index
2549
2550                         backgroundMap.childNodes.sort(nodeSort);
2551                 });
2552
2553         };
2554         game.start();
2555 };