OSDN Git Service

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