OSDN Git Service

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