OSDN Git Service

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