OSDN Git Service

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