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
732                 },
733                 search: function(){
734                         this.yukkuri.clearSearchObject();
735                         var nodes = ctl.getObjs();
736                         l = nodes.length;
737                         var ununFlg = false;
738
739                         for (var key in nodes) {
740                                 var node = nodes[key];
741                                 if(this.yukkuri.id === node.id)continue;
742                                 //うんうん臭いを検索
743                                 if (
744                                         node instanceof Unun
745                                         && !(this.targetNode instanceof Unun)
746                                         && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
747
748                                         this.yukkuri.addSearchObject(ESearch.UNUN, node);
749                                 }
750                                 //食べ物を検索
751                                 else if (node instanceof Food && node.amount > 0) {
752                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
753                                                 this.yukkuri.addSearchObject(ESearch.FOOD, node);
754                                         }
755                                 }
756                                 //ゆっくりを検索
757                                 else if(node instanceof Yukkuri){
758                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
759                                                 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
760                                         }
761                                 }
762                                 //ゆっくりプレイスを検索
763                                 else if(node instanceof Place){
764                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
765                                                 this.yukkuri.addSearchObject(ESearch.PLACE, node);
766                                         }
767                                 }
768                         }
769                         this.status =  EAction.WALK;
770                 }
771         });
772 /**
773  * Range範囲内のObjSprを管理する
774  * 注意!:ゆっくりプレイスを持って入るもののみ使用される
775  * @param  {[type]} )
776  * @return {[type]}
777  */
778         var SearchObjectMang = enchant.Class.create({
779                 initialize: function (){
780                         this.init();
781                 },
782                 init:function(){
783                         this.datas = [];
784                         for(var key in ESearch){
785                                 var esearch = ESearch[key];
786                                 this.datas[esearch] = [];
787                         }
788                 },
789                 add :function(esearch, node){
790                         this.datas[esearch].push(node);
791                 },
792                 clear :function(){
793                         for(var key in ESearch){
794                                 var esearch = ESearch[key];
795                                 this.datas[esearch].length = 0;
796                         }
797                         // this.datas.length = 0;
798                         // this.init();
799                 },
800                 get:function (esearch){
801                         return this.datas[esearch];
802                 },
803                 getNear:function (esearch, yukkuri){
804                         var objects = this.datas[esearch];
805                         var nearDistance = null;
806                         var ret = null;
807                         for(var i=0;i<objects.length;i++){
808                                 var object = objects[i];
809                                 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
810                                 if(nearDistance === null || nearDistance > nowDistance){
811                                         nearDistance = nowDistance;
812                                         ret = object;
813                                 }
814                         }
815                         return ret;
816                 },
817                 callEvent: function(yukkuri){
818                         if(yukkuri.isItemsMax() && yukkuri.isPlace()){
819                                 yukkuri.action.targetNode = yukkuri.getPlace();
820                                 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
821                                 return;
822                         }
823                         if(yukkuri.isVeryKuhuku()){
824                                 //エサを探す
825                                 var foods = this.get(ESearch.FOOD);
826                                 if(foods.length > 0){
827                                         var foods = this.get(ESearch.FOOD);
828                                         food = this.getNear(ESearch.FOOD, yukkuri);
829                                         if(food !== null){
830                                                 yukkuri.action.targetNode = food;
831                                                 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
832                                                 return;
833                                         }
834                                 }
835                                 if(yukkuri.getMemory(EMemory.FOOD_IN_PLACE) === 0 && yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
836                                         yukkuri.action.setStatus(EAction.WALK);
837                                         return;
838                                 }
839
840                                 if(foods.length === 0 && yukkuri.isPlace()){
841                                         //家があるなら家に帰宅
842                                         yukkuri.action.targetNode = yukkuri.getPlace();
843                                         yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
844                                         return;
845                                 }else{
846                                 }
847                         }
848
849                         if(yukkuri.isSleep()){
850                                 yukkuri.action.setStatus(EAction.SLEEP_START);
851                                 return;
852                         }
853
854                         else if(yukkuri.getUnun() >= 80){
855                                 yukkuri.action.setStatus(EAction.UNUN_START);
856                                 return;
857                         }
858
859
860                         if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
861                                 food = this.getNear(ESearch.FOOD, yukkuri);
862                                 if(food !== null){
863                                         yukkuri.action.targetNode = food;
864                                         yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
865                                         return;
866                                 }
867                         }
868                         ununs = this.get(ESearch.UNUN);
869                         if(ununs.length !== 0){
870                                 yukkuri.action.targetNode = yukkuri.getPlace();
871                                 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
872                                 return;
873                         }
874                         var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
875                         if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
876                                 yukkuri.action.targetNode = searchYukkuri;
877                                 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
878                                 return;
879                         }
880                         if(!yukkuri.isPlace()){
881                                 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
882                                 if(searchYukkuri != null && !searchYukkuri.isOwner()){
883                                         yukkuri.action.targetNode = searchYukkuri;
884                                         yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
885                                         return;
886                                 }
887                         }
888                         yukkuri.action.setStatus(EAction.WALK);
889
890                 }
891
892         });
893         var Event = enchant.Class.create({
894                 initialize: function (_data){
895                         this.guid = guid();
896                 },
897                 onactionstart:function(self){
898                         return this._onactionstart;
899                 },
900                 _onactionstart:function(e){
901                         if(typeof e === "undefined")return;
902                 },
903                 onactiontick:function(self){
904                         return function(e){
905                                 if(typeof e === "undefined")return;
906                         };
907                 },
908                 onactionend:function(self){
909                         return function(e){
910                                 if(typeof e === "undefined")return;
911                         };
912                 }
913         });
914         var WalkEvent = enchant.Class.create(Event,{
915                 initialize: function (_data){
916                         this.data = _data;
917                         this.yukkuri = _data.myYukkuri;
918                         this.action = _data.action;
919
920                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
921                         this.action.setStatus(EAction.SLEEP_WAIT);
922                         this.yukkuri.setFaceImage(EFace.SLEEP);
923                         this.yukkuri.tlPause();
924                         var self = this;
925                         this.yukkuri.addEventListener('enterframe', function() {
926                                 var yukkuri = self.yukkuri;
927                                 self.run();
928                         });
929                 },
930                 run : function(){
931
932                 }
933         });
934         var SleepEvent = enchant.Class.create(Event,{
935                 initialize: function (_data){
936                         this.data = _data;
937                         this.yukkuri = _data.myYukkuri;
938                         this.action = _data.action;
939
940                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
941                         this.action.setStatus(EAction.SLEEP_WAIT);
942                         this.yukkuri.setFaceImage(EFace.SLEEP);
943                         this.yukkuri.tlPause();
944                         var sec = FPS * 3;
945                         var self = this;
946                         this.yukkuri.addEventListener('enterframe', function() {
947                                 var yukkuri = self.yukkuri;
948                                 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
949                                 if(yukkuri.param.sleep <= 0){
950                                         yukkuri.param.sleep = 0;
951                                         this.removeEventListener("enterframe",arguments.callee);
952                                         mangMsg.output(self.yukkuri, EMsg.GET_UP);
953                                         yukkuri.setFaceImage(EFace.NORMAL);
954                                         yukkuri.tlResume();
955                                         // self.action.setStatus(EAction.WAIT);
956                                         if(self.data.nextStatus !== undefined){
957                                                 self.action.setStatus(self.data.nextStatus);
958                                         }else{
959                                                 self.action.setStatus(EAction.THINK);
960                                         }
961                                 }
962                         });
963                 }
964         });
965
966         var UnunEvent = enchant.Class.create(Event,{
967                 initialize: function (_data){
968                         this.data = _data;
969                         this.yukkuri = _data.myYukkuri;
970                         this.action = _data.action;
971                         this.action.setStatus(EAction.UNUN_WAIT);
972                         mangMsg.output(this.yukkuri, EMsg.UNUN);
973                         this.yukkuri.setFaceImage(EFace.HAPPY2);
974                         var sec = FPS * 3;
975
976                         this.yukkuri.wait(sec, {
977                                 "onactionend": this.onactionend(this)
978                         });
979                 },
980                 onactionend:function(self){
981                         return function(e){
982                                 if(typeof e === "undefined")return;
983                                 self.yukkuri.unun();
984                                 self.action.setStatus(EAction.WAIT);
985                                 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
986                                 new WaitEvent({
987                                         "waitframe": FPS * 1.5,
988                                         "action": self.action,
989                                         "myYukkuri": self.yukkuri
990                                 });
991                         };
992                 }
993         });
994         var WaitEvent = enchant.Class.create(Event,{
995                 initialize: function (_data){
996                         this.data = _data;
997                         this.yukkuri = _data.myYukkuri;
998                         this.action = _data.action;
999                         this.waitframe = _data.waitframe;
1000                         this.yukkuri.wait(this.waitframe, {
1001                                 "onactionstart": this.onactionstart(this),
1002                                 "onactiontick": this.onactiontick(this),
1003                                 "onactionend": this.onactionend(this)
1004                         });
1005                 },
1006                 onactionend:function(self){
1007                         return function(e){
1008                                 if(typeof e === "undefined")return;
1009                                 self.action.setStatus(EAction.THINK);
1010                         };
1011                 }
1012         });
1013         var UnunSmellEvent = enchant.Class.create(Event,{
1014                 initialize: function (_data){
1015                         this.data = _data;
1016                         this.yukkuri = _data.myYukkuri;
1017                         this.action = _data.action;
1018                         this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1019                         mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1020                         this.yukkuri.setFaceImage(EFace.CRY1);
1021                         var sec = FPS * 3;
1022                         this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1023                         this.yukkuri.wait(sec, {
1024                                 "onactionend": this.onactionend(this)
1025                         });
1026                 },
1027                 onactionend:function(self){
1028                         return function(e){
1029                                 if(typeof e === "undefined")return;
1030                                 self.action.setStatus(EAction.WALK);
1031                         };
1032                 }
1033         });
1034
1035         var EatEvent = enchant.Class.create(Event,{
1036                 initialize: function (_data){
1037                         this.data = _data;
1038                         this.yukkuri = _data.myYukkuri;
1039                         this.food = _data.targetNode;
1040                         this.action = _data.action;
1041                         this.action.setStatus(EAction.EAT_WAIT);
1042
1043
1044                         var sec = BASE_FPS * 3;
1045                         if(this.yukkuri.eat(this.food)){
1046                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1047                                 this.yukkuri.setFaceImage(EFace.EAT2);
1048                         }else{
1049                                 sec = BASE_FPS * 6;
1050                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1051                                 this.yukkuri.setFaceImage(EFace.CRY2);
1052                         }
1053                         this.yukkuri.wait(sec, {
1054                                 "onactionend": this.onactionend(this)
1055                         });
1056                 },
1057                 onactionend:function(self){
1058                         return function(e){
1059                                 if(typeof e === "undefined")return;
1060                                 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1061                                         self.action.setStatus(EAction.THINK);
1062                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1063                                 }else{
1064                                         self.action.setStatus(EAction.EAT_START);
1065                                 }
1066                         };
1067                 }
1068         });
1069         /**
1070          * Move Event
1071          * -When yukkuri find Food.
1072          * @param  _data
1073          * type: "food"
1074          * targetNode: enchant.Node
1075          * action:Action
1076          * myYukkuri:Yukkuri
1077          */
1078         var MoveToEatEvent = enchant.Class.create(Event,{
1079                 initialize: function (_data){
1080                         this.data = _data;
1081                         this.yukkuri = this.data.myYukkuri;
1082                         this.action = this.data.action;
1083
1084                         var yukkuri = this.yukkuri;
1085                         var node = this.data.targetNode;
1086                         //food distance
1087                         if(this.data.type == "food"){
1088                                 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1089                                 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1090                                 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1091                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1092                                 var frame = distance + distance/5 + 1;
1093                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1094                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1095                                 yukkuri.reverse();
1096
1097                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1098                                         "onactionstart": this.onactionstart(this),
1099                                         "onactiontick": this.onactiontick(this),
1100                                         "onactionend": this.onactionend(this)
1101                                 });
1102                         }
1103                 },
1104                 onactionstart:function(self){
1105                         return function(e){
1106                                 if(typeof e === "undefined")return;
1107                                 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1108                         };
1109                 },
1110                 onactiontick:function(self){
1111                         return function(e){
1112                                 if(typeof e === "undefined")return;
1113                         };
1114                 },
1115                 onactionend:function(self){
1116                         return function(e){
1117                                 if(typeof e === "undefined")return;
1118                                 self.action.setStatus(EAction.EAT_START);
1119                         };
1120                 }
1121         });
1122         var MoveToHuntEvent = enchant.Class.create(Event,{
1123                 initialize: function (_data){
1124                         this.data = _data;
1125                         this.yukkuri = this.data.myYukkuri;
1126                         this.action = this.data.action;
1127
1128                         var yukkuri = this.yukkuri;
1129                         var node = this.data.targetNode;
1130                         var nodeX = node.x;
1131                         var nodeY = node.y;
1132                         var nodeWidth = node.width;
1133                         var nodeHeight = node.height;
1134                         node = null;
1135
1136                         //food distance
1137                         if(this.data.type == "food"){
1138                                 this.action.setStatus(EAction.WAIT);
1139                                 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1140                                 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1141                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1142                                 var frame = distance + distance/5 + 1;
1143                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1144                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1145                                 yukkuri.reverse();
1146                                 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1147
1148                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1149                                         "onactionend": this.onactionend(this)
1150                                 });
1151                         }
1152                 },
1153                 onactionend:function(self){
1154                         return function(e){
1155                                 if(typeof e === "undefined")return;
1156                                 self.action.setStatus(EAction.HUNT_START);
1157                         };
1158                 }
1159         });
1160         var HuntStartEvent = enchant.Class.create(Event,{
1161                 initialize: function (_data){
1162                         Event.call(this, _data);
1163                         this.initCnt = 0;
1164                         this.data = _data;
1165                         this.yukkuri = _data.myYukkuri;
1166                         this.food = _data.targetNode;
1167                         this.action = _data.action;
1168                         this.action.setStatus(EAction.WAIT);
1169                         this.huntingStatus = "hunting";
1170                         this.tick = 0;
1171                         this.yukkuri.beforeHuntingFood = this.food;
1172                         var sec = BASE_FPS * 8;
1173                         if(this.yukkuri.hunt(this.food)){
1174                                 this.huntingStatus = "hunting";
1175                                 mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1176                                 this.yukkuri.setFaceImage(EFace.HAPPY1);
1177                         }else{
1178                                 if(this.yukkuri.isItemsMax()){
1179                                         sec = 1;
1180                                         this.huntingStatus = "return";
1181                                         // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1182                                         this.yukkuri.setFaceImage(EFace.NORMAL);
1183                                 }else{
1184                                         sec = BASE_FPS * 3;
1185                                         this.huntingStatus = "cry";
1186                                         mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1187                                         this.yukkuri.setFaceImage(EFace.CRY2);
1188                                 }
1189                         }
1190
1191                         this.yukkuri.wait(sec, {
1192                                 "onactiontick": this.onactiontick(this),
1193                                 "onactionend": this.onactionend(this)
1194                         });
1195                 },
1196                 onactiontick:function(self){
1197                         return function(e){
1198                                 if(typeof e === "undefined")return;
1199                                 self.tick++;
1200                                 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1201                                         if(this.age%(BASE_FPS * 3) == 0){
1202                                                 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1203                                                 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1204                                         }
1205                                 }
1206                         };
1207                 },
1208                 onactionend:function(self){
1209                         return function(e){
1210                                 if(typeof e === "undefined")return;
1211                                 if(self.huntingStatus == "hunting"){
1212                                         if(self.yukkuri.isItemsMax()){
1213                                                 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1214                                                 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1215                                         }else{
1216                                                 self.action.setStatus(EAction.HUNT_START);
1217                                         }
1218                                 }
1219                                 else if(self.huntingStatus == "return"){
1220                                         self.action.setStatus(EAction.MOVE_GOTO_HOME);
1221                                 }
1222                                 else if(self.huntingStatus === "cry"){
1223                                         // self.action.setStatus(EAction.THINK);
1224                                         self.action.setStatus(EAction.WALK);
1225                                 }
1226                                 self.release();
1227                         };
1228                 },
1229                 release:function(){
1230                         this.action = null;
1231                         this.yukkuri = null;
1232                         this.food = null;
1233                         this.data = null;
1234                 }
1235         });
1236         var MoveGotoHomeEvent = enchant.Class.create(Event,{
1237                 initialize: function (_data){
1238                         this.data = _data;
1239                         this.yukkuri = this.data.myYukkuri;
1240                         this.action = this.data.action;
1241
1242                         var yukkuri = this.yukkuri;
1243                         var place = this.data.targetNode;
1244                         //food distance
1245                         if(this.data.type == "hunt_end"){
1246                                 this.action.setStatus(EAction.WAIT);
1247                                 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1248                                 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1249                                 // console.log("place.x:" + place.x);
1250                                 // console.log("place.y:" + place.y);
1251                                 // console.log("yukkuri.getX():" + yukkuri.getX());
1252                                 // console.log("yukkuri.getY():" + yukkuri.getY());
1253                                 // console.log("yukkuri.vx:" + yukkuri.vx);
1254                                 // console.log("yukkuri.vy:" + yukkuri.vy);
1255                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1256                                 var frame = distance + distance/2 + 1 ;
1257                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1258                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1259                                 yukkuri.reverse();
1260                                 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1261
1262                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1263                                         "onactiontick": this.onactiontick(this),
1264                                         "onactionend": this.onactionend(this)
1265                                 });
1266                         }
1267                 },
1268                 onactiontick:function(self){
1269                         return function(e){
1270                                 if(typeof e === "undefined")return;
1271                                 if(this.age%(BASE_FPS * 5) == 0){
1272                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1273                                 }
1274                         };
1275                 },
1276                 onactionend:function(self){
1277                         return function(e){
1278                                 if(typeof e === "undefined")return;
1279                                 self.action.setStatus(EAction.IN_HOME);
1280                                 self.release();
1281                         };
1282                 },
1283                 release:function(){
1284                         this.action = null;
1285                         this.yukkuri = null;
1286                         this.data = null;
1287                 }
1288         });
1289         var InHomeEvent = enchant.Class.create(Event,{
1290                 initialize: function (_data){
1291                         this.data = _data;
1292                         this.yukkuri = this.data.myYukkuri;
1293                         this.action = this.data.action;
1294
1295                         var yukkuri = this.yukkuri;
1296                         var place = this.data.targetNode;
1297
1298                         if(yukkuri.isVeryKuhuku()){
1299                                 if(place.isFood()){
1300                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1301                                         this.action.setStatus(EAction.EAT_IN_HOME);
1302                                         return;
1303                                 }else{
1304                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1305                                         //experience skill
1306                                         if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1307                                                 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1308                                                 this.action.setStatus(EAction.THINK);
1309                                                 return;
1310                                         }else{
1311                                                 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1312                                                 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1313                                         }
1314
1315                                 }
1316                         }
1317                         this.action.setStatus(EAction.WAIT);
1318                         var items = this.yukkuri.getItems();
1319                         if(items.length > 0){
1320                                 place.setItems(items);
1321                         }else{
1322
1323                         }
1324                         var sec = BASE_FPS * 10;
1325                         if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1326                         this.yukkuri.wait(sec, {
1327                                 "onactiontick": this.onactiontick(this),
1328                                 "onactionend": this.onactionend(this)
1329                         });
1330                 },
1331                 onactiontick:function(self){
1332                         return function(e){
1333                                 if(typeof e === "undefined")return;
1334                                 if(this.age%(BASE_FPS * 5) == 0){
1335                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1336                                 }
1337                         };
1338                 },
1339                 onactionend:function(self){
1340                         return function(e){
1341                                 if(typeof e === "undefined")return;
1342                                 self.action.setStatus(EAction.THINK_IN_HOME);
1343                         };
1344                 }
1345         });
1346         var EatInHomeEvent = enchant.Class.create(Event,{
1347                 initialize: function (_data){
1348                         this.data = _data;
1349                         this.yukkuri = _data.myYukkuri;
1350                         this.place = _data.targetNode;
1351                         this.action = _data.action;
1352                         this.action.setStatus(EAction.EAT_WAIT);
1353
1354                         var sec = BASE_FPS * 3;
1355                         var foodHash = this.place.getFoodHash();
1356                         if(foodHash !== false && this.yukkuri.eat(foodHash)){
1357                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1358                                 this.yukkuri.setFaceImage(EFace.EAT2);
1359                         }else{
1360                                 sec = BASE_FPS * 6;
1361                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1362                                 this.yukkuri.setFaceImage(EFace.CRY2);
1363                         }
1364
1365                         this.yukkuri.wait(sec, {
1366                                 "onactionend": this.onactionend(this)
1367                         });
1368                 },
1369                 onactionend:function(self){
1370                         return function(e){
1371                                 if(typeof e === "undefined")return;
1372                                 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1373                                         self.action.setStatus(EAction.EAT_IN_HOME);
1374
1375                                         // new EatInHomeEvent({
1376                                         //      "targetNode": self.place,
1377                                         //      "action": self.action,
1378                                         //      "myYukkuri": self.yukkuri
1379                                         // });
1380                                 }else{
1381                                         self.action.setStatus(EAction.THINK_IN_HOME);
1382                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1383                                 }
1384                         };
1385                 }
1386         });
1387
1388
1389         var MoveCommandEvent = enchant.Class.create(Event,{
1390                 initialize: function (_data){
1391                         this.data = _data;
1392                         this.yukkuri = this.data.myYukkuri;
1393                         this.action = this.data.action;
1394                         this.vx = this.data.vx;
1395                         this.vy = this.data.vy;
1396
1397                         var yukkuri = this.yukkuri;
1398                         this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1399                         yukkuri.vx = node.x - yukkuri.getX();
1400                         yukkuri.vy = node.y - yukkuri.getY();
1401                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1402                         var frame = distance + 1;
1403                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1404
1405                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1406                                 "onactionstart": this.onactionstart(this),
1407                                 "onactiontick": this.onactiontick(this),
1408                                 "onactionend": this.onactionend(this)
1409                         });
1410                 },
1411                 onactionstart:function(self){
1412                         return function(e){
1413                                 if(typeof e === "undefined")return;
1414                         };
1415                 },
1416                 onactiontick:function(self){
1417                         return function(e){
1418                                 if(typeof e === "undefined")return;
1419                         };
1420                 },
1421                 onactionend:function(self){
1422                         return function(e){
1423                                 if(typeof e === "undefined")return;
1424                                 self.action.setStatus(EAction.THINK);
1425                         };
1426                 }
1427         });
1428         /**
1429          * Say hello contact to send communication .
1430          */
1431         var ComSayHelloSendEvent = enchant.Class.create(Event,{
1432                 initialize: function (_data){
1433                         this.data = _data;
1434                         this.yukkuri = _data.myYukkuri;
1435                         this.targetYukkuri = _data.targetNode;
1436                         this.action = _data.action;
1437                         this.action.setStatus(EAction.COMMUNICATE_WAIT);
1438                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1439
1440
1441                         this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1442                         this.targetYukkuri.tlPause();
1443                         this.yukkuri.tlPause();
1444                         this.yukkuri.syncDirection(this.targetYukkuri);
1445
1446                         this.yukkuri.addAddress(this.targetYukkuri);
1447                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1448
1449                         var sec = BASE_FPS * 2;
1450                         this.yukkuri.wait(sec, {
1451                                 "onactiontick": this.onactiontick(this),
1452                                 "onactionend": this.onactionend(this)
1453                         });
1454                 },
1455                 onactiontick:function(self){
1456                         return function(e){
1457                                 if(typeof e === "undefined")return;
1458                         };
1459                 },
1460                 onactionend:function(self){
1461                         return function(e){
1462                                 if(typeof e === "undefined")return;
1463                                 new ComSayHelloRecvEvent({
1464                                         "type": 'greeting',
1465                                         "targetNode": self.yukkuri,
1466                                         "action": self.targetYukkuri.action,
1467                                         "myYukkuri": self.targetYukkuri
1468                                 });
1469                         };
1470                 }
1471         });
1472         var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1473                 initialize: function (_data){
1474                         this.data = _data;
1475                         this.yukkuri = _data.myYukkuri;
1476                         this.targetYukkuri = _data.targetNode;
1477                         this.action = _data.action;
1478                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1479                         this.yukkuri.addAddress(this.targetYukkuri);
1480                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1481
1482                         var sec = BASE_FPS * 2;
1483                         this.yukkuri.wait(sec, {
1484                                 "onactiontick": this.onactiontick(this),
1485                                 "onactionend": this.onactionend(this)
1486                         });
1487                 },
1488                 onactiontick:function(self){
1489                         return function(e){
1490                                 if(typeof e === "undefined")return;
1491                         };
1492                 },
1493                 onactionend:function(self){
1494                         return function(e){
1495                                 if(typeof e === "undefined")return;
1496                                 self.action.setStatus(EAction.THINK);
1497
1498                                 self.yukkuri.action.setStatus(EAction.THINK);
1499                                 self.yukkuri.animation();
1500                                 self.targetYukkuri.action.setStatus(EAction.THINK);
1501                                 self.targetYukkuri.animation();
1502                         };
1503                 }
1504         });
1505         var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1506                 initialize: function (_data){
1507                         this.data = _data;
1508                         this.yukkuri = this.data.myYukkuri;
1509                         this.action = this.data.action;
1510
1511                         var yukkuri = this.yukkuri;
1512                         var node = this.data.targetNode;
1513
1514                         this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1515                         yukkuri.vx = node.x + node.width /2  - yukkuri.getX();
1516                         yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1517                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1518                         var frame = distance + distance/5 + 1;
1519                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1520
1521                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1522                         yukkuri.reverse();
1523
1524                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1525                                 "onactionend": this.onactionend(this)
1526                         });
1527                 },
1528                 onactionend:function(self){
1529                         return function(e){
1530                                 if(typeof e === "undefined")return;
1531                                 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1532                                 self.data = null;
1533                                 self.yukkuri = null;
1534                                 self.action = null;
1535                         };
1536                 }
1537         });
1538         var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1539                 initialize: function (_data){
1540                         this.data = _data;
1541                         this.yukkuri = _data.myYukkuri;
1542                         this.place = _data.targetNode;
1543                         this.action = _data.action;
1544                         this.action.setStatus(EAction.WAIT);
1545
1546
1547                         var sec = BASE_FPS * 3;
1548                         this.yukkuri.declarePlace(this.place);
1549                         this.place.setOwner(this.yukkuri);
1550                         mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1551
1552                         this.yukkuri.setFaceImage(EFace.NORMAL);
1553                         this.yukkuri.wait(sec, {
1554                                 "onactionend": this.onactionend(this)
1555                         });
1556                 },
1557                 onactionend:function(self){
1558                         return function(e){
1559                                 if(typeof e === "undefined")return;
1560                                 self.action.setStatus(EAction.THINK);
1561                         };
1562                 }
1563         });
1564
1565         var Food = enchant.Class.create(ObjSprite,{
1566                 initialize: function (type, x, y){
1567                         this.classname = "Food";
1568                         //一つにつきgiveの値分、hunguryを減少させられる
1569                         if(type == "apple"){
1570                                 ObjSprite.call(this,16,16);
1571                                 this.image = game.assets[EResPath.OBJECT];
1572                                 this.frame = 15;
1573                                 this.give = 40;
1574                                 this.amount = 3;
1575                         }else if(type == "grass"){
1576                                 ObjSprite.call(this,64,64);
1577                                 this.image = game.assets[EResPath.GRASS];
1578                                 this.frame = 0;
1579                                 this.give = 10;
1580                                 this.amount = 20;
1581                         }
1582                         this.x = x;
1583                         this.y = y;
1584                         foodGroup.addChild(this);
1585                         this.addEventListener('enterframe', function(){
1586                                 if(this.amount <= 0){
1587                                         this.removeAll();
1588                                 }
1589                         });
1590                 },
1591                 getAmount: function(){
1592                         return this.amount;
1593                 },
1594                 getGive: function(){
1595                         return this.give;
1596                 }
1597         });
1598         var Place = enchant.Class.create(ObjSprite,{
1599                 initialize: function (type, x, y){
1600                         ObjSprite.call(this,128,128);
1601                         this.image = game.assets[EResPath.PLACE_TREE];
1602                         this.x = x - this.width / 2;
1603                         this.y = y - this.height / 2;
1604                         backgroundMap.addChild(this);
1605                         this.owner = null;
1606                         this.foods = [];
1607                         for(var key in EFood){
1608                                 var efood = EFood[key];
1609                                 this.foods[efood] = 0;
1610                         }
1611                         // this.addEventListener('enterframe', function(){
1612                         //      if(this.age%10 === 0 && this.age !== 0){
1613                         //              console.log("x/y " + this.x + "/" + this.y);
1614                         //      }
1615                         //      if(game.input.left){
1616                         //              this.x -= 10;;
1617                         //      }
1618                         //      if(game.input.right){
1619                         //              this.x += 10;;
1620                         //      }
1621                         //      if(game.input.up){
1622                         //              this.y -= 10;;
1623                         //      }
1624                         //      if(game.input.down){
1625                         //              this.y += 10;;
1626                         //      }
1627                         // });
1628                 },
1629                 getStatusForDisplay: function(){
1630                         var ret = "";
1631                         var ownerId = "なし";
1632                         if(this.owner == null)ownerId = "なし";
1633                         else ownerId = this.owner.id;
1634                         ret += "プレイスID " + this.id + "\n";
1635                         ret += "オーナーID " + ownerId + "\n";
1636                         ret += "食料うめぇ  " + this.foods[EFood.GREAT] + "\n";
1637                         ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1638                         ret += "食料にがにが  " + this.foods[EFood.BAD] + "\n";
1639                         return ret;
1640                 },
1641                 setItems:function(items){
1642                         var len = items.length;
1643                         for(var i=0; i<len; i++){
1644                                 var item = items[i];
1645                                 if(item instanceof Food){
1646                                         this.foods[EFood.NORMAL]++;
1647                                 }
1648                         }
1649                         items.length = 0;
1650                 },
1651                 isFood:function(){
1652                         var ret = 0;
1653                         for(var key in EFood){
1654                                 var efood = EFood[key];
1655                                 ret += this.foods[efood];
1656                         }
1657                         return ret !== 0;
1658                 },
1659                 getFoodHash:function(){
1660                         if(this.foods[EFood.GREAT] !== 0){
1661                                 this.foods[EFood.GREAT]--;
1662                                 return {give:20,yukkuri:15,unun:20};
1663                         }
1664                         else if(this.foods[EFood.NORMAL] !== 0){
1665                                 this.foods[EFood.NORMAL]--;
1666                                 return {give:10,yukkuri:5,unun:10};
1667                         }
1668                         else if(this.foods[EFood.BAD] !== 0){
1669                                 this.foods[EFood.BAD]--;
1670                                 return {give:10,yukkuri:-2,unun:10};
1671                         }
1672                         return false;
1673                 },
1674                 setOwner: function(yukkuri){
1675                         this.owner = yukkuri;
1676                 },
1677                 isOwner: function(){
1678                         return this.owner !== null;
1679                 }
1680         });
1681         var Unun = enchant.Class.create(ObjSprite,{
1682                 initialize: function (x, y){
1683                         this.classname = "Unun";
1684                         ObjSprite.call(this,32,32);
1685                         this.image = game.assets[EResPath.YUKKURI_UNUN];
1686                         this.x = x;
1687                         this.y = y;
1688                         backgroundMap.addChild(this);
1689                         this.lifetime = 30 * 24 * 3;
1690                         this.addEventListener('enterframe', this.runEnterframe(this));
1691                         // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1692
1693                 },
1694                 runEnterframe:function(self){
1695                         return function(e){
1696                                 if(typeof e === "undefined")return;
1697                                 if(this.age%BASE_FPS === 0 && this.age !== 0){
1698                                         self.lifetime--;
1699                                         if(self.lifetime <= 0){
1700                                                 this.parentNode.removeChild(this);
1701                                                 ctl.backgroundMap.removeChild(this);
1702                                                 ctl.removeObj(this);
1703                                                 self.image = null;
1704                                         }
1705                                 }
1706
1707                         };
1708                 }
1709                 // runEnterframe: function(){
1710                 //      console.log("enterframe:" + this.id);
1711                 // }
1712         });
1713         var Okazari = enchant.Class.create(enchant.Sprite,{
1714                 initialize: function(yukkuri){
1715                         this.classname = "Okazari";
1716                         if(yukkuri.myCode === "REIMU"){
1717                                 enchant.Sprite.call(this, 80, 32);
1718                                 this.image = game.assets[EResPathReimu.OKAZARI];
1719                                 this.x = -CHARA_WIDTH / 2 - 1;
1720                                 this.y = 0;
1721                         }else{
1722                                 enchant.Sprite.call(this, 64, 64);
1723                                 this.image = game.assets[EResPath.MARISA_OKAZARI];
1724                                 this.x = -CHARA_WIDTH / 2;
1725                                 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1726                         }
1727                         this.yukkuri = yukkuri;
1728                 },
1729                 getWidth: function(){
1730                         return this.width;
1731                         // return this.width * this.yukkuri.myScaleX;
1732                 },
1733                 getHeight: function(){
1734                         return this.height;
1735                         // return this.height * this.yukkuri.myScaleY;
1736                 }
1737         });
1738         var Address = enchant.Class.create({
1739                 initialize: function(yukkuri){
1740                         this.friendlyLv = 1;
1741                         this.yukkuri = yukkuri;
1742                         this.isGreeting = false;
1743                         this.greetingWaitFrame = 0;
1744                         this.comMatrix = {
1745                                 "beginSayHello" : false,
1746                                 "sayHello" : false,
1747                         };
1748                         this.evtHash = {};
1749                 },
1750                 set:function(key, value){
1751                         this.comMatrix[key] = value;
1752                 },
1753                 get:function(key){
1754                         return this.comMatrix[key];
1755                 }
1756         });
1757
1758         var Yukkuri = enchant.Class.create(ObjSprite,{
1759                 initialize: function(x, y, grow){
1760                         ObjSprite.call(this, 64, 64);
1761                         this.searchObjectMang = new SearchObjectMang();
1762                         this.grow = grow;
1763                         this.myCode = "YUKKURI";
1764                         this.myName = "ゆっくり";
1765                         this.beforeHuntingFood = null;
1766                         if(grow == EGrow.ADULT){
1767                                 this.myScaleX = 1;
1768                                 this.myScaleY = 1;
1769                                 this.mySize = "L";
1770                         }
1771                         else if(grow == EGrow.SUBADULT){
1772                                 this.myScaleX = 0.8;
1773                                 this.myScaleY = 0.8;
1774                                 this.mySize = "M";
1775                         }
1776                         else if(grow == EGrow.CHILD){
1777                                 this.myScaleX = 0.6;
1778                                 this.myScaleY = 0.6;
1779                                 this.mySize = "S";
1780                         }
1781                         else if(grow == EGrow.BABY){
1782                                 this.myScaleX = 0.3;
1783                                 this.myScaleY = 0.3;
1784                                 this.mySize = "SS";
1785                         }
1786
1787                         // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1788                         this.classname = "Yukkuri";
1789                         this.addressBook = {};
1790                         this.imgGroup = new SpriteGroup();
1791                         this.imgBody = new SpriteGroup();
1792                         this.imgGroup.id = guid();
1793                         this.imgBody.id = guid();
1794                         this.x = -CHARA_WIDTH / 2;
1795                         this.y = -CHARA_HEIGHT / 2;
1796                         this.vx = 0;
1797                         this.vy = 0;
1798                         this.image = game.assets[EResPath.YUKKURI_BASE];
1799                         this.direction = EDirection.RIGHT;
1800                         this.addEventListener('enterframe', this.runEnterframe);
1801                         this.bodyStatus ={};
1802                         this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1803                         this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1804                         this.walkAnimationStatus = EWalkAnimation.END;
1805                         this.place = null;
1806                         this.items = [];
1807                         this.actionQueue = [];
1808                         this.exLvHash = {};
1809                         this.exValueHash = {};
1810                         this.memoryHash = {};
1811                         for(var _v in EExSkill){
1812                                 var key = EExSkill[_v];
1813                                 this.exLvHash[key] = 0;
1814                                 this.exValueHash[key] = 0;
1815                         }
1816
1817                 },
1818                 runEnterframe:function(){
1819                         // try{
1820                                 this.act();
1821                                 if(this.isDead())return;
1822                                 this.runYukkuri();
1823                                 this.runHungry();
1824                                 this.runUnun();
1825                                 this.runSleep();
1826                                 this.runAddress();
1827                         // }catch(e){
1828                         //      console.log(e);
1829                         // }
1830                 },
1831                 reverse:function(){
1832                         if(this.direction == EDirection.RIGHT){
1833                                 this.imgBody.scaleX = 1;
1834                         }
1835                         else if(this.direction == EDirection.LEFT){
1836                                 this.imgBody.scaleX = -1;
1837                         }
1838                 },
1839                 tweet:function(text){
1840                         text = text.replace(/%name%/g, this.myName);
1841                         this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1842                 },
1843                 moveTo:function(x, y, time){
1844                         this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1845                 },
1846                 moveBy:function(x, y, time, eventFunctions){
1847                         var self = this;
1848                         var params = {
1849                                 x: function() {
1850                                         return self.imgGroup.x + x;
1851                                 },
1852                                 y: function() {
1853                                         return self.imgGroup.y + y;
1854                                 },
1855                                 time: time,
1856                                 easing: enchant.Easing.SIN_EASEINOUT
1857                         };
1858                         //-Event register [onactionstart,onactiontick,onactionend]
1859                         if(eventFunctions !== undefined){
1860                                 for(var key in eventFunctions){
1861                                         params[key] = eventFunctions[key];
1862                                 }
1863                         }
1864                         return this.imgGroup.tl.tween(params);
1865                 },
1866                 wait:function(frame, eventFunctions){
1867                         this.moveBy(0,1,frame,eventFunctions);
1868                 },
1869                 act: function(){
1870                         this.action.act();
1871                 },
1872                 animation: function(){
1873
1874                         var frame = 10;
1875                         frame -= plusFrameScale(frame, this.getMyScale()) / 2;
1876                         var move = 5;
1877                         move -= plusFrameScale(move, this.getMyScale());
1878                         if(this.walkAnimationStatus == EWalkAnimation.END){
1879                                 this.imgBody.y = 0;
1880                                 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1881                                         "onactionstart": function(e){
1882                                                 this.walkAnimationStatus = EWalkAnimation.START;
1883                                         }
1884                                 })
1885                                 .moveByEx(0, move, frame, enchant.Easing.SWING,
1886                                 {
1887                                         "onactionend": function(e){
1888                                                 this.walkAnimationStatus = EWalkAnimation.END;
1889                                         }
1890                                 }).loop();
1891
1892                         }else{
1893                                 this.imgBody.tl.loop();
1894                         }
1895                 },
1896                 getMyScale: function(){
1897                         return (this.myScaleX + this.myScaleY) / 2;
1898                 },
1899                 getWidth: function(){
1900                         return this.width * this.myScaleX;
1901                 },
1902                 getHeight: function(){
1903                         return this.height * this.myScaleY;
1904                 },
1905                 getX: function(){
1906                         return this.imgGroup.x;
1907                 },
1908                 getY: function(){
1909                         return this.imgGroup.y;
1910                 },
1911                 moveX: function(x){
1912                         this.imgGroup.x += x;
1913                         // this.x += x;
1914                         // this.shadow.x += x;
1915                         // this._tweet.x += x;
1916                 },
1917                 moveY: function(y){
1918                         this.imgGroup.y += y;
1919                         // this.y += y;
1920                         // this.shadow.y += y;
1921                         // this._tweet.y += y;
1922                 },
1923                 // changeFace: function(erespath){
1924                 //      this.face.image = game.assets[erespath];
1925                 // },
1926                 loadParamsXML: function(url){
1927                         var http = new JKL.ParseXML( url );
1928                         return http.parse();
1929                 },
1930                 runYukkuri: function(){
1931                         if(this.param.hungry > 70){
1932                                 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1933                                         this.param.yukkuri -= 1;
1934                                 }
1935                         }
1936                         else if(this.param.hungry < 10){
1937                                 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1938                         }
1939
1940                         if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1941                         else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1942                 },
1943                 runHungry: function(){
1944                         if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1945                         if(this.param.hungry >= 100)this.param.hungry = 100;
1946                 },
1947                 runUnun: function(){
1948                         if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1949                         if(this.param.unun >= 100)this.param.unun = 100;
1950                 },
1951                 runSleep: function(){
1952                         if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1953                                 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1954                                 if(this.param.sleep >= 100){
1955                                         this.param.sleep = 100;
1956                                 }
1957                         }
1958                 },
1959                 runAddress: function(){
1960                         for(var key in this.addressBook){
1961                                 var address = this.addressBook[key];
1962                                 //挨拶時間。24時間に1度だけ。
1963                                 if(address.isGreeting){
1964                                         address.greetingWaitFrame++;
1965                                         if(address.greetingWaitFrame >= DAY){
1966                                                 address.greetingWaitFrame = 0;
1967                                                 address.isGreeting = false;
1968                                         }
1969                                 }
1970                         }
1971                 },
1972                 changeFace: function(){
1973                         if(this.param.yukkuri >= 80){
1974                                 this.setFaceImage(EFace.HAPPY1);
1975                         }
1976                         else if(this.param.yukkuri >= 50){
1977                                 this.setFaceImage(EFace.NORMAL);
1978                         }
1979                         else if(this.param.yukkuri >= 30){
1980                                 this.setFaceImage(EFace.TIRED);
1981                         }
1982                         else if(this.param.yukkuri >= 10){
1983                                 this.setFaceImage(EFace.CRY1);
1984                         }
1985                         else if(this.param.yukkuri >= 1){
1986                                 this.setFaceImage(EFace.CRY2);
1987                         }
1988                 },
1989                 getRange: function(){
1990                         return this.param.range;
1991                 },
1992                 isSleep: function(){
1993                         return this.param.sleep >= 100;
1994                 },
1995                 isDead: function(){
1996                         return this.param.yukkuri <= 0;
1997                 },
1998                 isManpuku: function(){
1999                         return this.param.hungry <= 20;
2000                 },
2001                 isKuhuku: function(){
2002                         return this.param.hungry >= 40;
2003                 },
2004                 isVeryKuhuku: function(){
2005                         return this.param.hungry >= 80;
2006                 },
2007                 getYukkuri: function(){
2008                         return this.param.yukkuri;
2009                 },
2010                 setYukkuri: function(yukkuri){
2011                         this.param.yukkuri = yukkuri;
2012                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2013                 },
2014                 getHungry: function(){
2015                         return this.param.hungry;
2016                 },
2017                 setHungry: function(hungry){
2018                         this.param.hungry = hungry;
2019                         if(this.param.hungry < 0)this.param.hungry = 0;
2020                 },
2021                 getUnun: function(){
2022                         return this.param.unun;
2023                 },
2024                 setUnun: function(unun){
2025                         this.param.unun = unun;
2026                         if(this.param.unun < 0)this.param.unun = 0;
2027                 },
2028
2029                 eat:function(food){
2030                         if(food instanceof Food){
2031                                 //Food object case
2032                                 if(food.amount > 0){
2033                                         food.amount--;
2034                                         this.setHungry(this.param.hungry - food.getGive());
2035                                         this.setUnun(this.getUnun() + food.getGive() / 4);
2036                                         this.setYukkuri(this.getYukkuri() + 5);
2037                                         return true;
2038                                 }else{
2039                                         this.setYukkuri(this.getYukkuri() - 5);
2040                                         return false;
2041                                 }
2042                         }else{
2043                                 //hash case
2044                                 if(food != null){
2045                                         this.setHungry(this.param.hungry - food.give);
2046                                         this.setUnun(this.getUnun() + food.unun);
2047                                         this.setYukkuri(this.getYukkuri() + food.yukkuri);
2048                                         return true;
2049                                 }else{
2050                                         return false;
2051                                 }
2052                         }
2053                 },
2054                 hunt:function(food){
2055                         if(food.amount > 0){
2056                                 if(!this.isItemsMax()){
2057                                         food.amount--;
2058                                         this.items.push(food);
2059                                         this.setYukkuri(this.getYukkuri() + 1);
2060                                         return true;
2061                                 }
2062                         }
2063                         return false;
2064                 },
2065                 declarePlace: function(place){
2066                         this.place = place;
2067                 },
2068                 getPlace:function(){
2069                         return this.place;
2070                 },
2071                 isPlace: function(){
2072                         return this.place !== null;
2073                 },
2074
2075                 unun:function(){
2076                         if(this.direction == EDirection.RIGHT){
2077                                 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2078                         }else{
2079                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2080                         }
2081                         this.setUnun(0);
2082                 },
2083                 setBodyImage: function(ebody){
2084                         var path = this.bodyStatus[ebody];
2085                         this.image = game.assets[path];
2086                 },
2087                 tlPause:function(){
2088                         // this.imgBody.tl.pause();
2089                         // this.imgGroup.tl.pause();
2090                         this.imgBody.tl.clear();
2091                         this.imgGroup.tl.clear();
2092                         this.imgBody.tl.unloop();
2093                         this.imgGroup.tl.unloop();
2094                         this.imgBody.y = 0;
2095
2096                 },
2097                 tlResume: function(){
2098                         // this.imgBody.tl.resume();
2099                         // this.imgGroup.tl.resume();
2100                         this.animation();
2101                 },
2102                 syncDirection:function(senderYukkuri){
2103                         if(this.getX() > senderYukkuri.getX()){
2104                                 this.direction = EDirection.LEFT;
2105                                 senderYukkuri.direction = EDirection.RIGHT;
2106                         }else{
2107                                 this.direction = EDirection.RIGHT;
2108                                 senderYukkuri.direction = EDirection.LEFT;
2109                         }
2110                 },
2111                 isCommunication: function(yukkuri){
2112                         if(this.addressBook[yukkuri.id] === undefined) return true;
2113                         if(this.addressBook[yukkuri.id].isGreeting) return false;
2114                         return true;
2115                 },
2116                 addAddress: function(yukkuri){
2117                         this.addressBook[yukkuri.id] = new Address(yukkuri);
2118                 },
2119                 getAddress: function(yukkuri){
2120                         if(this.addressBook[yukkuri.id] === undefined)return null;
2121                         return this.addressBook[yukkuri.id];
2122                 },
2123                 getStatusForDisplay: function (){
2124                         var ret = "";
2125                         var placeId = (this.place==null)?"無し" : this.place.id;
2126                         ret += "ID " + this.id + "\n";
2127                         ret += "プレイス  " + placeId + "\n";
2128                         ret += "ゆっくり  " + this.getYukkuri() + "\n";
2129                         ret += "空腹  " + this.getHungry() + "\n";
2130                         ret += "うんうん  " + this.getUnun() + "\n";
2131                         ret += "もちもの  " + this.items.length + "\n";
2132                         ret += "debug  " + this.action.status + "\n";
2133                         return ret;
2134                 },
2135                 isItemsMax:function(){
2136                         return this.items.length >= this.param.items_max;
2137                 },
2138                 getItems:function(){
2139                         return this.items;
2140                 },
2141                 addSearchObject:function(esearch, node){
2142                         this.searchObjectMang.add(esearch, node)
2143                 },
2144                 clearSearchObject:function(){
2145                         this.searchObjectMang.clear()
2146                 },
2147                 setFaceImage: function(eface){
2148                         var path = this.faceStatus[eface];
2149                         this.face.image = game.assets[path];
2150                 },
2151                 myScale: function(_scaleX, _scaleY){
2152                         this.face.scale(_scaleX,_scaleY);
2153                         if(this.myCode === "REIMU"){
2154                                 this.okazari.x = -this.okazari.width / 2;
2155                                 this.okazari.y = -CHARA_HEIGHT  / 2 + (this.okazari.height * (1 - _scaleY)) / 2;
2156                         }else{
2157                                 this.okazari.x = -CHARA_WIDTH /2;
2158                                 this.okazari.y = -CHARA_HEIGHT / 2 - (CHARA_HEIGHT * _scaleY)/6;
2159                         }
2160                         if(this.sub1 != null){
2161                                 this.sub1.scale(_scaleX,_scaleY);
2162                         }
2163
2164                         this.okazari.scale(_scaleX,_scaleY);
2165                         this.hear.scale(_scaleX,_scaleY);
2166                         this.scale(_scaleX,_scaleY);
2167                         this.shadow.scale(_scaleX, _scaleY);
2168                 },
2169                 send: function(targetYukkuri, object, callback){
2170                         targetYukkuri.recv(object, callback);
2171                 },
2172                 recv: function(object, callback){
2173                         this.actionQueue.push({
2174                                 object : object,
2175                                 actionStatus : EAction.COMMUNICATE_RECV,
2176                                 callback: callback
2177                         });
2178                 },
2179                 addExValue: function(eexskill, plus){
2180                         this.exValueHash[eexskill] += plus;
2181                         if(this.exValueHash[eexskill] >= 100){
2182                                 this.exLvHash[eexskill] = 1;
2183                         }
2184                 },
2185                 getExValue: function(eexskill){
2186                         return this.exValueHash[eexskill];
2187                 },
2188                 getExSkill: function(eexskill){
2189                         return this.exLvHash[eexskill];
2190                 },
2191
2192                 setMemory: function(ememory, value){
2193                         this.memoryHash[ememory] = value;
2194                 },
2195                 getMemory: function(ememory){
2196                         return this.memoryHash[ememory];
2197                 },
2198                 destruct: function(){
2199
2200                 }
2201         });
2202         var Marisa = enchant.Class.create(Yukkuri,{
2203                 initialize: function(x, y, grow){
2204                         Yukkuri.call(this,x,y, grow);
2205                         this.classname = "Marisa";
2206                         this.myCode = "MARISA";
2207                         this.myName = "まりさ";
2208
2209                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2210                         // var json = net.load("./data/marisa/params.json");
2211                         // this.param = json.root.param;
2212                         this.param = MarisaParam;
2213                         if(this.grow == EGrow.BABY){
2214                                 this.myName = "まりちゃ";
2215                                 this.param.range /= 4;
2216                         }
2217                         else if(this.grow == EGrow.CHILD){
2218                                 this.param.range /= 3;
2219                         }
2220                         else if(this.grow == EGrow.SUBADULT){
2221                                 this.param.range *= 0.8;
2222                         }
2223                         this.shadow = new enchant.Sprite(64, 64);
2224                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2225                         this.shadow.x = 0 + this.x;
2226                         this.shadow.y = this.getWidth() / 16 + this.x;
2227
2228                         this._style.zIndex = 5;
2229
2230                         this.face = new enchant.Sprite(64, 64);
2231                         this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2232                         this.face.x = -CHARA_WIDTH / 2;
2233                         this.face.y = -CHARA_HEIGHT / 2;
2234
2235                         this.faceStatus ={};
2236                         this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2237                         this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2238                         this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2239                         this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2240                         this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2241                         this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2242                         this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2243                         this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2244                         this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2245                         this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2246
2247
2248                         this.hear = new enchant.Sprite(64, 64);
2249                         this.hear.image = game.assets[EResPath.MARISA_HEAR];
2250                         this.hear.x = -CHARA_WIDTH / 2;
2251                         this.hear.y = -CHARA_HEIGHT / 2;
2252
2253                         this.okazari = new Okazari(this);
2254
2255
2256
2257                         this.imgGroup.addChild(this.shadow);
2258                         this.imgBody.addChild(this);
2259                         this.imgBody.addChild(this.face);
2260                         this.imgBody.addChild(this.hear);
2261                         this.imgBody.addChild(this.okazari);
2262                         this.myScale(this.myScaleX, this.myScaleY)
2263                         if(this instanceof Player){
2264                                 // this.myScaleX = 0.5;
2265                                 // this.myScaleY = 0.5;
2266
2267                                 this.budge = new enchant.Sprite(16, 16);
2268                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2269                                 this.imgBody.addChild(this.budge);
2270                                 this.budge.x -= this.getWidth()/2;
2271                                 this.budge.y -= this.getHeight()/2;
2272                                 this.budge.scale(this.myScaleX, this.myScaleX);
2273                         }
2274                         this.imgGroup.width = this.getWidth();
2275                         this.imgGroup.height = this.getHeight();
2276                         this.imgGroup.addChild(this.imgBody);
2277                         backgroundMap.addChild(this.imgGroup);
2278                         this._tweet = new TTweet(148, 64);
2279
2280                         this.imgGroup.addChild(this._tweet);
2281                         this.imgGroup.x = x;
2282                         this.imgGroup.y = y;
2283
2284                         this.animation();
2285                         this.action = new Action(this);
2286                         ctl.addObj(this);
2287                 }
2288         });
2289         var Player = enchant.Class.create(Marisa,{
2290                 initialize: function(x, y){
2291                         // this.runEnterframe = function(){
2292                         // },
2293                         Marisa.call(this, x, y, EGrow.ADULT);
2294                         this.classname = "Player";
2295                         this.cmdQue = [];
2296                         ctl.setPlayer(this);
2297                         // this.removeEventListener('enterframe',this.runEnterframe);
2298                         this.addEventListener('enterframe', function(){
2299
2300
2301                                 if(this.age%10 === 0 && this.age !== 0){
2302                                         // console.log("palyer:" + this.age);
2303                                 }
2304                                 // this.act();
2305                                 ///////////////////////////////////////////////
2306                                 //Action pattern  debug
2307                                 if(game.input.left){
2308                                         // this.changeFace(EResPath.MARISA_FACE_TIRED);
2309                                         this.moveX(-10);
2310                                         this.direction = EDirection.LEFT;
2311                                 }
2312                                 if(game.input.right){
2313                                         this.moveX(10);
2314                                         this.direction = EDirection.RIGHT;
2315                                 }
2316                                 if(game.input.up){
2317                                         this.moveY(-10);
2318                                 }
2319                                 if(game.input.down){
2320                                         this.moveY(10);
2321                                 }
2322
2323                                 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2324                                 ///////////////////////////////////////////////
2325                                 // this.reverse();
2326                                 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2327                                 //      console.log("hit:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.height/2) );
2328                                 // }else{
2329                                 //      console.log("not:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.image.height/2));
2330                                 // }
2331                                 //- Display the circle of search range.
2332                                 // fieldBg.image.clear();
2333                                 // fieldBg.image.context.beginPath();
2334                                 // fieldBg.image.context.fillStyle = '#ff0000';
2335                                 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2336                                 // fieldBg.image.context.fill();
2337                         });
2338                 }
2339         });
2340         var Reimu = enchant.Class.create(Yukkuri,{
2341                 initialize: function(x, y, grow){
2342                         Yukkuri.call(this,x,y, grow);
2343                         this.classname = "Reimu";
2344                         this.myCode = "REIMU";
2345                         this.myName = "れいむ";
2346
2347                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2348                         // var json = net.load("./data/reimu/params.json");
2349                         // this.param = json.root.param;
2350                         this.param = ReimuParam;
2351                         if(this.grow == EGrow.BABY){
2352                                 this.myName = "れいみゅ";
2353                                 this.param.range /= 4;
2354                         }
2355                         else if(this.grow == EGrow.CHILD){
2356                                 this.param.range /= 3;
2357                         }
2358                         else if(this.grow == EGrow.SUBADULT){
2359                                 this.param.range *= 0.8;
2360                         }
2361                         this.shadow = new enchant.Sprite(64, 64);
2362                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2363                         this.shadow.x = 0 + this.x;
2364                         this.shadow.y = this.getWidth() / 16 + this.x;
2365                         this.shadow.image._element.style.zIndex = 2;
2366
2367                         this._style.zIndex = 5;
2368
2369                         this.face = new enchant.Sprite(64, 64);
2370                         this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2371                         this.face.x = -CHARA_WIDTH / 2;
2372                         this.face.y = -CHARA_HEIGHT / 2;
2373                         this.face._style.zIndex = 0;
2374
2375                         this.faceStatus ={};
2376                         this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2377                         this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2378                         this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2379                         this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2380                         this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2381                         this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2382                         this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2383                         this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2384                         this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2385                         this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2386
2387
2388                         this.hear = new enchant.Sprite(64, 64);
2389                         this.hear.image = game.assets[EResPathReimu.HEAR];
2390                         this.hear.x = -CHARA_WIDTH / 2;
2391                         this.hear.y = -CHARA_HEIGHT / 2;
2392
2393                         this.sub1 = new enchant.Sprite(64, 64);
2394                         this.sub1.image = game.assets[EResPathReimu.SUB1];
2395                         this.sub1.x = -CHARA_WIDTH / 2;
2396                         this.sub1.y = -CHARA_HEIGHT / 2;
2397
2398                         this.okazari = new Okazari(this);
2399
2400                         // this.imgGroup._style.zIndex = 1;
2401
2402
2403                         this.imgGroup.addChild(this.shadow);
2404                         this.imgBody.addChild(this.okazari);
2405                         this.imgBody.addChild(this);
2406                         this.imgBody.addChild(this.face);
2407                         this.imgBody.addChild(this.hear);
2408                         this.imgBody.addChild(this.sub1);
2409                         this.myScale(this.myScaleX, this.myScaleY)
2410                         if(this instanceof Player){
2411                                 // this.myScaleX = 0.5;
2412                                 // this.myScaleY = 0.5;
2413
2414                                 this.budge = new enchant.Sprite(16, 16);
2415                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2416                                 this.imgBody.addChild(this.budge);
2417                                 this.budge.x -= this.getWidth()/2;
2418                                 this.budge.y -= this.getHeight()/2;
2419                                 this.budge.scale(this.myScaleX, this.myScaleX);
2420                         }
2421                         this.imgGroup.width = this.getWidth();
2422                         this.imgGroup.height = this.getHeight();
2423                         this.imgGroup.addChild(this.imgBody);
2424                         backgroundMap.addChild(this.imgGroup);
2425                         this._tweet = new TTweet(148, 64);
2426
2427                         this.imgGroup.addChild(this._tweet);
2428                         this.imgGroup.x = x;
2429                         this.imgGroup.y = y;
2430
2431                         this.animation();
2432                         this.action = new Action(this);
2433                         ctl.addObj(this);
2434                         this.exLvHash[EExSkill.KEKKAI] = 1;
2435                         this.exValueHash[EExSkill.KEKKAI] = 100;
2436                 }
2437         });
2438
2439         game.onload = function(){
2440                 def.Food = Food;
2441                 def.Unun = Unun;
2442                 def.Place = Place;
2443                 def.ObjSprite = ObjSprite;
2444                 def.Yukkuri = Yukkuri;
2445                 def.nodeSort = nodeSort;
2446                 mangTouch = new MangTouch(ctl);
2447                 mangMsg = new MangMsg(ctl);
2448                 ctl.setDefined(def);
2449                 backgroundMap.image = game.assets[EResPath.MAP0];
2450                 backgroundMap.loadData(_mapData);
2451                 backgroundMap.collisionData = _collisionData;
2452
2453                 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2454                 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2455                 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2456                 fieldBg.image = fieldSurface;
2457                 fieldBg.x = 0;
2458                 fieldBg.y = 0;
2459
2460                 windowFront.image = windowSurface;
2461                 windowFront.x = 0;
2462                 windowFront.y = 0;
2463                 windowFront.opacity = 0.5;
2464
2465                 windowSurface.context.fillStyle = '#000';
2466                 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2467
2468
2469                 menuSurface.context.fillStyle = '#000';
2470                 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2471                 menuBg.image = menuSurface;
2472                 menuBg.x = EMenuPos.X;
2473                 menuBg.y = EMenuPos.Y;
2474                 backgroundMap.addChild(fieldBg);
2475                 mangIcon = new MangIcon(ctl, menuBg);
2476
2477                 game.rootScene.addChild(backgroundMap);
2478                 game.rootScene.addChild(windowFront);
2479                 game.rootScene.addChild(menuBg);
2480
2481                 // var labelGroup = new LabelGroup();
2482                 mangLabel = new MangLabel(ctl, menuBg);
2483                 // var info = new Label("ゆっくり");
2484                 // info.color = "#ffffff";
2485                 // info.font = "14px 'Times New Roman'";
2486                 // info.x = 4;
2487                 // info.y = GAME_HEIGHT / 2;
2488                 // labelGroup.addChild(info);
2489                 // menuBg.addChild(labelGroup);
2490
2491
2492                 // var food = new def.Food("apple", 200, 250);
2493                 backgroundMap.addChild(foodGroup);
2494                 // backgroundMap.addChild(placeGroup);
2495                 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2496                 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2497                 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2498                 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2499                 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
2500                 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2501                 new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
2502                 new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);
2503                 new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
2504                 // new Unun(100, 100);
2505                 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2506                 var touchX = 0;
2507
2508
2509                 game.rootScene.addEventListener('touchstart', function (e) {
2510                         game.touched = true;
2511                         var mang = mangTouch.get(ctl.getCurrentCommand());
2512                         mang.touchstart(e);
2513                 });
2514                 game.rootScene.addEventListener('touchmove', function (e) {
2515                         var mang = mangTouch.get(ctl.getCurrentCommand());
2516                         mang.touchmove(e);
2517                 });
2518                 game.rootScene.addEventListener('touchend', function (e) {
2519                         var mang = mangTouch.get(ctl.getCurrentCommand());
2520                         mang.touchend(e);
2521                         game.touched = false;
2522                 });
2523
2524
2525                 game.rootScene.addEventListener('enterframe', function(){
2526                         //main frame
2527                         mangLabel.draw(player);
2528                         if(this.age%BASE_FPS == 0 ){
2529                                 ctl.calcTime();
2530                         }
2531                         ctl.time += TIME_SPEED;
2532                 });
2533                 this.addEventListener('enterframe', function(){
2534                         //The priority processing of display instead of z-index
2535
2536                         backgroundMap.childNodes.sort(nodeSort);
2537                 });
2538
2539         };
2540         game.start();
2541 };