OSDN Git Service

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