OSDN Git Service

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