OSDN Git Service

実ゆっくり画像追加
[yukkurioverwint/YukkuriOverwinter.git] / main.js
1 enchant();
2 //////////////////////////////////////
3 /*
4     CanvasLayer初期化後にcanvasのコンテキストを操作する
5 */
6 // var initCanvas = CanvasLayer.prototype.initialize;
7
8 // CanvasLayer.prototype.initialize = function() {
9 //     initCanvas.call(this);
10 //     console.log("canvas");
11
12 //     // 拡大時の処理をNearest Neighbor方式に切り替え
13 //     // ただしChromeとFireFoxでのみ動作
14 //     this.context.imageSmoothingEnabled = false;
15 //     this.context.webkitImageSmoothingEnabled = false;
16 //     this.context.mozImageSmoothingEnabled = false;
17 // };
18 //global
19 var ctl = null;
20 var mangIcon = null;
21 var mangTouch = null;
22 var mangLabel = null;
23 var mangMsg = null;
24 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
25 var net = new Net();
26 //////////////////////////////////////
27 //define
28 //////////////////////////////////////
29 var 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.direction = 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.direction = EDirection.RIGHT;
711                                         }
712                                         else if(rand(8) == 2){
713                                                 this.yukkuri.vx = xpos;
714                                                 this.yukkuri.vy = 0;
715                                                 this.yukkuri.direction = EDirection.RIGHT;
716                                         }
717                                         else if(rand(8) == 3){
718                                                 this.yukkuri.vx = xpos;
719                                                 this.yukkuri.vy = ypos;
720                                                 this.yukkuri.direction = 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.direction = EDirection.LEFT;
730                                         }
731                                         else if(rand(8) == 6){
732                                                 this.yukkuri.vx = -xpos;
733                                                 this.yukkuri.vy = 0;
734                                                 this.yukkuri.direction = EDirection.LEFT;
735                                         }
736                                         else if(rand(8) == 7){
737                                                 this.yukkuri.vx = -xpos;
738                                                 this.yukkuri.vy = -ypos;
739                                                 this.yukkuri.direction = 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.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
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.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
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.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1408                                 yukkuri.reverse();
1409                                 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1410
1411                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1412                                         "onactiontick": this.onactiontick(this),
1413                                         "onactionend": this.onactionend(this)
1414                                 });
1415                         }
1416                 },
1417                 onactiontick:function(self){
1418                         return function(e){
1419                                 if(typeof e === "undefined")return;
1420                                 if(this.age%(BASE_FPS * 5) == 0){
1421                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1422                                 }
1423                         };
1424                 },
1425                 onactionend:function(self){
1426                         return function(e){
1427                                 if(typeof e === "undefined")return;
1428                                 self.action.setStatus(EAction.IN_HOME);
1429                                 self.release();
1430                         };
1431                 },
1432                 release:function(){
1433                         this.action = null;
1434                         this.yukkuri = null;
1435                         this.data = null;
1436                 }
1437         });
1438         var InHomeEvent = enchant.Class.create(Event,{
1439                 initialize: function (_data){
1440                         this.data = _data;
1441                         this.yukkuri = this.data.myYukkuri;
1442                         this.action = this.data.action;
1443
1444                         var yukkuri = this.yukkuri;
1445                         var place = this.data.targetNode;
1446
1447                         if(yukkuri.isVeryKuhuku()){
1448                                 if(place.isFood()){
1449                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1450                                         this.action.setStatus(EAction.EAT_IN_HOME);
1451                                         return;
1452                                 }else{
1453                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1454                                         //experience skill
1455                                         if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1456                                                 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1457                                                 this.action.setStatus(EAction.THINK);
1458                                                 return;
1459                                         }else{
1460                                                 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1461                                                 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1462                                         }
1463
1464                                 }
1465                         }
1466                         this.action.setStatus(EAction.WAIT);
1467                         var items = this.yukkuri.getItems();
1468                         if(items.length > 0){
1469                                 place.setItems(items);
1470                         }else{
1471
1472                         }
1473                         var sec = BASE_FPS * 10;
1474                         if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1475                         this.yukkuri.wait(sec, {
1476                                 "onactiontick": this.onactiontick(this),
1477                                 "onactionend": this.onactionend(this)
1478                         });
1479                 },
1480                 onactiontick:function(self){
1481                         return function(e){
1482                                 if(typeof e === "undefined")return;
1483                                 if(this.age%(BASE_FPS * 5) == 0){
1484                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1485                                 }
1486                         };
1487                 },
1488                 onactionend:function(self){
1489                         return function(e){
1490                                 if(typeof e === "undefined")return;
1491                                 self.action.setStatus(EAction.THINK_IN_HOME);
1492                         };
1493                 }
1494         });
1495         var EatInHomeEvent = enchant.Class.create(Event,{
1496                 initialize: function (_data){
1497                         this.data = _data;
1498                         this.yukkuri = _data.myYukkuri;
1499                         this.place = _data.targetNode;
1500                         this.action = _data.action;
1501                         this.action.setStatus(EAction.EAT_WAIT);
1502
1503                         var sec = BASE_FPS * 3;
1504                         var foodHash = this.place.getFoodHash();
1505                         if(foodHash !== false && this.yukkuri.eat(foodHash)){
1506                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1507                                 this.yukkuri.setFaceImage(EFace.EAT2);
1508                         }else{
1509                                 sec = BASE_FPS * 6;
1510                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1511                                 this.yukkuri.setFaceImage(EFace.CRY2);
1512                         }
1513
1514                         this.yukkuri.wait(sec, {
1515                                 "onactionend": this.onactionend(this)
1516                         });
1517                 },
1518                 onactionend:function(self){
1519                         return function(e){
1520                                 if(typeof e === "undefined")return;
1521                                 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1522                                         self.action.setStatus(EAction.EAT_IN_HOME);
1523
1524                                         // new EatInHomeEvent({
1525                                         //      "targetNode": self.place,
1526                                         //      "action": self.action,
1527                                         //      "myYukkuri": self.yukkuri
1528                                         // });
1529                                 }else{
1530                                         self.action.setStatus(EAction.THINK_IN_HOME);
1531                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1532                                 }
1533                         };
1534                 }
1535         });
1536
1537
1538         var MoveToCommandEvent = enchant.Class.create(Event,{
1539                 initialize: function (_data){
1540                         this.data = _data;
1541                         this.yukkuri = this.data.myYukkuri;
1542                         this.action = this.data.action;
1543                         // this.vx = this.data.cmdObject.vx;
1544                         // this.vy = this.data.cmdObject.vy;
1545                         // var vx = (-backgroundMap.x + e.x) - this.ctl.player.getX() ;
1546
1547
1548                         var yukkuri = this.yukkuri;
1549                         this.action.status = EAction.WAIT;
1550                         yukkuri.vx = this.data.cmdObject.touchX - this.yukkuri.getX();
1551                         yukkuri.vy = this.data.cmdObject.touchY - this.yukkuri.getY();
1552                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1553                         var frame = distance + distance/2 + 1;
1554                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1555
1556                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1557
1558                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1559                                 "onactiontick": this.onactiontick(this),
1560                                 "onactionend": this.onactionend(this)
1561                         });
1562                 },
1563                 onactiontick:function(self){
1564                         return function(e){
1565                                 if(typeof e === "undefined")return;
1566                         };
1567                 },
1568                 onactionend:function(self){
1569                         return function(e){
1570                                 if(typeof e === "undefined")return;
1571                                 self.action.setStatus(EAction.THINK);
1572                         };
1573                 }
1574         });
1575         /**
1576          * Say hello contact to send communication .
1577          */
1578         var ComSayHelloSendEvent = enchant.Class.create(Event,{
1579                 initialize: function (_data){
1580                         this.data = _data;
1581                         this.yukkuri = _data.myYukkuri;
1582                         this.targetYukkuri = _data.targetNode;
1583                         this.action = _data.action;
1584                         this.action.setStatus(EAction.COMMUNICATE_WAIT);
1585                         // this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1586                         // this.targetYukkuri.tlPause();
1587                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1588                         this.yukkuri.send(this.targetYukkuri, {
1589                                 "actionStatus":EAction.COMMUNICATE_RECV,
1590                                 "yukkuri":this.yukkuri
1591                         });
1592
1593
1594                         this.yukkuri.tlPause();
1595                         this.yukkuri.syncDirection(this.targetYukkuri);
1596
1597                         this.yukkuri.addAddress(this.targetYukkuri);
1598                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1599
1600                         var sec = BASE_FPS * 2;
1601                         this.yukkuri.wait(sec, {
1602                                 "onactiontick": this.onactiontick(this),
1603                                 "onactionend": this.onactionend(this)
1604                         });
1605                 },
1606                 onactiontick:function(self){
1607                         return function(e){
1608                                 if(typeof e === "undefined")return;
1609                         };
1610                 },
1611                 onactionend:function(self){
1612                         return function(e){
1613                                 if(typeof e === "undefined")return;
1614                                 new ComSayHelloRecvEvent({
1615                                         "type": 'greeting',
1616                                         "targetNode": self.yukkuri,
1617                                         "action": self.targetYukkuri.action,
1618                                         "myYukkuri": self.targetYukkuri
1619                                 });
1620                         };
1621                 }
1622         });
1623         var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1624                 initialize: function (_data){
1625                         this.data = _data;
1626                         this.yukkuri = _data.myYukkuri;
1627                         this.targetYukkuri = _data.targetNode;
1628                         this.action = _data.action;
1629                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1630                         this.yukkuri.addAddress(this.targetYukkuri);
1631                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1632
1633                         var sec = BASE_FPS * 2;
1634                         this.yukkuri.wait(sec, {
1635                                 "onactiontick": this.onactiontick(this),
1636                                 "onactionend": this.onactionend(this)
1637                         });
1638                 },
1639                 onactiontick:function(self){
1640                         return function(e){
1641                                 if(typeof e === "undefined")return;
1642                         };
1643                 },
1644                 onactionend:function(self){
1645                         return function(e){
1646                                 if(typeof e === "undefined")return;
1647                                 self.action.setStatus(EAction.THINK);
1648
1649                                 self.yukkuri.action.setStatus(EAction.THINK);
1650                                 self.yukkuri.animation();
1651                                 self.targetYukkuri.action.setStatus(EAction.THINK);
1652                                 self.targetYukkuri.animation();
1653                         };
1654                 }
1655         });
1656         var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1657                 initialize: function (_data){
1658                         this.data = _data;
1659                         this.yukkuri = this.data.myYukkuri;
1660                         this.action = this.data.action;
1661
1662                         var yukkuri = this.yukkuri;
1663                         var node = this.data.targetNode;
1664
1665                         this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1666                         yukkuri.vx = node.x + node.width /2  - yukkuri.getX();
1667                         yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1668                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1669                         var frame = distance + distance/5 + 1;
1670                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1671
1672                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1673                         yukkuri.reverse();
1674                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1675                                 "onactionend": this.onactionend(this)
1676                         });
1677                 },
1678                 onactionend:function(self){
1679                         return function(e){
1680                                 if(typeof e === "undefined")return;
1681                                 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1682                                 self.data = null;
1683                                 self.yukkuri = null;
1684                                 self.action = null;
1685                         };
1686                 }
1687         });
1688         var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1689                 initialize: function (_data){
1690                         this.data = _data;
1691                         this.yukkuri = _data.myYukkuri;
1692                         this.place = _data.targetNode;
1693                         this.action = _data.action;
1694                         this.action.setStatus(EAction.WAIT);
1695
1696
1697                         var sec = BASE_FPS * 3;
1698                         this.yukkuri.declarePlace(this.place);
1699                         this.place.setOwner(this.yukkuri);
1700                         mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1701
1702                         this.yukkuri.setFaceImage(EFace.NORMAL);
1703                         this.yukkuri.wait(sec, {
1704                                 "onactionend": this.onactionend(this)
1705                         });
1706                 },
1707                 onactionend:function(self){
1708                         return function(e){
1709                                 if(typeof e === "undefined")return;
1710                                 self.action.setStatus(EAction.THINK);
1711                         };
1712                 }
1713         });
1714
1715         var Food = enchant.Class.create(ObjSprite,{
1716                 initialize: function (type, x, y){
1717                         this.classname = "Food";
1718                         //一つにつきgiveの値分、hunguryを減少させられる
1719                         if(type == "apple"){
1720                                 ObjSprite.call(this,16,16);
1721                                 this.image = game.assets[EResPath.OBJECT];
1722                                 this.frame = 15;
1723                                 this.give = 40;
1724                                 this.amount = 3;
1725                         }else if(type == "grass"){
1726                                 ObjSprite.call(this,64,64);
1727                                 this.image = game.assets[EResPath.GRASS];
1728                                 this.frame = 0;
1729                                 this.give = 10;
1730                                 this.amount = 20;
1731                         }
1732                         this.x = x;
1733                         this.y = y;
1734                         foodGroup.addChild(this);
1735                         this.addEventListener('enterframe', function(){
1736                                 if(this.amount <= 0){
1737                                         this.removeAll();
1738                                 }
1739                         });
1740                 },
1741                 getAmount: function(){
1742                         return this.amount;
1743                 },
1744                 getGive: function(){
1745                         return this.give;
1746                 }
1747         });
1748         var MemoryPlace = enchant.Class.create({
1749                 // initialize: function (place){
1750                 //      if(place.x != null){
1751                 //              this.isWorld = true;
1752                 //      }else{
1753                 //              this.isWorld = false;
1754                 //      }
1755                 //      this.isWorld = (place.x != null);
1756                 //      this.x = place.x;
1757                 //      this.y = place.y;
1758                 //      this.width = place.width;
1759                 //      this.height = place.height;
1760                 // },
1761                 // isWorld: function(){
1762                 //      return this.isWorld;
1763                 // }
1764
1765         });
1766         var MemoryFood = enchant.Class.create({
1767                 initialize: function (food){
1768                         if(food.x != null){
1769                                 this.isWorld = true;
1770                         }else{
1771                                 this.isWorld = false;
1772                         }
1773                         this.isWorld = (food.x != null);
1774                         this.x = food.x;
1775                         this.y = food.y;
1776                         this.width = food.width;
1777                         this.height = food.height;
1778                 },
1779                 isWorld: function(){
1780                         return this.isWorld;
1781                 }
1782         });
1783         var Place = enchant.Class.create(ObjSprite,{
1784                 initialize: function (type, x, y){
1785                         ObjSprite.call(this,128,128);
1786                         this.image = game.assets[EResPath.PLACE_TREE];
1787                         this.x = x - this.width / 2;
1788                         this.y = y - this.height / 2;
1789                         backgroundMap.addChild(this);
1790                         this.owner = null;
1791                         this.foods = [];
1792                         for(var key in EFood){
1793                                 var efood = EFood[key];
1794                                 this.foods[efood] = 0;
1795                         }
1796                         // this.addEventListener('enterframe', function(){
1797                         //      if(this.age%10 === 0 && this.age !== 0){
1798                         //              console.log("x/y " + this.x + "/" + this.y);
1799                         //      }
1800                         //      if(game.input.left){
1801                         //              this.x -= 10;;
1802                         //      }
1803                         //      if(game.input.right){
1804                         //              this.x += 10;;
1805                         //      }
1806                         //      if(game.input.up){
1807                         //              this.y -= 10;;
1808                         //      }
1809                         //      if(game.input.down){
1810                         //              this.y += 10;;
1811                         //      }
1812                         // });
1813                 },
1814                 getStatusForDisplay: function(){
1815                         var ret = "";
1816                         var ownerId = "なし";
1817                         if(this.owner == null)ownerId = "なし";
1818                         else ownerId = this.owner.id;
1819                         ret += "プレイスID " + this.id + "\n";
1820                         ret += "オーナーID " + ownerId + "\n";
1821                         ret += "食料うめぇ  " + this.foods[EFood.GREAT] + "\n";
1822                         ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1823                         ret += "食料にがにが  " + this.foods[EFood.BAD] + "\n";
1824                         return ret;
1825                 },
1826                 setItems:function(items){
1827                         var len = items.length;
1828                         for(var i=0; i<len; i++){
1829                                 var item = items[i];
1830                                 if(item instanceof Food){
1831                                         this.foods[EFood.NORMAL]++;
1832                                 }
1833                         }
1834                         items.length = 0;
1835                 },
1836                 isFood:function(){
1837                         var ret = 0;
1838                         for(var key in EFood){
1839                                 var efood = EFood[key];
1840                                 ret += this.foods[efood];
1841                         }
1842                         return ret !== 0;
1843                 },
1844                 getFoodHash:function(){
1845                         if(this.foods[EFood.GREAT] !== 0){
1846                                 this.foods[EFood.GREAT]--;
1847                                 return {give:20,yukkuri:15,unun:20};
1848                         }
1849                         else if(this.foods[EFood.NORMAL] !== 0){
1850                                 this.foods[EFood.NORMAL]--;
1851                                 return {give:10,yukkuri:5,unun:10};
1852                         }
1853                         else if(this.foods[EFood.BAD] !== 0){
1854                                 this.foods[EFood.BAD]--;
1855                                 return {give:10,yukkuri:-2,unun:10};
1856                         }
1857                         return false;
1858                 },
1859                 setOwner: function(yukkuri){
1860                         this.owner = yukkuri;
1861                 },
1862                 isOwner: function(){
1863                         return this.owner !== null;
1864                 }
1865         });
1866         var Unun = enchant.Class.create(ObjSprite,{
1867                 initialize: function (x, y){
1868                         this.classname = "Unun";
1869                         ObjSprite.call(this,32,32);
1870                         this.image = game.assets[EResPath.YUKKURI_UNUN];
1871                         this.x = x;
1872                         this.y = y;
1873                         backgroundMap.addChild(this);
1874                         // this.lifetime = 30 * 24 * 3;
1875                         this.lifetime = 15 * 24;
1876                         this.addEventListener('enterframe', this.runEnterframe(this));
1877                         // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1878
1879                 },
1880                 runEnterframe:function(self){
1881                         return function(e){
1882                                 if(typeof e === "undefined")return;
1883                                 if(this.age%BASE_FPS === 0 && this.age !== 0){
1884                                         self.lifetime--;
1885                                         if(self.lifetime <= 0){
1886                                                 this.parentNode.removeChild(this);
1887                                                 ctl.backgroundMap.removeChild(this);
1888                                                 ctl.removeObj(this);
1889                                                 self.image = null;
1890                                         }
1891                                 }
1892
1893                         };
1894                 }
1895         });
1896         var Okazari = enchant.Class.create(enchant.Sprite,{
1897                 initialize: function(yukkuri){
1898                         this.classname = "Okazari";
1899                         if(yukkuri.myCode === "REIMU"){
1900                                 enchant.Sprite.call(this, 80, 32);
1901                                 this.image = game.assets[EResPathReimu.OKAZARI];
1902                                 this.x = -CHARA_WIDTH / 3 * 2;
1903                                 this.y = -yukkuri.getHeight()/5 * 2 - 4;
1904                         }else{
1905                                 enchant.Sprite.call(this, 64, 64);
1906                                 this.image = game.assets[EResPath.MARISA_OKAZARI];
1907                                 this.x = -CHARA_WIDTH / 2;
1908                                 this.y = -CHARA_HEIGHT / 2 - yukkuri.getHeight()/6;
1909                         }
1910                         this.yukkuri = yukkuri;
1911                 },
1912                 getWidth: function(){
1913                         return this.width;
1914                         // return this.width * this.yukkuri.myScaleX;
1915                 },
1916                 getHeight: function(){
1917                         return this.height;
1918                         // return this.height * this.yukkuri.myScaleY;
1919                 }
1920         });
1921         var Kuki = enchant.Class.create(ObjSprite,{
1922                 initialize: function(yukkuri, x, y){
1923                         this.classname = "Kuki";
1924                         enchant.Sprite.call(this, 56, 40);
1925                         this.image = game.assets[EResPath.KUKI];
1926                         this.x = 0 + x;
1927                         this.y = -CHARA_HEIGHT / 2 -CHARA_HEIGHT / 4 + y;
1928                         this.owner = yukkuri;
1929                         this.miYukkuris = [];
1930                 },
1931                 addMiYukkuri: function(miYukkuri){
1932                         // miYukkuri.setX(miYukkuri.getX() + 30);
1933                         // miYukkuri.setY(miYukkuri.getY() - 30);
1934                         this.miYukkuris.push(miYukkuri);
1935                 },
1936                 getMiYukkuris: function(){
1937                         return this.miYukkuris;
1938                 },
1939                 getX : function(){
1940                         return this.x;
1941                 },
1942                 getY : function(){
1943                         return this.y;
1944                 },
1945                 getWidth: function(){
1946                         return this.width;
1947                         // return this.width * this.yukkuri.myScaleX;
1948                 },
1949                 getHeight: function(){
1950                         return this.height;
1951                         // return this.height * this.yukkuri.myScaleY;
1952                 }
1953         });
1954         var Address = enchant.Class.create({
1955                 initialize: function(yukkuri){
1956                         this.friendlyLv = 1;
1957                         this.yukkuri = yukkuri;
1958                         this.isGreeting = false;
1959                         this.greetingWaitFrame = 0;
1960                         this.comMatrix = {
1961                                 "beginSayHello" : false,
1962                                 "sayHello" : false,
1963                         };
1964                         this.evtHash = {};
1965                 },
1966                 set:function(key, value){
1967                         this.comMatrix[key] = value;
1968                 },
1969                 get:function(key){
1970                         return this.comMatrix[key];
1971                 }
1972         });
1973
1974         var Yukkuri = enchant.Class.create(ObjSprite,{
1975                 initialize: function(x, y, grow){
1976                         ObjSprite.call(this, 64, 64);
1977                         this.searchObjectMang = new SearchObjectMang();
1978                         this.grow = grow;
1979                         //base plyaer only
1980                         this.cmdQueue = [];
1981                         this.myCode = "YUKKURI";
1982                         this.myName = "ゆっくり";
1983                         this.beforeHuntingFood = null;
1984                         if(grow == EGrow.ADULT){
1985                                 this.myScaleX = 1;
1986                                 this.myScaleY = 1;
1987                                 this.mySize = "L";
1988                         }
1989                         else if(grow == EGrow.SUBADULT){
1990                                 this.myScaleX = 0.8;
1991                                 this.myScaleY = 0.8;
1992                                 this.mySize = "M";
1993                         }
1994                         else if(grow == EGrow.CHILD){
1995                                 this.myScaleX = 0.6;
1996                                 this.myScaleY = 0.6;
1997                                 this.mySize = "S";
1998                         }
1999                         else if(grow == EGrow.BABY){
2000                                 this.myScaleX = 0.3;
2001                                 this.myScaleY = 0.3;
2002                                 this.mySize = "SS";
2003                         }
2004                         else if(grow == EGrow.FRUIT_BABY){
2005                                 this.myScaleX = 0.2;
2006                                 this.myScaleY = 0.2;
2007                                 this.mySize = "SSS";
2008                         }
2009
2010                         // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
2011                         this.classname = "Yukkuri";
2012                         this.addressBook = {};
2013                         // this.imgGroup = new SpriteGroup();
2014                         // this.imgBody = new SpriteGroup();
2015                         // this.imgGroup.id = guid();
2016                         // this.imgBody.id = guid();
2017                         this.x = -CHARA_WIDTH / 2;
2018                         this.y = -CHARA_HEIGHT / 2;
2019                         this.vx = 0;
2020                         this.vy = 0;
2021                         this.image = game.assets[EResPath.YUKKURI_BASE];
2022                         this.direction = EDirection.RIGHT;
2023                         this.addEventListener('enterframe', this.runEnterframe);
2024                         this.bodyStatus ={};
2025                         this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
2026                         this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
2027                         this.walkAnimationStatus = EWalkAnimation.END;
2028                         this.place = null;
2029                         this.items = [];
2030                         this.actionQueue = [];
2031                         this.exLvHash = {};
2032                         this.exValueHash = {};
2033                         this.memoryHash = {};
2034                         this.communicateYukkuri = {};
2035                         for(var _v in EExSkill){
2036                                 var key = EExSkill[_v];
2037                                 this.exLvHash[key] = 0;
2038                                 this.exValueHash[key] = 0;
2039                         }
2040                         this.kukis = [];
2041                         this.formSprite = new FormSprite();
2042                 },
2043                 runEnterframe:function(){
2044                         // console.log("runEnterframe");
2045                                 // this.formSprite.run();
2046                                 // this.formSprite.addX(1);
2047
2048                         // try{
2049                                 if(this.grow == EGrow.FRUIT_BABY){
2050                                 }else{
2051                                         if(this.kukis){
2052                                                 // this.kukis[0].miYukkuris[0].setX(this.getX());
2053                                                 // this.kukis[0].miYukkuris[0].setY(this.getY());
2054                                                 // var _x = this.imgBody.tl.node.x;
2055                                                 // var _y = this.imgBody.tl.node.y;
2056                                                 // var _gety = this.kukis[0].miYukkuris[0].getY();
2057                                                 // this.kukis[0].miYukkuris[0].setOldY();
2058                                                 // this.kukis[0].miYukkuris[0].animY(-_y);
2059                                                 // this.kukis[0].direction = this.direction;
2060                                         }
2061                                         // console.log(this.getX() + ":" + this.getY());
2062                                         this.act();
2063                                         if(this.isDead())return;
2064                                         this.runYukkuri();
2065                                         this.runHungry();
2066                                         this.runUnun();
2067                                         this.runSleep();
2068                                         this.runAddress();
2069                                         this.runAnimation();
2070                                         // this.animation();
2071
2072                                 }
2073                         // }catch(e){
2074                         //      console.log(e);
2075                         // }
2076                 },
2077                 reverse:function(){
2078                         if(this.direction == EDirection.RIGHT){
2079                                 this.formSprite.formScaleX(this.myScaleX);
2080                                 if(this instanceof Player){
2081                                         this.formSprite.setFixBudgeRight(5);
2082                                 }
2083                                 this.formSprite.setFixKukiRight();
2084                                 // this.formSprite.formScaleY(this.myScale);
2085
2086                                 // this.imgBody.scaleX = 1;
2087                         }
2088                         else if(this.direction == EDirection.LEFT){
2089                                 this.formSprite.formScaleX(-this.myScaleX);
2090                                 if(this instanceof Player){
2091                                         this.formSprite.setFixBudgeLeft(5);
2092                                         this.formSprite.setFixKukiLeft();
2093                                 }
2094                                 this.formSprite.setFixKukiLeft();
2095                                 // this.formSprite.formScaleY(this.myScale);
2096                                 // this.imgBody.scaleX = -1;
2097                         }
2098                 },
2099                 tweet:function(text){
2100                         text = text.replace(/%name%/g, this.myName);
2101                         // this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
2102                         this._tweet.text(text, this.getX() - this._tweet.width/4, this.getY() - this._tweet.height);
2103                 },
2104                 moveTo:function(x, y, time){
2105                         this.formSprite.tlMoveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
2106                         // this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
2107                 },
2108                 moveBy:function(x, y, time, eventFunctions){
2109                         this.formSprite.tlMoveBy(x, y, time, eventFunctions);
2110                         // var self = this;
2111                         // var params = {
2112                         //      x: function() {
2113                         //              return self.getX() + x;
2114                         //              // return self.imgGroup.x + x;
2115                         //      },
2116                         //      y: function() {
2117                         //              return self.getY() + y;
2118                         //              // return self.imgGroup.y + y;
2119                         //      },
2120                         //      time: time,
2121                         //      easing: enchant.Easing.SIN_EASEINOUT
2122                         // };
2123                         // //-Event register [onactionstart,onactiontick,onactionend]
2124                         // if(eventFunctions !== undefined){
2125                         //      for(var key in eventFunctions){
2126                         //              params[key] = eventFunctions[key];
2127                         //      }
2128                         // }
2129                         // console.log("moveBy");
2130                         // console.log("self.x:" + self.getX());
2131                         // return this.formSprite.tlTween(params);
2132                         // // return this.imgGroup.tl.tween(params);
2133                 },
2134                 wait:function(frame, eventFunctions){
2135                         this.moveBy(0,0,frame,eventFunctions);
2136                 },
2137                 act: function(){
2138                         this.action.act();
2139                 },
2140                 runAnimation: function(){
2141                         this.formSprite.formRunAnimation();
2142                 },
2143                 animation: function(){
2144                         this.formSprite.formStartAnimation();
2145                         // var frame = 10;
2146                         // frame -= plusFrameScale(frame, this.getMyScale()) / 2;
2147                         // var move = 5;
2148                         // move -= plusFrameScale(move, this.getMyScale());
2149                         // if(this.walkAnimationStatus == EWalkAnimation.END){
2150                         //      this.imgBody.y = 0;
2151                         //      this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
2152                         //              "onactionstart": function(e){
2153                         //                      this.walkAnimationStatus = EWalkAnimation.START;
2154                         //              }
2155                         //      })
2156                         //      .moveByEx(0, move, frame, enchant.Easing.SWING,
2157                         //      {
2158                         //              "onactionend": function(e){
2159                         //                      this.walkAnimationStatus = EWalkAnimation.END;
2160                         //              }
2161                         //      }).loop();
2162                         // }else{
2163                         //      this.imgBody.tl.loop();
2164                         // }
2165                 },
2166                 getMyScale: function(){
2167                         return (this.myScaleX + this.myScaleY) / 2;
2168                 },
2169                 getWidth: function(){
2170                         return this.width * this.myScaleX;
2171                 },
2172                 getHeight: function(){
2173                         return this.height * this.myScaleY;
2174                 },
2175                 setX: function(x){
2176                         this.formSprite.setX(x);
2177                         // this.imgGroup.x = x;
2178                 },
2179                 setY: function(y){
2180                         this.formSprite.setY(y);
2181                         // this.imgGroup.y = y;
2182                 },
2183                 getX: function(){
2184                         return this.formSprite.getX();
2185                         // return this.imgGroup.x;
2186                 },
2187                 getY: function(){
2188                         return this.formSprite.getY();
2189                         // return this.imgGroup.y;
2190                 },
2191                 moveX: function(x){
2192                         this.formSprite.addX(x);
2193                         // this.imgGroup.x += x;
2194                 },
2195                 moveY: function(y){
2196                         this.formSprite.addY(y);
2197                         // this.imgGroup.y += y;
2198                 },
2199                 // changeFace: function(erespath){
2200                 //      this.face.image = game.assets[erespath];
2201                 // },
2202                 loadParamsXML: function(url){
2203                         var http = new JKL.ParseXML( url );
2204                         return http.parse();
2205                 },
2206                 runYukkuri: function(){
2207                         if(this.param.hungry > 70){
2208                                 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
2209                                         this.param.yukkuri -= 1;
2210                                 }
2211                         }
2212                         else if(this.param.hungry < 10){
2213                                 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
2214                         }
2215
2216                         if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
2217                         else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
2218
2219                         var x = this.getX();
2220                         var y = this.getY();
2221
2222                         var kukiLength = this.kukis.length;
2223                         var yukkuris = [];
2224                         if(kukiLength > 0){
2225                                 for(var i=0;i<kukiLength;i++){
2226                                         var kuki = this.kukis[i];
2227                                         yukkuris = kuki.getMiYukkuris();
2228                                         var yukkuriLength = yukkuris.length;
2229                                         for(var j=0;j<yukkuriLength;j++){
2230                                                 var yukkuri = yukkuris[j];
2231                                                 yukkuri.setX(x);
2232                                                 yukkuri.setY(y);
2233                                         }
2234                                 }
2235
2236                         }
2237                 },
2238                 runHungry: function(){
2239                         if(this.age%50 === 0 && this.age !== 0)this.param.hungry += ADD_HUNGRY;
2240                         if(this.param.hungry >= 100)this.param.hungry = 100;
2241                 },
2242                 runUnun: function(){
2243                         if(this.age%50 === 0 && this.age !== 0)this.param.unun += 1;
2244                         if(this.param.unun >= 100)this.param.unun = 100;
2245                 },
2246                 runSleep: function(){
2247                         if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
2248                                 if(this.age%80 === 0 && this.age !== 0)this.param.sleep += 1;
2249                                 if(this.param.sleep >= 100){
2250                                         this.param.sleep = 100;
2251                                 }
2252                         }
2253                 },
2254                 runAddress: function(){
2255                         for(var key in this.addressBook){
2256                                 var address = this.addressBook[key];
2257                                 //挨拶時間。24時間に1度だけ。
2258                                 if(address.isGreeting){
2259                                         address.greetingWaitFrame++;
2260                                         if(address.greetingWaitFrame >= DAY){
2261                                                 address.greetingWaitFrame = 0;
2262                                                 address.isGreeting = false;
2263                                         }
2264                                 }
2265                         }
2266                 },
2267                 changeFace: function(){
2268                         if(this.param.yukkuri >= 80){
2269                                 this.setFaceImage(EFace.HAPPY1);
2270                         }
2271                         else if(this.param.yukkuri >= 50){
2272                                 this.setFaceImage(EFace.NORMAL);
2273                         }
2274                         else if(this.param.yukkuri >= 30){
2275                                 this.setFaceImage(EFace.TIRED);
2276                         }
2277                         else if(this.param.yukkuri >= 10){
2278                                 this.setFaceImage(EFace.CRY1);
2279                         }
2280                         else if(this.param.yukkuri >= 1){
2281                                 this.setFaceImage(EFace.CRY2);
2282                         }
2283                 },
2284                 getRange: function(){
2285                         return this.param.range;
2286                 },
2287                 isSleep: function(){
2288                         return this.param.sleep >= 100;
2289                 },
2290                 isDead: function(){
2291                         return this.param.yukkuri <= 0;
2292                 },
2293                 isManpuku: function(){
2294                         return this.param.hungry <= 20;
2295                 },
2296                 isKuhuku: function(){
2297                         return this.param.hungry >= 40;
2298                 },
2299                 isVeryKuhuku: function(){
2300                         return this.param.hungry >= 80;
2301                 },
2302                 getYukkuri: function(){
2303                         return this.param.yukkuri;
2304                 },
2305                 setYukkuri: function(yukkuri){
2306                         this.param.yukkuri = yukkuri;
2307                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2308                 },
2309                 addYukkuri: function(yukkuri){
2310                         this.param.yukkuri += yukkuri;
2311                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2312                 },
2313                 getHungry: function(){
2314                         return this.param.hungry;
2315                 },
2316                 setHungry: function(hungry){
2317                         this.param.hungry = hungry;
2318                         if(this.param.hungry < 0)this.param.hungry = 0;
2319                 },
2320                 getUnun: function(){
2321                         return this.param.unun;
2322                 },
2323                 getLooksNumber: function(){
2324                         return this.param.looks;
2325                 },
2326                 getLooksText: function(){
2327                         if(this.param.looks == ELooks.GOOD_YUKKURI){
2328                                 return "びゆん";
2329                         }
2330                         if(this.param.looks == ELooks.NORMAL_YUKKURI){
2331                                 return "ぼんゆん";
2332                         }
2333                         if(this.param.looks == ELooks.BAD_YUKKURI){
2334                                 return "ぶさゆん";
2335                         }
2336                         return "";
2337                 },
2338                 setUnun: function(unun){
2339                         this.param.unun = unun;
2340                         if(this.param.unun < 0)this.param.unun = 0;
2341                 },
2342
2343                 eat:function(food){
2344                         if(food instanceof Food){
2345                                 //Food object case
2346                                 if(food.amount > 0){
2347                                         food.amount--;
2348                                         this.setHungry(this.param.hungry - food.getGive());
2349                                         this.setUnun(this.getUnun() + food.getGive() / 4);
2350                                         this.setYukkuri(this.getYukkuri() + 5);
2351                                         return true;
2352                                 }else{
2353                                         this.setYukkuri(this.getYukkuri() - 5);
2354                                         return false;
2355                                 }
2356                         }else{
2357                                 //hash case
2358                                 if(food != null){
2359                                         this.setHungry(this.param.hungry - food.give);
2360                                         this.setUnun(this.getUnun() + food.unun);
2361                                         this.setYukkuri(this.getYukkuri() + food.yukkuri);
2362                                         return true;
2363                                 }else{
2364                                         return false;
2365                                 }
2366                         }
2367                 },
2368                 hunt:function(food){
2369                         if(food.amount > 0){
2370                                 if(!this.isItemsMax()){
2371                                         food.amount--;
2372                                         this.items.push(food);
2373                                         this.setYukkuri(this.getYukkuri() + 1);
2374                                         return true;
2375                                 }
2376                         }
2377                         return false;
2378                 },
2379                 declarePlace: function(place){
2380                         this.place = place;
2381                 },
2382                 getPlace:function(){
2383                         return this.place;
2384                 },
2385                 isPlace: function(){
2386                         return this.place !== null;
2387                 },
2388
2389                 unun:function(){
2390                         if(this.direction == EDirection.RIGHT){
2391                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2392                         }else{
2393                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2394                         }
2395                         // if(this.direction == EDirection.RIGHT){
2396                         //      new Unun(this.getX() + this.getWidth()/2 - this.getWidth()/5, this.getY() + this.getHeight() / 2 +  this.getHeight() / 5 );
2397                         // }else{
2398                         //      new Unun(this.getX() + this.getWidth()/2 - this.getWidth()/5, this.getY() + this.getHeight() / 2 + this.getHeight() / 5 );
2399                         // }
2400                         this.setUnun(0);
2401                 },
2402                 setBodyImage: function(ebody){
2403                         var path = this.bodyStatus[ebody];
2404                         this.image = game.assets[path];
2405                 },
2406                 tlPause:function(){
2407                         // this.imgBody.tl.clear();
2408                         // this.imgGroup.tl.clear();
2409                         // this.imgBody.tl.unloop();
2410                         // this.imgGroup.tl.unloop();
2411                         // this.imgBody.y = 0;
2412                         this.formSprite.formStopAnimation();
2413                 },
2414                 tlResume: function(){
2415                         // this.imgBody.tl.resume();
2416                         // this.imgGroup.tl.resume();
2417                         this.animation();
2418                 },
2419                 syncDirection:function(senderYukkuri){
2420                         if(this.getX() > senderYukkuri.getX()){
2421                                 this.direction = EDirection.LEFT;
2422                                 senderYukkuri.direction = EDirection.RIGHT;
2423                         }else{
2424                                 this.direction = EDirection.RIGHT;
2425                                 senderYukkuri.direction = EDirection.LEFT;
2426                         }
2427                 },
2428                 isCommunication: function(yukkuri){
2429                         if(this.addressBook[yukkuri.id] === undefined) return true;
2430                         if(this.addressBook[yukkuri.id].isGreeting) return false;
2431                         return true;
2432                 },
2433                 addAddress: function(yukkuri){
2434                         this.addressBook[yukkuri.id] = new Address(yukkuri);
2435                 },
2436                 getAddress: function(yukkuri){
2437                         if(this.addressBook[yukkuri.id] === undefined)return null;
2438                         return this.addressBook[yukkuri.id];
2439                 },
2440                 getStatusForDisplay: function (){
2441                         var ret = "";
2442                         var placeId = (this.place==null)?"無し" : this.place.id;
2443                         ret += "ID " + this.id + "\n";
2444                         ret += "プレイス  " + placeId + "\n";
2445                         ret += "ゆっくり  " + this.getYukkuri() + "\n";
2446                         ret += "空腹  " + this.getHungry() + "\n";
2447                         ret += "うんうん  " + this.getUnun() + "\n";
2448                         ret += "もちもの  " + this.items.length + "\n";
2449                         ret += "容姿  " + this.getLooksText() + "\n";
2450                         ret += "debug  " + this.action.status + "\n";
2451                         return ret;
2452                 },
2453                 isItemsMax:function(){
2454                         return this.items.length >= this.param.items_max;
2455                 },
2456                 getItems:function(){
2457                         return this.items;
2458                 },
2459                 addSearchObject:function(esearch, node){
2460                         this.searchObjectMang.add(esearch, node)
2461                 },
2462                 clearSearchObject:function(){
2463                         this.searchObjectMang.clear()
2464                 },
2465                 setFaceImage: function(eface){
2466                         var path = this.faceStatus[eface];
2467                         this.face.image = game.assets[path];
2468                 },
2469                 myScale: function(_scaleX, _scaleY){
2470                         this.formSprite.scale(_scaleX, _scaleY);
2471                         // this.face.scale(_scaleX,_scaleY);
2472                         // if(this.myCode === "REIMU"){
2473                         //      // this.okazari.x = -this.okazari.width / 2;
2474                         //      // this.okazari.y = -CHARA_HEIGHT  / 2 + (this.okazari.height * (1 - _scaleY)) / 2;
2475                         // }else{
2476                         //      // this.okazari.x = -CHARA_WIDTH /2;
2477                         //      // this.okazari.y = -CHARA_HEIGHT / 2 - (CHARA_HEIGHT * _scaleY)/6;
2478                         // }
2479                         // if(this.sub1 != null){
2480                         //      this.sub1.scale(_scaleX,_scaleY);
2481                         // }
2482
2483                         // this.okazari.scale(_scaleX,_scaleY);
2484                         // this.hear.scale(_scaleX,_scaleY);
2485                         // this.scale(_scaleX,_scaleY);
2486                         // if(this.shadow)this.shadow.scale(_scaleX, _scaleY);
2487                 },
2488                 send: function(targetYukkuri, object, callback){
2489                         this.communicateYukkuri = targetYukkuri;
2490                         targetYukkuri.recv(object, callback);
2491                 },
2492                 recv: function(object, callback){
2493                         this.communicateYukkuri = object.yukkuri;
2494                         this.tlPause();
2495                         this.action.setStatus(object.actionStatus);
2496
2497                         // this.actionQueue.push({
2498                         //      object : object,
2499                         //      callback: callback
2500                         // });
2501                 },
2502                 addExValue: function(eexskill, plus){
2503                         this.exValueHash[eexskill] += plus;
2504                         if(this.exValueHash[eexskill] >= 100){
2505                                 this.exLvHash[eexskill] = 1;
2506                         }
2507                 },
2508                 getExValue: function(eexskill){
2509                         return this.exValueHash[eexskill];
2510                 },
2511                 getExSkill: function(eexskill){
2512                         return this.exLvHash[eexskill];
2513                 },
2514
2515                 setMemory: function(ememory, value){
2516                         this.memoryHash[ememory] = value;
2517                 },
2518                 getMemory: function(ememory){
2519                         return this.memoryHash[ememory];
2520                 },
2521                 damage: function(edamage){
2522                         if(edamage == EDamage.PICOHAN){
2523                                 mangMsg.output(this, EMsg.DAMAGE);
2524                                 this.setFaceImage(EFace.CRY1);
2525                                 this.addYukkuri(-1);
2526                                 //現在の行動パターンから躾対象かセレクトする
2527                         }
2528                 },
2529                 // addKuki: function(){
2530                         // for(var i=0;i<this.kukis.length;i++){
2531                         //      if(this.kukis[i].opacity == 0){
2532                         //              this.kukis[i].opacity = 1.0;
2533                         //              // var miMarisa = new MiMarisa(this.getX(), this.getY());
2534                         //              var miMarisa = new MiMarisa(100, 100);
2535                                         
2536                         //              // console.log(this.imgBody);
2537                         //              // this.imgBody.addChild(miMarisa);
2538                         //              this.kukis[i].addMiYukkuri(miMarisa);
2539                         //              break;
2540                         //      }
2541                         // }
2542                 // },
2543                 addKuki: function(kuki){
2544                         this.kukis.push(kuki);
2545                         var length = this.kukis.length;
2546                         this.formSprite.addChild(kuki,1000 + length,{type:"kuki",scaleValue:this.myScaleY});
2547                 },
2548                 addMiYukkuri: function(index){
2549                         var kuki = this.kukis[index];
2550                         var miYukkuri = new MiMarisa(this, 10, -30);
2551                         // var x = this.getX();
2552                         // var y = this.getY();
2553                         kuki.addMiYukkuri(miYukkuri);
2554
2555                 },
2556                 destruct: function(){
2557
2558                 }
2559         });
2560         var MiYukkuri = enchant.Class.create(ObjSprite, {
2561                 initialize: function(param){
2562                         ObjSprite.call(this,14,14);
2563                         // this.oldX = x;
2564                         // this.oldY = y;
2565
2566                         this.classname = "MiYukkuri";
2567                         this.image = game.assets[EResPath.MIYUKKURI];
2568                         this.x = param.x;
2569                         this.y = param.y;
2570                         this.addX = param.addX;
2571                         this.addY = param.addY;
2572                         this.scaleValue = 1;
2573                         backgroundMap.addChild(this);
2574                         this.anim = {};
2575                         this.anim.cnt = 0;
2576
2577                 },
2578                 setX : function(x){
2579                         this.x = x + this.addX;
2580                 },
2581                 setY : function(y){
2582                         this.y = y + this.addY;
2583                 },
2584                 setOldY: function(){
2585                         this.imgGroup.y = this.oldY;
2586
2587                 },
2588                 animX: function(x){
2589                         this.oldX = this.imgGroup.x;
2590                         this.imgGroup.x -= x;
2591                 },
2592                 animY: function(y){
2593                         this.imgGroup.y = this.oldY;
2594                         // this.oldY = this.imgGroup.y;
2595                         this.imgGroup.y -= y;
2596                 }
2597         }); 
2598         var MiMarisa = enchant.Class.create(MiYukkuri,{
2599                 initialize: function(parentYukkuri, addX, addY){
2600                         var x = parentYukkuri.getX();
2601                         var y = parentYukkuri.getY();
2602                         if(addX === undefined){
2603                                 x += addX;
2604                         }
2605                         if(addY === undefined){
2606                                 y += addY;
2607                         }
2608                         MiYukkuri.call(this, {x:x, y:y,addX:addX, addY:addY});
2609                         this.classname = "MiMarisa";
2610                         this.myCode = "MI_MARISA";
2611                         this.myName = "実まりちゃ";
2612
2613                         // this.classname = "Marisa";
2614                         // this.myCode = "MARISA";
2615                         // this.myName = "実まりさ";
2616
2617                         // this.param = new MarisaParam();
2618                         // this.param.looks = ELooks.GOOD_YUKKURI;
2619                         // this.myName = "実まりちゃ";
2620                         // this.param.range /= 4;
2621
2622                         // this.face = new enchant.Sprite(64, 64);
2623                         // this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2624                         // this.face.x = -CHARA_WIDTH / 2;
2625                         // this.face.y = -CHARA_HEIGHT / 2;
2626
2627                         // this.faceStatus ={};
2628                         // this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2629                         // this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2630                         // this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2631                         // this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2632                         // this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2633                         // this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2634                         // this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2635                         // this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2636                         // this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2637                         // this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2638
2639
2640                         // this.hear = new enchant.Sprite(64, 64);
2641                         // this.hear.image = game.assets[EResPath.MARISA_HEAR];
2642                         // this.hear.x = -CHARA_WIDTH / 2;
2643                         // this.hear.y = -CHARA_HEIGHT / 2;
2644
2645                         // this.okazari = new Okazari(this);
2646
2647                         // this._tweet = new TTweet(this, 148, 64);
2648
2649                         // this.formSprite.addChild(this, 1, {
2650                         //      mainIndexFlg:true,
2651                         //      type : "body",
2652                         //      scaleValue:this.myScaleY
2653                         // });
2654
2655                         // this.formSprite.addChild(this.face,2,{type:"body",scaleValue:this.myScaleY});
2656                         // this.formSprite.addChild(this.hear,3,{type:"body",scaleValue:this.myScaleY});
2657                         // this.formSprite.addChild(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
2658                         // this.formSprite.addChild(this._tweet,6,{type:"tweet",scaleValue:this.myScaleY});
2659                         // this.myScale(this.myScaleX, this.myScaleY)
2660                         // if(this instanceof Player){
2661                         //      this.budge = new enchant.Sprite(16, 16);
2662                         //      this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2663                         //      this.budge.x = -this.getWidth()/2;
2664                         //      this.budge.y = -this.getHeight()/2;
2665                         //      this.budge.scale(this.myScaleX, this.myScaleY);
2666                         //      this.formSprite.addChild(this.budge,5, {type:"budge",scaleValue:this.myScaleY});
2667                         //      this.formSprite.setX(x);
2668                         //      this.formSprite.setY(y);
2669                         // }
2670                         // this.formSprite.setX(x);
2671                         // this.formSprite.setY(y);
2672                         // this.animation();
2673                         // this.action = new Action(this);
2674                         // ctl.addObj(this);
2675                 }
2676
2677         });
2678         var Marisa = enchant.Class.create(Yukkuri,{
2679                 initialize: function(x, y, grow){
2680                         Yukkuri.call(this,x,y, grow);
2681                         this.classname = "Marisa";
2682                         this.myCode = "MARISA";
2683                         this.myName = "まりさ";
2684
2685                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2686                         // var json = net.load("./data/marisa/params.json");
2687                         // this.param = json.root.param;
2688                         this.param = new MarisaParam();
2689                         this.param.looks = ELooks.GOOD_YUKKURI;
2690                         if(this.grow == EGrow.BABY){
2691                                 this.myName = "まりちゃ";
2692                                 this.param.range /= 4;
2693                         }
2694                         else if(this.grow == EGrow.CHILD){
2695                                 this.param.range /= 3;
2696                         }
2697                         else if(this.grow == EGrow.SUBADULT){
2698                                 this.param.range *= 0.8;
2699                         }else{
2700                         }
2701                         this.shadow = new enchant.Sprite(64, 64);
2702                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2703                         this.shadow.x = 0 + this.x;
2704                         this.shadow.y = this.getHeight() / 16 + this.y;
2705
2706                         this._style.zIndex = 5;
2707
2708                         this.face = new enchant.Sprite(64, 64);
2709                         this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2710                         this.face.x = -CHARA_WIDTH / 2;
2711                         this.face.y = -CHARA_HEIGHT / 2;
2712
2713                         this.faceStatus ={};
2714                         this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2715                         this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2716                         this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2717                         this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2718                         this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2719                         this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2720                         this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2721                         this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2722                         this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2723                         this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2724
2725
2726                         this.hear = new enchant.Sprite(64, 64);
2727                         this.hear.image = game.assets[EResPath.MARISA_HEAR];
2728                         this.hear.x = -CHARA_WIDTH / 2;
2729                         this.hear.y = -CHARA_HEIGHT / 2;
2730
2731                         this.okazari = new Okazari(this);
2732
2733                         this.kukis = [];
2734                         this.kukis[0] = new Kuki(this, 0, 0);
2735                         // this.kukis[1] = new Kuki(this, 10, 0);
2736                         // this.kukis[2] = new Kuki(this, 5, 5);
2737                         // this.kukis[3] = new Kuki(this, -5, 5);
2738                         this._tweet = new TTweet(this, 148, 64);
2739
2740                         this.formSprite.addChild(this.shadow,0,{type:"shadow",shadowIndexFlg:true,scaleValue:this.myScaleY});
2741                         this.formSprite.addChild(this, 1, {
2742                                 mainIndexFlg:true,
2743                                 type : "body",
2744                                 scaleValue:this.myScaleY
2745                         });
2746
2747                         this.formSprite.addChild(this.face,2,{type:"body",scaleValue:this.myScaleY});
2748                         this.formSprite.addChild(this.hear,3,{type:"body",scaleValue:this.myScaleY});
2749                         this.formSprite.addChild(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
2750                         this.formSprite.addChild(this._tweet,6,{type:"tweet",scaleValue:this.myScaleY});
2751                         this.formSprite.addChild(this.kukis[0],7,{type:"kuki",scaleValue:this.myScaleY});
2752
2753
2754                         // this.formSprite.addChildAll();
2755                         // App.backgroundMap.addChild(this._tweet);
2756                         // this.imgGroup.addChild(this.shadow);
2757                         // this.imgBody.addChild(this);
2758                         // this.imgBody.addChild(this.face);
2759                         // this.imgBody.addChild(this.hear);
2760                         // this.imgBody.addChild(this.okazari);
2761                         // for(var i=0;i<this.kukis.length;i++){
2762                         //      this.imgBody.addChild(this.kukis[i]);
2763                         //      this.kukis[i].opacity = 0;
2764                         // }
2765                         // this.kuki = ;
2766                         // this.imgBody.addChild(new Kuki(this));
2767                         this.myScale(this.myScaleX, this.myScaleY)
2768                         if(this instanceof Player){
2769                                 this.budge = new enchant.Sprite(16, 16);
2770                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2771                                 this.budge.x = -this.getWidth()/2;
2772                                 this.budge.y = -this.getHeight()/2;
2773                                 this.budge.scale(this.myScaleX, this.myScaleY);
2774                                 this.formSprite.addChild(this.budge,5, {type:"budge",scaleValue:this.myScaleY});
2775                                 this.formSprite.setX(x);
2776                                 this.formSprite.setY(y);
2777                         }
2778                         // this.imgGroup.width = this.getWidth();
2779                         // this.imgGroup.height = this.getHeight();
2780                         // this.imgGroup.addChild(this.imgBody);
2781
2782                         // backgroundMap.addChild(this.imgGroup);
2783                         // this._tweet = new TTweet(148, 64);
2784
2785                         // this.imgGroup.addChild(this._tweet);
2786                         // this.imgGroup.x = x;
2787                         // this.imgGroup.y = y;
2788                         this.formSprite.setX(x);
2789                         this.formSprite.setY(y);
2790                         this.animation();
2791                         this.action = new Action(this);
2792                         ctl.addObj(this);
2793                 }
2794         });
2795         var Player = enchant.Class.create(Marisa,{
2796                 initialize: function(x, y, grow){
2797                         // this.runEnterframe = function(){
2798                         // },
2799                         if(grow === undefined)grow = EGrow.ADULT;
2800                         Marisa.call(this, x, y, grow);
2801                         this.classname = "Player";
2802                         ctl.setPlayer(this);
2803                         // this.removeEventListener('enterframe',this.runEnterframe);
2804                         this.addEventListener('enterframe', function(){
2805
2806                                 if(this.age%10 === 0 && this.age !== 0){
2807                                         // console.log("palyer:" + this.age);
2808                                 }
2809                                 // this.act();
2810                                 ///////////////////////////////////////////////
2811                                 //Action pattern  debug
2812                                 if(game.input.left){
2813                                         // this.changeFace(EResPath.MARISA_FACE_TIRED);
2814                                         // this.moveX(-10);
2815                                         this.direction = EDirection.LEFT;
2816                                 }
2817                                 if(game.input.right){
2818                                         // for(var i=0;i<this.formSprite.spriteArray.length;i++){
2819                                         //      var spr = this.formSprite.spriteArray[i];
2820                                         //      console.log(i+":spry:" + spr.y);
2821                                         // }
2822                                         // this.moveX(10);
2823                                         this.direction = EDirection.RIGHT;
2824                                 }
2825                                 if(game.input.up){
2826                                         this.moveY(-10);
2827                                 }
2828                                 if(game.input.down){
2829                                         this.moveY(10);
2830                                 }
2831
2832                                 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2833                                 ///////////////////////////////////////////////
2834                                 // this.reverse();
2835                                 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2836                                 //      console.log("hit:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.height/2) );
2837                                 // }else{
2838                                 //      console.log("not:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.image.height/2));
2839                                 // }
2840                                 //- Display the circle of search range.
2841                                 // fieldBg.image.clear();
2842                                 // fieldBg.image.context.beginPath();
2843                                 // fieldBg.image.context.fillStyle = '#ff0000';
2844                                 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2845                                 // fieldBg.image.context.fill();
2846                         });
2847                 }
2848         });
2849         var Reimu = enchant.Class.create(Yukkuri,{
2850                 initialize: function(x, y, grow){
2851                         Yukkuri.call(this,x,y, grow);
2852                         this.classname = "Reimu";
2853                         this.myCode = "REIMU";
2854                         this.myName = "れいむ";
2855                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2856                         // var json = net.load("./data/reimu/params.json");
2857                         // this.param = json.root.param;
2858                         this.param = new ReimuParam();
2859                         if(this.grow == EGrow.BABY){
2860                                 this.myName = "れいみゅ";
2861                                 this.param.range /= 4;
2862                         }
2863                         else if(this.grow == EGrow.CHILD){
2864                                 this.param.range /= 3;
2865                         }
2866                         else if(this.grow == EGrow.SUBADULT){
2867                                 this.param.range *= 0.8;
2868                         }
2869                         this.shadow = new enchant.Sprite(64, 64);
2870                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2871                         this.shadow.x = 0 + this.x;
2872                         this.shadow.y = this.getWidth() / 16 + this.x;
2873
2874
2875                         this.face = new enchant.Sprite(64, 64);
2876                         this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2877                         this.face.x = -CHARA_WIDTH / 2;
2878                         this.face.y = -CHARA_HEIGHT / 2;
2879                         this.face._style.zIndex = 0;
2880
2881                         this.faceStatus ={};
2882                         this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2883                         this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2884                         this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2885                         this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2886                         this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2887                         this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2888                         this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2889                         this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2890                         this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2891                         this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2892
2893
2894                         this.hear = new enchant.Sprite(64, 64);
2895                         this.hear.image = game.assets[EResPathReimu.HEAR];
2896                         this.hear.x = -CHARA_WIDTH / 2;
2897                         this.hear.y = -CHARA_HEIGHT / 2;
2898
2899                         this.sub1 = new enchant.Sprite(64, 64);
2900                         this.sub1.image = game.assets[EResPathReimu.SUB1];
2901                         this.sub1.x = -CHARA_WIDTH / 2;
2902                         this.sub1.y = -CHARA_HEIGHT / 2;
2903
2904
2905                         this.okazari = new Okazari(this);
2906                         this.formSprite.addChild(this.shadow,0,{type:"shadow",scaleValue:this.myScaleY});
2907                         this.formSprite.addChild(this, 1, {
2908                                 mainIndexFlg:true,
2909                                 type : "body",
2910                                 scaleValue:this.myScaleY
2911                         });
2912                         this.formSprite.addChild(this.face,2,{type:"body",scaleValue:this.myScaleY});
2913                         this.formSprite.addChild(this.hear,3,{type:"body",scaleValue:this.myScaleY});
2914                         this.formSprite.addChild(this.okazari,4,{type:"body",scaleValue:this.myScaleY,spname:"reimu"});
2915                         this.formSprite.addChild(this.sub1,5,{type:"body",scaleValue:this.myScaleY});
2916                         this._tweet = new TTweet(this, 148, 64);
2917                         this.formSprite.addChild(this._tweet,6,{type:"tweet",scaleValue:this.myScaleY});
2918
2919                         this.myScale(this.myScaleX, this.myScaleY)
2920                         if(this instanceof Player){
2921                                 this.budge = new enchant.Sprite(16, 16);
2922                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2923                                 this.imgBody.addChild(this.budge);
2924                                 this.budge.x -= this.getWidth()/2;
2925                                 this.budge.y -= this.getHeight()/2;
2926                                 this.budge.scale(this.myScaleX, this.myScaleX);
2927                         }
2928
2929                         this.formSprite.setX(x);
2930                         this.formSprite.setY(y);
2931                         this.animation();
2932                         this.action = new Action(this);
2933                         ctl.addObj(this);
2934                         this.exLvHash[EExSkill.KEKKAI] = 1;
2935                         this.exValueHash[EExSkill.KEKKAI] = 100;
2936                 }
2937         });
2938
2939         game.onload = function(){
2940                 def.Food = Food;
2941                 def.Unun = Unun;
2942                 def.Place = Place;
2943                 def.ObjSprite = ObjSprite;
2944                 def.Yukkuri = Yukkuri;
2945                 def.nodeSort = nodeSort;
2946                 mangTouch = new MangTouch(ctl);
2947                 mangMsg = new MangMsg(ctl);
2948                 ctl.setDefined(def);
2949                 backgroundMap.image = game.assets[EResPath.MAP0];
2950                 backgroundMap.loadData(_mapData);
2951                 backgroundMap.collisionData = _collisionData;
2952
2953                 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2954                 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2955                 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2956                 fieldBg.image = fieldSurface;
2957                 fieldBg.x = 0;
2958                 fieldBg.y = 0;
2959
2960                 windowFront.image = windowSurface;
2961                 windowFront.x = 0;
2962                 windowFront.y = 0;
2963                 windowFront.opacity = 0.5;
2964
2965                 windowSurface.context.fillStyle = '#000';
2966                 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2967
2968                 menuSurface.context.fillStyle = '#000';
2969                 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2970                 menuBg.image = menuSurface;
2971                 menuBg.x = EMenuPos.X;
2972                 menuBg.y = EMenuPos.Y;
2973                 backgroundMap.addChild(fieldBg);
2974                 mangIcon = new MangIcon(ctl, menuBg);
2975
2976                 game.rootScene.addChild(backgroundMap);
2977                 // game.rootScene.addChild(windowFront);
2978                 // game.rootScene.addChild(gwindow);
2979                 // var gwindow = new GWindow(ctl, {}, 0, 0, 80, 80);
2980                 game.rootScene.addChild(menuBg);
2981
2982                 // var labelGroup = new LabelGroup();
2983                 mangLabel = new MangLabel(ctl, menuBg);
2984                 // var info = new Label("ゆっくり");
2985                 // info.color = "#ffffff";
2986                 // info.font = "14px 'Times New Roman'";
2987                 // info.x = 4;
2988                 // info.y = GAME_HEIGHT / 2;
2989                 // labelGroup.addChild(info);
2990                 // menuBg.addChild(labelGroup);
2991
2992
2993                 // var food = new def.Food("apple", 200, 250);
2994                 backgroundMap.addChild(foodGroup);
2995                 // backgroundMap.addChild(placeGroup);
2996                 // var mimarisa = new MiMarisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 100, EGrow.FRUIT_BABY);
2997                 var player = new Player(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.ADULT);
2998                 ;
2999                 player.addMiYukkuri(0);
3000                 // var player = new Player(0, 0);
3001                 // console.log(player.getX());
3002                 // player.addKuki();
3003                 // player.addMiYukkuri(mimarisa)
3004                 // player.createKuki();
3005                 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
3006                 
3007                 // new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.ADULT);
3008                 // new Marisa(PALYER_INIT_X + 250, PALYER_INIT_Y + 200, EGrow.ADULT);
3009                 // new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
3010                 // new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
3011                 // new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
3012                 // new Reimu(PALYER_INIT_X + 100, PALYER_INIT_Y + 100, EGrow.ADULT);
3013                 // new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
3014                 // new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);
3015                 // new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
3016                 // new Unun(100, 100);
3017                 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
3018                 var touchX = 0;
3019                 // var input = new Label("<form name='hoge' style='background-color:#ff0000;'>" +
3020                 //              "<input type='text' name='text'>" +
3021                 //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
3022                 //              "</from>");
3023                 // input.y = 0;
3024                 // input.element.innerHTML = "<form name='hoge' style='background-color:#ff0000;'>" +
3025                 //              "<input type='text' name='text'>" +
3026                 //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
3027                 //              "</from>";
3028                 // menuBg.addChild(input);
3029                 // game.rootScene.addChild(input);
3030                 // var inputEvent = new Label('');
3031                 // output.y = 64;
3032                 // game.rootScene.addChild(output);
3033                 // output.onenterframe = function(e) {
3034                 //              output.text = document.hoge.text.value;
3035                 //      };
3036                 // };
3037                 // enchant.Node.GAddEvent = function(){
3038                 // }
3039                 var popupStatus = null;
3040                 var testFlg = false;
3041                 var iconText = [];
3042                 game._element.addEventListener('mousemove', function (e) {
3043                         var mang = mangTouch.get(ctl.getCurrentCommand());
3044                         if(EMenuPos.X < e.layerX){
3045                                 var ex = e.layerX - EMenuPos.X;
3046                                 var ey = e.layerY;
3047                                 var hitFlg = false;
3048                                 for(var i=0;i<mangIcon.cmdIcons.length;i++){
3049                                         var icon = mangIcon.cmdIcons[i];
3050                                         if(icon.x <= ex && ex <= (icon.x + ICON_WIDTH)
3051                                                 && icon.y <= ey && ey <= (icon.y + ICON_HEIGHT)
3052                                                 ){
3053                                                 hitFlg = true;
3054                                                 if(popupStatus !== i){
3055                                                         ctl.popup.renew(game.rootScene, EMenuPos.X + 5, e.layerY + ICON_HEIGHT / 2, 80, 80);
3056                                                         ctl.popup.setText(icon.text);
3057                                                         popupStatus = i;
3058                                                         break;
3059                                                 }
3060                                         }
3061                                 }
3062
3063                                 if(hitFlg){
3064                                         ctl.popup.opacity = 0.9;
3065                                         ctl.popup.drawText();
3066                                 }
3067                                 else {
3068                                         ctl.popup.opacity = 0;
3069                                 }
3070                                 // console.log(e.layerX + ":" + e.layerY);
3071                         }
3072                 });
3073                 // enchant.Core.instance._element.addEventListener('mousemove', function(e) {
3074
3075                 // game.rootScene.addEventListener('mousemove', function (e) {
3076                 //      console.log("mmmmmmmmm");
3077                 // });
3078
3079
3080                 game.rootScene.addEventListener('touchstart', function (e) {
3081                         game.touched = true;
3082                         var mang = mangTouch.get(ctl.getCurrentCommand());
3083                         mang.touchstart(e);
3084                 });
3085                 game.rootScene.addEventListener('touchmove', function (e) {
3086                         var mang = mangTouch.get(ctl.getCurrentCommand());
3087                         mang.touchmove(e);
3088                 });
3089                 game.rootScene.addEventListener('touchend', function (e) {
3090                         var mang = mangTouch.get(ctl.getCurrentCommand());
3091                         mang.touchend(e);
3092                         game.touched = false;
3093                 });
3094
3095
3096                 game.rootScene.addEventListener('enterframe', function(e){
3097                         //main frame
3098                         mangLabel.draw(player);
3099                         if(this.age%BASE_FPS == 0 ){
3100                                 ctl.calcTime();
3101                         }
3102                         ctl.time += TIME_SPEED;
3103                 });
3104                 this.addEventListener('enterframe', function(){
3105                         //The priority processing of display instead of z-index
3106
3107                         backgroundMap.childNodes.sort(nodeSort);
3108                 });
3109
3110         };
3111         game.start();
3112 };
3113
3114