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