OSDN Git Service

add placetree command and yukkuri sky bug update
[yukkurioverwint/YukkuriOverwinter.git] / main.js
1 enchant();
2 //////////////////////////////////////
3 //global
4 var ctl = null;
5 var mangIcon = null;
6 var mangTouch = null;
7 var mangLabel = null;
8 var mangMsg = null;
9 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
10 var net = new Net();
11 //////////////////////////////////////
12 //define
13 //////////////////////////////////////
14 var PALYER_INIT_X = 100;
15 var PALYER_INIT_Y = 100;
16 var CHARA_WIDTH = 64;
17 var CHARA_HEIGHT = 64;
18 var GAME_WIDTH = 800;
19 var GAME_HEIGHT = 600;
20 var FPS = 20;
21 var BASE_FPS = 20;
22 var HUNGRY_MAX = 100;
23 var MIN = BASE_FPS;
24 var HOUR = MIN * 60;
25 // var DAY = HOUR * 24;
26 var DAY = HOUR ;
27
28 var EResPath = {
29         YUKKURI_BASE : './data/yukkuri_base.png',
30         YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
31         YUKKURI_UNUN : './data/unun.png',
32         YUKKURI_SHADOW : './data/shadow.png',
33         MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
34         MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
35         MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
36         MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
37         MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
38         MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
39         MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
40         MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
41         MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
42         MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
43         MARISA_HEAR : './data/marisa/hear1.png',
44         OBJECT : './data/object.png',
45         MAP0 : './data/map0.png',
46         COMMAND : './data/command.png',
47         OKAZARI : './data/okazari.png',
48         PLACE_TREE : './data/system/place_tree.png',
49         // PLACE_TREE : './data/system/rapture.png',
50 };
51 var EFace = {
52         NORMAL:0,
53         TIRED:1,
54         ANGRY:2,
55         CRY1:3,
56         CRY2:4,
57         EAT1:5,
58         EAT2:6,
59         HAPPY1:7,
60         HAPPY2:8,
61         SLEEP:9,
62 };
63 var EBody = {
64         NORMAL: 0,
65         DEAD: 1,
66 };
67
68 var ECommand = {
69         WORLD_CURSOR: 0,
70         WORLD_TARGET: 1,
71         WORLD_APPLE: 2,
72         WORLD_PLACE: 3,
73 };
74
75 var EMenuPos = {
76         X : 600,
77         Y : 0,
78         WIDTH : 200,
79         HEIGHT : GAME_HEIGHT,
80 };
81 var EFieldPos = {
82         X : 0,
83         Y : 0,
84         WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
85         HEIGHT: GAME_HEIGHT,
86 };
87 var EAction = {
88         WAIT : 0,
89         HUNT : 3,
90         THINK : 4,
91         WALK : 5,
92         DEAD: 6,
93         EAT_START : 8,
94         EAT_WAIT : 9,
95         MOVE_TO_EAT_START: 10,
96         MOVE_TO_EAT_UNDERWAY: 11,
97         MOVE_TO_COMMAND: 12,
98         UNUN_START : 13,
99         UNUN_WAIT : 14,
100         UNUN_SMELL_START : 15,
101         UNUN_SMELL_WAIT : 16,
102         SLEEP_START : 17,
103         SLEEP_WAIT : 18,
104         COMMUNICATE_START : 19,
105         COMMUNICATE_WAIT: 20,
106         COMMUNICATE_RECV: 21,
107         NONE: 9999
108 };
109 var EDirection = {
110         LEFT : 0,
111         RIGHT: 1,
112 };
113 var EMsg = {
114         WALK: 0,
115         SLEEP: 1,
116         EAT: 2,
117         GET_UP: 3,
118         DEAD: 4,
119         UNUN: 5,
120         UNUN_END: 6,
121         UNUN_SMELL_START: 7,
122         SEARCH_FOOD: 8,
123         EAT_FAILED: 9,
124         GREETING: 10,
125 };
126 var EWalkAnimation = {
127         START: 0,
128         END: 1,
129 };
130 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
131         var params = {
132                 x: function() {
133                         return this.x + x;
134                 },
135                 y: function() {
136                         return this.y + y;
137                 },
138                 time: time,
139                 easing: easing
140         };
141         //-Event register [onactionstart,onactiontick,onactionend]
142         if(eventFunctions !== undefined){
143                 for(var key in eventFunctions){
144                         params[key] = eventFunctions[key];
145                 }
146         }
147         return this.tween(params);
148 };
149
150
151
152 include("./lang/ja.js");
153 window.onload = function(){
154
155         //init game
156         var def = new Object();
157         var foodGroup = new Group();
158         // var placeGroup = new Group();
159         var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
160         var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
161         var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
162         var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
163         var game = new Game(GAME_WIDTH, GAME_HEIGHT);
164         game.fps = FPS;
165         var _loadArr = [];
166         var i=0;
167         for(var _v in EResPath){
168                 _loadArr[i] = EResPath[_v];
169                 i++;
170         }
171         game.preload(_loadArr);
172         var MapGroup = enchant.Class.mixClasses(Map, Group,true);
173         var backgroundMap = new MapGroup(16, 16);
174         include("./class.js");
175         include("./ctrl.js");
176         ctl = new Ctrl();
177         ctl.init(game);
178         ctl.setBackgroundMap(backgroundMap);
179         var Action = enchant.Class.create({
180                 initialize: function (yukkuri){
181                         this.status = EAction.THINK;
182                         this.yukkuri = yukkuri;
183                         this.isMoving = false;
184                         this.targetNode = null;
185                 },
186                 getStatus: function(){
187                         return this.status;
188                 },
189                 setStatus: function(eaction){
190                         this.status = eaction;
191                 },
192                 observe: function(){
193                         if(this.yukkuri.isDead()){
194                                 this.status = EAction.DEAD;
195                         }
196                         // else if(this.yukkuri.isSleep()){
197                         //      this.status = EAction.SLEEP;
198                         // }
199
200                 },
201                 act : function(){
202                         // console.log("status:" + this.status + ":" + this.yukkuri.id);
203
204                         this.observe();
205                         switch(this.status){
206                                 case EAction.WAIT:
207
208                                 break;
209                                 case EAction.THINK:
210                                         if(this.yukkuri.age%2 === 0){
211                                                 if(this.yukkuri.isSleep()){
212                                                         this.setStatus(EAction.SLEEP_START);
213                                                 }
214                                                 else if(this.yukkuri.getUnun() >= 80){
215                                                         this.setStatus(EAction.UNUN_START);
216                                                 }else{
217                                                         // this.yukkuri.param.yukkuri -= 1;
218                                                         this.yukkuri.changeFace();
219                                                         this.search();
220                                                 }
221
222                                         }
223                                 break;
224                                 case EAction.MOVE_TO_EAT_START:
225                                         this.move_to_eat_start();
226                                 break;
227                                 case EAction.MOVE_TO_EAT_UNDERWAY:
228                                 break;
229                                 //Random Walk
230                                 case EAction.WALK:
231                                         this.walk(0);
232                                 break;
233                                 case EAction.SLEEP_START:
234                                         this.sleep_start();
235                                 break;
236                                 case EAction.SLEEP_WAIT:
237                                 break;
238                                 case EAction.DEAD:
239                                         this.dead();
240                                 break;
241                                 case EAction.EAT_START:
242                                         this.eat_start();
243                                 break;
244                                 case EAction.EAT_WAIT:
245                                 break;
246                                 case EAction.UNUN_START:
247                                         this.unun_start();
248                                 break;
249                                 case EAction.UNUN_WAIT:
250                                 break;
251                                 case EAction.MOVE_TO_COMMAND:
252                                         this.move_to_command();
253                                 break;
254                                 case EAction.UNUN_SMELL_START:
255                                         this.unun_smell_start();
256                                 break;
257                                 case EAction.COMMUNICATE_START:
258                                         this.communicate_start();
259                                 break;
260                                 case EAction.COMMUNICATE_WAIT:
261                                 break;
262                                 case EAction.COMMUNICATE_RECV:
263                                 break;
264
265                         }
266                         this.yukkuri.reverse();
267                 },
268
269                 move_to_eat_start : function(){
270                         new MoveToEatEvent({
271                                 "type": 'food',
272                                 "targetNode": this.targetNode,
273                                 "action": this,
274                                 "myYukkuri": this.yukkuri
275                         });
276                 },
277                 walkNew: function(){
278
279                 },
280                 walk : function(retryCounter){
281                         if(retryCounter > 15){
282                                 retryCounter = 0;
283                                 this.status = EAction.NONE;
284                                 console.log("retryCount over");
285                                 return;
286                         }
287                         if(this.yukkuri.imgGroup.tl.queue.length === 0){
288                                 var frame = 200;
289                                 if(this.isMoving){
290                                         this.isMoving = false;
291                                         this.status = EAction.THINK;
292                                         this.yukkuri.vx = 0;
293                                         this.yukkuri.vy = 0;
294                                 }else{
295                                         var xpos = 150 + rand(40) - (retryCounter * 10);
296                                         var ypos = 150 + rand(40) - (retryCounter * 10);
297                                         if(rand(8) === 0){
298                                                 this.yukkuri.vx = 0;
299                                                 this.yukkuri.vy = -ypos;
300                                         }
301                                         else if(rand(8) == 1){
302                                                 this.yukkuri.vx = xpos;
303                                                 this.yukkuri.vy = -ypos;
304                                                 this.yukkuri.direction = EDirection.RIGHT;
305                                         }
306                                         else if(rand(8) == 2){
307                                                 this.yukkuri.vx = xpos;
308                                                 this.yukkuri.vy = 0;
309                                                 this.yukkuri.direction = EDirection.RIGHT;
310                                         }
311                                         else if(rand(8) == 3){
312                                                 this.yukkuri.vx = xpos;
313                                                 this.yukkuri.vy = ypos;
314                                                 this.yukkuri.direction = EDirection.RIGHT;
315                                         }
316                                         else if(rand(8) == 4){
317                                                 this.yukkuri.vx = 0;
318                                                 this.yukkuri.vy = ypos;
319                                         }
320                                         else if(rand(8) == 5){
321                                                 this.yukkuri.vx = -xpos;
322                                                 this.yukkuri.vy = ypos;
323                                                 this.yukkuri.direction = EDirection.LEFT;
324                                         }
325                                         else if(rand(8) == 6){
326                                                 this.yukkuri.vx = -xpos;
327                                                 this.yukkuri.vy = 0;
328                                                 this.yukkuri.direction = EDirection.LEFT;
329                                         }
330                                         else if(rand(8) == 7){
331                                                 this.yukkuri.vx = -xpos;
332                                                 this.yukkuri.vy = -ypos;
333                                                 this.yukkuri.direction = EDirection.LEFT;
334                                         }
335                                         if (this.yukkuri.vx || this.yukkuri.vy) {
336                                                 var map = ctl.backgroundMap;
337                                                 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
338                                                 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
339                                                 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
340                                                 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
341                                                 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
342                                                         // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
343                                                         // console.log("X:" + this.yukkuri.moveX);
344                                                         // console.log("Y:" + this.yukkuri.moveY);
345                                                         this.isMoving = true;
346                                                         this.yukkuri.reverse();
347                                                         this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
348                                                         mangMsg.output(this.yukkuri,EMsg.WALK);
349                                                         //うんうんくさい対策
350                                                         this.targetNode = null;
351                                                 }else{
352                                                         // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
353                                                         this.walk(retryCounter+1);
354                                                 }
355                                         }
356                                 }
357                         }
358                 },
359                 sleep_start: function(){
360                         new SleepEvent({
361                                 "action": this,
362                                 "myYukkuri": this.yukkuri
363                         });
364                 },
365                 dead : function(){
366                         console.log("dead");
367                         mangMsg.output(this.yukkuri, EMsg.DEAD);
368                         this.yukkuri.tlPause();
369                         this.yukkuri.setBodyImage(EBody.DEAD);
370                 },
371                 eat_start: function(){
372                         new EatEvent({
373                                 "type": 'eat',
374                                 "targetNode": this.targetNode,
375                                 "action": this,
376                                 "myYukkuri": this.yukkuri
377                         });
378
379                 },
380                 unun_start: function(){
381                         new UnunEvent({
382                                 "action": this,
383                                 "myYukkuri": this.yukkuri
384                         });
385                 },
386                 unun_smell_start: function(){
387                         new UnunSmellEvent({
388                                 "action": this,
389                                 "myYukkuri": this.yukkuri
390                         });
391                 },
392                 communicate_start:function(){
393                         new ComFirstSendEvent({
394                                 "type": 'greeting',
395                                 "targetNode": this.targetNode,
396                                 "action": this,
397                                 "myYukkuri": this.yukkuri
398                         });
399                 },
400                 move_to_command: function(){
401
402                 },
403                 search : function(){
404                         var nodes = ctl.getObjs();
405                         l = nodes.length;
406                         var ununFlg = false;
407
408                         for (var key in nodes) {
409                                 var node = nodes[key];
410                                 if(this.yukkuri.id === node.id)continue;
411                                 if (!ununFlg
412                                         && node instanceof Unun
413                                         && !(this.targetNode instanceof Unun)
414                                         && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
415                                         ununFlg = true;
416                                         this.targetNode = node;
417                                         this.setStatus(EAction.UNUN_SMELL_START);
418                                         return;
419                                 }
420                                 else if (node instanceof Food) {
421                                         if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
422
423                                                 //A yukkuri to go to the food area
424                                                 this.targetNode = node;
425                                                 this.setStatus(EAction.MOVE_TO_EAT_START);
426
427                                                 return;
428                                         }else{
429                                                 //not hunbry or not food.
430                                         }
431                                 }
432                                 else if(node instanceof Yukkuri){
433                                         if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
434                                                 this.targetNode = node;
435                                                 this.setStatus(EAction.COMMUNICATE_START);
436                                                 return;
437                                         }
438                                 }
439                         }
440                         this.status =  EAction.WALK;
441                 }
442         });
443         var Event = enchant.Class.create({
444                 initialize: function (_data){
445                         this.progress = null;
446                 },
447                 setProgress: function(progress){
448                         this.progress = progress;
449                 },
450                 onactionstart:function(self){
451                         return function(e){
452                                 if(typeof e === "undefined")return;
453                         };
454                 },
455                 onactiontick:function(self){
456                         return function(e){
457                                 if(typeof e === "undefined")return;
458                         };
459                 },
460                 onactionend:function(self){
461                         return function(e){
462                                 if(typeof e === "undefined")return;
463                         };
464                 }
465         });
466         var WalkEvent = enchant.Class.create(Event,{
467                 initialize: function (_data){
468                         this.data = _data;
469                         this.yukkuri = _data.myYukkuri;
470                         this.action = _data.action;
471
472                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
473                         this.action.setStatus(EAction.SLEEP_WAIT);
474                         this.yukkuri.setFaceImage(EFace.SLEEP);
475                         this.yukkuri.tlPause();
476                         var self = this;
477                         this.yukkuri.addEventListener('enterframe', function() {
478                                 var yukkuri = self.yukkuri;
479                                 self.run();
480                         });
481                 },
482                 run : function(){
483
484                 }
485         });
486         var SleepEvent = enchant.Class.create(Event,{
487                 initialize: function (_data){
488                         this.data = _data;
489                         this.yukkuri = _data.myYukkuri;
490                         this.action = _data.action;
491
492                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
493                         this.action.setStatus(EAction.SLEEP_WAIT);
494                         this.yukkuri.setFaceImage(EFace.SLEEP);
495                         this.yukkuri.tlPause();
496                         var sec = FPS * 3;
497                         var self = this;
498                         this.yukkuri.addEventListener('enterframe', function() {
499                                 var yukkuri = self.yukkuri;
500                                 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
501                                 if(yukkuri.param.sleep <= 0){
502                                         yukkuri.param.sleep = 0;
503                                         this.removeEventListener("enterframe",arguments.callee);
504                                         mangMsg.output(self.yukkuri, EMsg.GET_UP);
505                                         yukkuri.setFaceImage(EFace.NORMAL);
506                                         yukkuri.tlResume();
507                                         // self.action.setStatus(EAction.WAIT);
508                                         self.action.setStatus(EAction.THINK);
509                                 }
510                         });
511                 }
512         });
513
514         var UnunEvent = enchant.Class.create(Event,{
515                 initialize: function (_data){
516                         this.data = _data;
517                         this.yukkuri = _data.myYukkuri;
518                         this.action = _data.action;
519                         this.action.setStatus(EAction.UNUN_WAIT);
520                         mangMsg.output(this.yukkuri, EMsg.UNUN);
521                         this.yukkuri.setFaceImage(EFace.HAPPY2);
522                         var sec = FPS * 3;
523
524                         this.yukkuri.wait(sec, {
525                                 "onactionstart": this.onactionstart(this),
526                                 "onactiontick": this.onactiontick(this),
527                                 "onactionend": this.onactionend(this)
528                         });
529                 },
530                 onactionstart:function(self){
531                         return function(e){
532                                 if(typeof e === "undefined")return;
533                         };
534                 },
535                 onactiontick:function(self){
536                         return function(e){
537                                 if(typeof e === "undefined")return;
538                         };
539                 },
540                 onactionend:function(self){
541                         return function(e){
542                                 if(typeof e === "undefined")return;
543                                 self.yukkuri.unun();
544                                 self.action.setStatus(EAction.WAIT);
545                                 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
546                                 new WaitEvent({
547                                         "waitframe": FPS * 1.5,
548                                         "action": self.action,
549                                         "myYukkuri": self.yukkuri
550                                 });
551                         };
552                 }
553         });
554         var WaitEvent = enchant.Class.create(Event,{
555                 initialize: function (_data){
556                         this.data = _data;
557                         this.yukkuri = _data.myYukkuri;
558                         this.action = _data.action;
559                         this.waitframe = _data.waitframe;
560                         this.yukkuri.wait(this.waitframe, {
561                                 "onactionstart": this.onactionstart(this),
562                                 "onactiontick": this.onactiontick(this),
563                                 "onactionend": this.onactionend(this)
564                         });
565                 },
566                 onactionend:function(self){
567                         return function(e){
568                                 if(typeof e === "undefined")return;
569                                 self.action.setStatus(EAction.THINK);
570                         };
571                 }
572         });
573         var UnunSmellEvent = enchant.Class.create(Event,{
574                 initialize: function (_data){
575                         this.data = _data;
576                         this.yukkuri = _data.myYukkuri;
577                         this.action = _data.action;
578                         this.action.setStatus(EAction.UNUN_SMELL_WAIT);
579                         mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
580                         this.yukkuri.setFaceImage(EFace.CRY1);
581                         var sec = FPS * 3;
582                         this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
583                         this.yukkuri.wait(sec, {
584                                 "onactionstart": this.onactionstart(this),
585                                 "onactiontick": this.onactiontick(this),
586                                 "onactionend": this.onactionend(this)
587                         });
588                 },
589                 onactionend:function(self){
590                         return function(e){
591                                 if(typeof e === "undefined")return;
592                                 self.action.setStatus(EAction.THINK);
593                         };
594                 }
595         });
596
597         var EatEvent = enchant.Class.create(Event,{
598                 initialize: function (_data){
599                         this.data = _data;
600                         this.yukkuri = _data.myYukkuri;
601                         this.food = _data.targetNode;
602                         this.action = _data.action;
603                         this.action.setStatus(EAction.EAT_WAIT);
604
605
606                         var sec = BASE_FPS * 3;
607                         if(this.yukkuri.eat(this.food)){
608                                 mangMsg.output(this.yukkuri, EMsg.EAT);
609                                 this.yukkuri.setFaceImage(EFace.EAT2);
610                         }else{
611                                 sec = BASE_FPS * 6;
612                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
613                                 this.yukkuri.setFaceImage(EFace.CRY2);
614                         }
615                         this.yukkuri.wait(sec, {
616                                 "onactionend": this.onactionend(this)
617                         });
618                 },
619                 onactionend:function(self){
620                         return function(e){
621                                 if(typeof e === "undefined")return;
622                                 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
623                                         self.action.setStatus(EAction.THINK);
624                                         self.yukkuri.setFaceImage(EFace.NORMAL);
625                                 }else{
626                                         self.action.setStatus(EAction.EAT_START);
627                                 }
628                         };
629                 }
630         });
631         /**
632          * Move Event
633          * -When yukkuri find Food.
634          * @param  _data
635          * type: "food"
636          * targetNode: enchant.Node
637          * action:Action
638          * myYukkuri:Yukkuri
639          */
640         var MoveToEatEvent = enchant.Class.create(Event,{
641                 initialize: function (_data){
642                         this.data = _data;
643                         this.yukkuri = this.data.myYukkuri;
644                         this.action = this.data.action;
645
646                         var yukkuri = this.yukkuri;
647                         var node = this.data.targetNode;
648                         //food distance
649                         if(this.data.type == "food"){
650                                 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
651                                 yukkuri.vx = node.x - yukkuri.getX();
652                                 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
653                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
654                                 var frame = distance + distance/5 + 1;
655                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
656                                 yukkuri.reverse();
657
658                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
659                                         "onactionstart": this.onactionstart(this),
660                                         "onactiontick": this.onactiontick(this),
661                                         "onactionend": this.onactionend(this)
662                                 });
663                         }
664                 },
665                 onactionstart:function(self){
666                         return function(e){
667                                 if(typeof e === "undefined")return;
668                                 self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
669                         };
670                 },
671                 onactiontick:function(self){
672                         return function(e){
673                                 if(typeof e === "undefined")return;
674                         };
675                 },
676                 onactionend:function(self){
677                         return function(e){
678                                 if(typeof e === "undefined")return;
679                                 self.action.setStatus(EAction.EAT_START);
680                         };
681                 }
682         });
683         var MoveCommandEvent = enchant.Class.create(Event,{
684                 initialize: function (_data){
685                         this.data = _data;
686                         this.yukkuri = this.data.myYukkuri;
687                         this.action = this.data.action;
688                         this.vx = this.data.vx;
689                         this.vy = this.data.vy;
690
691                         var yukkuri = this.yukkuri;
692                         this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
693                         yukkuri.vx = node.x - yukkuri.getX();
694                         yukkuri.vy = node.y - yukkuri.getY();
695                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
696                         var frame = distance + 1;
697                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
698                                 "onactionstart": this.onactionstart(this),
699                                 "onactiontick": this.onactiontick(this),
700                                 "onactionend": this.onactionend(this)
701                         });
702                 },
703                 onactionstart:function(self){
704                         return function(e){
705                                 if(typeof e === "undefined")return;
706                         };
707                 },
708                 onactiontick:function(self){
709                         return function(e){
710                                 if(typeof e === "undefined")return;
711                         };
712                 },
713                 onactionend:function(self){
714                         return function(e){
715                                 if(typeof e === "undefined")return;
716                                 self.action.setStatus(EAction.THINK);
717                         };
718                 }
719         });
720         /**
721          * First contact to send communication .
722          */
723         var ComFirstSendEvent = enchant.Class.create(Event,{
724                 initialize: function (_data){
725                         this.data = _data;
726                         this.yukkuri = _data.myYukkuri;
727                         this.targetYukkuri = _data.targetNode;
728                         this.action = _data.action;
729                         this.action.setStatus(EAction.COMMUNICATE_WAIT);
730                         this.setProgress("start");
731                         mangMsg.output(this.yukkuri, EMsg.GREETING);
732                         // this.targetYukkuri.recvCommunication(this.yukkuri, this);
733
734                         this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
735                         this.targetYukkuri.tlPause();
736                         this.yukkuri.tlPause();
737                         this.yukkuri.syncDirection(this.targetYukkuri);
738
739                         this.yukkuri.addAddress(this.targetYukkuri);
740                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
741
742                         var sec = BASE_FPS * 2;
743                         this.yukkuri.wait(sec, {
744                                 "onactiontick": this.onactiontick(this),
745                                 "onactionend": this.onactionend(this)
746                         });
747                 },
748                 onactiontick:function(self){
749                         return function(e){
750                                 if(typeof e === "undefined")return;
751                                 self.setProgress("tick");
752                         };
753                 },
754                 onactionend:function(self){
755                         return function(e){
756                                 if(typeof e === "undefined")return;
757                                 self.setProgress("end");
758                                 new ComFirstRecvEvent({
759                                         "type": 'greeting',
760                                         "targetNode": self.yukkuri,
761                                         "action": self.targetYukkuri.action,
762                                         "myYukkuri": self.targetYukkuri
763                                 });
764
765                                 // self.targetYukkuri.recvCommunication(self.yukkuri, self);
766                         };
767                 }
768         });
769         var ComFirstRecvEvent = enchant.Class.create(Event,{
770                 initialize: function (_data){
771                         this.data = _data;
772                         this.yukkuri = _data.myYukkuri;
773                         this.targetYukkuri = _data.targetNode;
774                         this.action = _data.action;
775                         this.setProgress("start");
776                         mangMsg.output(this.yukkuri, EMsg.GREETING);
777                         this.yukkuri.addAddress(this.targetYukkuri);
778                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
779
780                         var sec = BASE_FPS * 2;
781                         this.yukkuri.wait(sec, {
782                                 "onactiontick": this.onactiontick(this),
783                                 "onactionend": this.onactionend(this)
784                         });
785                 },
786                 onactiontick:function(self){
787                         return function(e){
788                                 if(typeof e === "undefined")return;
789                                 self.setProgress("tick");
790                         };
791                 },
792                 onactionend:function(self){
793                         return function(e){
794                                 if(typeof e === "undefined")return;
795                                 self.setProgress("end");
796                                 self.action.setStatus(EAction.THINK);
797
798                                 self.yukkuri.action.setStatus(EAction.THINK);
799                                 self.yukkuri.animation();
800                                 self.targetYukkuri.action.setStatus(EAction.THINK);
801                                 self.targetYukkuri.animation();
802                                 // self.targetYukkuri.recvCommunication(self.yukkuri, self);
803                         };
804                 }
805         });
806
807
808         var ObjSprite = enchant.Class.create(enchant.Sprite,{
809                 initialize: function (w, h){
810                         enchant.Sprite.call(this, w, h);
811                         this.id = guid();
812                         ctl.addObj(this);
813                 },
814                 removeAll: function(){
815                         this.remove();
816                         ctl.removeObj(this);
817                 }
818         });
819
820         var Food = enchant.Class.create(ObjSprite,{
821                 initialize: function (type, x, y){
822                         this.classname = "Food";
823                         ObjSprite.call(this,16,16);
824                         this.image = game.assets[EResPath.OBJECT];
825                         this.frame = 15;
826                         this.x = x;
827                         this.y = y;
828                         //一つにつきgiveの値分、hunguryを減少させられる
829                         this.give = 40;
830                         this.amount = 3;
831                         foodGroup.addChild(this);
832                         this.addEventListener('enterframe', function(){
833                                 if(this.amount <= 0){
834                                         this.removeAll();
835                                 }
836                         });
837                 },
838                 getAmount: function(){
839                         return this.amount;
840                 },
841                 getGive: function(){
842                         return this.give;
843                 }
844         });
845         var Place= enchant.Class.create(ObjSprite,{
846                 initialize: function (type, x, y){
847                         ObjSprite.call(this,128,128);
848                         this.image = game.assets[EResPath.PLACE_TREE];
849                         this.x = x - this.width / 2;
850                         this.y = y - this.height / 2;
851                         // placeGroup.addChild(this);
852                         backgroundMap.addChild(this);
853
854                         // this.addEventListener('enterframe', function(){
855
856
857                         //      if(this.age%10 === 0 && this.age !== 0){
858                         //              console.log("x/y " + this.x + "/" + this.y);
859                         //      }
860                         //      if(game.input.left){
861                         //              this.x -= 10;;
862                         //      }
863                         //      if(game.input.right){
864                         //              this.x += 10;;
865                         //      }
866                         //      if(game.input.up){
867                         //              this.y -= 10;;
868                         //      }
869                         //      if(game.input.down){
870                         //              this.y += 10;;
871                         //      }
872                         // });
873
874                 }
875         });
876         var Unun = enchant.Class.create(ObjSprite,{
877                 initialize: function (x, y){
878                         this.classname = "Unun";
879                         ObjSprite.call(this,32,32);
880                         this.image = game.assets[EResPath.YUKKURI_UNUN];
881                         this.x = x;
882                         this.y = y;
883                         backgroundMap.addChild(this);
884                 }
885         });
886         var Okazari = enchant.Class.create(enchant.Sprite,{
887                 initialize: function(){
888                         this.classname = "Okazari";
889                         enchant.Sprite.call(this, 64, 64);
890                         this.image = game.assets[EResPath.OKAZARI];
891                         this.x = -CHARA_WIDTH / 2;
892                         this.y = -12 - CHARA_HEIGHT / 2;
893                 }
894         });
895         var Address = enchant.Class.create({
896                 initialize: function(yukkuri){
897                         this.friendlyLv = 1;
898                         this.yukkuri = yukkuri;
899                         this.isGreeting = false;
900                         this.greetingWaitFrame = 0;
901                 }
902         });
903
904         var Yukkuri = enchant.Class.create(ObjSprite,{
905                 initialize: function(x, y){
906                         ObjSprite.call(this, 64, 64);
907                         this.classname = "Yukkuri";
908                         this.addressBook = {};
909                         this.imgGroup = new SpriteGroup();
910                         this.imgBody = new SpriteGroup();
911                         this.imgGroup.id = guid();
912                         this.imgBody.id = guid();
913                         this.x = -CHARA_WIDTH / 2;
914                         this.y = -CHARA_HEIGHT / 2;
915                         this.vx = 0;
916                         this.vy = 0;
917                         this.image = game.assets[EResPath.YUKKURI_BASE];
918                         this.direction = EDirection.RIGHT;
919                         this.addEventListener('enterframe', this.runEnterframe);
920                         this.bodyStatus ={};
921                         this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
922                         this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
923                         this.walkAnimationStatus = EWalkAnimation.END;
924                 },
925                 runEnterframe:function(){
926                         this.act();
927                         if(this.isDead())return;
928                         this.runYukkuri();
929                         this.runHungry();
930                         this.runUnun();
931                         this.runSleep();
932                         this.runAddress();
933                 },
934                 reverse:function(){
935                         if(this.direction == EDirection.RIGHT){
936                                 this.imgBody.scaleX = 1;
937                         }
938                         else if(this.direction == EDirection.LEFT){
939                                 this.imgBody.scaleX = -1;
940                         }
941                 },
942                 tweet:function(text){
943                         this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
944                 },
945                 moveTo:function(x, y, time){
946                         this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
947                 },
948                 moveBy:function(x, y, time, eventFunctions){
949                         var self = this;
950                         var params = {
951                                 x: function() {
952                                         return self.imgGroup.x + x;
953                                 },
954                                 y: function() {
955                                         return self.imgGroup.y + y;
956                                 },
957                                 time: time,
958                                 easing: enchant.Easing.SIN_EASEINOUT
959                         };
960                         //-Event register [onactionstart,onactiontick,onactionend]
961                         if(eventFunctions !== undefined){
962                                 for(var key in eventFunctions){
963                                         params[key] = eventFunctions[key];
964                                 }
965                         }
966                         return this.imgGroup.tl.tween(params);
967                 },
968                 wait:function(frame, eventFunctions){
969                         this.moveBy(0,1,frame,eventFunctions);
970                 },
971                 act: function(){
972                         this.action.act();
973                 },
974                 animation: function(){
975                         if(this.walkAnimationStatus == EWalkAnimation.END){
976                                 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
977                                         "onactionstart": function(e){
978                                                 this.walkAnimationStatus = EWalkAnimation.START;
979                                         }
980                                 })
981                                 .moveByEx(0, 5, 10, enchant.Easing.SWING,
982                                 {
983                                         "onactionend": function(e){
984                                                 this.walkAnimationStatus = EWalkAnimation.END;
985                                         }
986                                 }).loop();
987
988                         }else{
989                                 this.imgBody.tl.loop();
990                         }
991                         // this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING)
992                         // this.imgBody.tl.moveByEx(0, 5, 10, enchant.Easing.SWING);
993                         // this.imgBody.tl.loop();
994                         // this.moveBy(0, -5, 10).moveBy(0, 5, 10).loop();
995
996                 },
997                 getWidth: function(){
998                         return this.width;
999                 },
1000                 getHeight: function(){
1001                         return this.height;
1002                 },
1003                 getX: function(){
1004                         return this.imgGroup.x;
1005                 },
1006                 getY: function(){
1007                         return this.imgGroup.y;
1008                 },
1009                 moveX: function(x){
1010                         this.imgGroup.x += x;
1011                         // this.x += x;
1012                         // this.shadow.x += x;
1013                         // this._tweet.x += x;
1014                 },
1015                 moveY: function(y){
1016                         this.imgGroup.y += y;
1017                         // this.y += y;
1018                         // this.shadow.y += y;
1019                         // this._tweet.y += y;
1020                 },
1021                 // changeFace: function(erespath){
1022                 //      this.face.image = game.assets[erespath];
1023                 // },
1024                 loadParamsXML: function(url){
1025                         var http = new JKL.ParseXML( url );
1026                         return http.parse();
1027                 },
1028                 runYukkuri: function(){
1029                         if(this.param.hungry > 70){
1030                                 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1031                                         this.param.yukkuri -= 1;
1032                                 }
1033                         }
1034                         else if(this.param.hungry < 10){
1035                                 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1036                         }
1037
1038                         if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1039                         else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1040                 },
1041                 runHungry: function(){
1042                         if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1043                         if(this.param.hungry >= 100)this.param.hungry = 100;
1044                 },
1045                 runUnun: function(){
1046                         if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1047                         if(this.param.unun >= 100)this.param.unun = 100;
1048                 },
1049                 runSleep: function(){
1050                         if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1051                                 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1052                                 if(this.param.sleep >= 100){
1053                                         this.param.sleep = 100;
1054                                 }
1055                         }
1056                 },
1057                 runAddress: function(){
1058                         for(var key in this.addressBook){
1059                                 var address = this.addressBook[key];
1060                                 //挨拶時間。24時間に1度だけ。
1061                                 if(address.isGreeting){
1062                                         address.greetingWaitFrame++;
1063                                         if(address.greetingWaitFrame >= DAY){
1064                                                 address.greetingWaitFrame = 0;
1065                                                 address.isGreeting = false;
1066                                         }
1067                                 }
1068                         }
1069                 },
1070                 changeFace: function(){
1071                         if(this.param.yukkuri >= 80){
1072                                 this.setFaceImage(EFace.HAPPY1);
1073                         }
1074                         else if(this.param.yukkuri >= 50){
1075                                 this.setFaceImage(EFace.NORMAL);
1076                         }
1077                         else if(this.param.yukkuri >= 30){
1078                                 this.setFaceImage(EFace.TIRED);
1079                         }
1080                         else if(this.param.yukkuri >= 10){
1081                                 this.setFaceImage(EFace.CRY1);
1082                         }
1083                         else if(this.param.yukkuri >= 1){
1084                                 this.setFaceImage(EFace.CRY2);
1085                         }
1086                 },
1087                 getRange: function(){
1088                         return this.param.range;
1089                 },
1090                 isSleep: function(){
1091                         return this.param.sleep >= 100;
1092                 },
1093                 isDead: function(){
1094                         return this.param.yukkuri <= 0;
1095                 },
1096                 isManpuku: function(){
1097                         return this.param.hungry <= 20;
1098                 },
1099                 isKuhuku: function(){
1100                         return this.param.hungry >= 40;
1101                 },
1102                 getYukkuri: function(){
1103                         return this.param.yukkuri;
1104                 },
1105                 setYukkuri: function(yukkuri){
1106                         this.param.yukkuri = yukkuri;
1107                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1108                 },
1109                 getHungry: function(){
1110                         return this.param.hungry;
1111                 },
1112                 setHungry: function(hungry){
1113                         this.param.hungry = hungry;
1114                         if(this.param.hungry < 0)this.param.hungry = 0;
1115                 },
1116                 getUnun: function(){
1117                         return this.param.unun;
1118                 },
1119                 setUnun: function(unun){
1120                         this.param.unun = unun;
1121                         if(this.param.unun < 0)this.param.unun = 0;
1122                 },
1123
1124                 eat:function(food){
1125                         if(food.amount > 0){
1126                                 food.amount--;
1127                                 this.setHungry(this.param.hungry - food.getGive());
1128                                 this.setUnun(this.getUnun() + food.getGive() / 4);
1129                                 this.setYukkuri(this.getYukkuri() + 5);
1130                                 return true;
1131                         }else{
1132                                 this.setYukkuri(this.getYukkuri() - 5);
1133                                 return false;
1134                         }
1135                 },
1136                 unun:function(){
1137                         if(this.direction == EDirection.RIGHT){
1138                                 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1139                         }else{
1140                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
1141                         }
1142                         this.setUnun(0);
1143                 },
1144                 setBodyImage: function(ebody){
1145                         var path = this.bodyStatus[ebody];
1146                         this.image = game.assets[path];
1147                 },
1148                 tlPause:function(){
1149                         // this.imgBody.tl.pause();
1150                         // this.imgGroup.tl.pause();
1151                         // this.imgBody.tl.clear();
1152                         // this.imgGroup.tl.clear();
1153                         this.imgBody.tl.unloop();
1154                         this.imgGroup.tl.unloop();
1155                 },
1156                 tlResume: function(){
1157                         // this.imgBody.tl.resume();
1158                         // this.imgGroup.tl.resume();
1159                         this.animation();
1160                 },
1161                 syncDirection:function(senderYukkuri){
1162                         if(this.getX() > senderYukkuri.getX()){
1163                                 this.direction = EDirection.LEFT;
1164                                 senderYukkuri.direction = EDirection.RIGHT;
1165                         }else{
1166                                 this.direction = EDirection.RIGHT;
1167                                 senderYukkuri.direction = EDirection.LEFT;
1168                         }
1169                 },
1170                 // recvCommunication: function(senderYukkuri, event){
1171                 //      if(event instanceof ComFirstSendEvent){
1172                 //              if(event.progress == "start"){
1173                 //                      this.action.setStatus(EAction.COMMUNICATE_RECV);
1174                 //                      this.tlPause();
1175                 //                      this.syncDirection(senderYukkuri);
1176
1177                 //              }
1178                 //              else if(event.progress == "end"){
1179                 //                      new ComFirstRecvEvent({
1180                 //                              "type": 'greeting',
1181                 //                              "targetNode": senderYukkuri,
1182                 //                              "action": this.action,
1183                 //                              "myYukkuri": this
1184                 //                      });
1185                 //              }
1186                 //      }
1187                 //      if(event instanceof ComFirstRecvEvent){
1188                 //              if(event.progress == "end"){
1189                 //                      senderYukkuri.action.setStatus(EAction.THINK);
1190                 //                      senderYukkuri.animation();
1191                 //                      this.action.setStatus(EAction.THINK);
1192                 //                      this.animation();
1193                 //              }
1194                 //      }
1195
1196                 // },
1197                 isCommunication: function(yukkuri){
1198                         if(this.addressBook[yukkuri.id] === undefined) return true;
1199                         if(this.addressBook[yukkuri.id].isGreeting) return false;
1200                         return true;
1201                 },
1202                 addAddress: function(yukkuri){
1203                         this.addressBook[yukkuri.id] = new Address(yukkuri);
1204                 },
1205                 getAddress: function(yukkuri){
1206                         return this.addressBook[yukkuri.id];
1207                 },
1208                 destruct: function(){
1209
1210                 }
1211         });
1212         var Marisa = enchant.Class.create(Yukkuri,{
1213                 initialize: function(x, y){
1214                         Yukkuri.call(this,x,y);
1215                         this.classname = "Marisa";
1216
1217
1218                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
1219                         var json = net.load("./data/marisa/params.json");
1220                         this.param = json.root.param;
1221                         this.shadow = new enchant.Sprite(64, 64);
1222                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1223                         this.shadow.x = 0 + this.x;
1224                         this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1225                         this.shadow.image._element.style.zIndex = 2;
1226
1227                         this._style.zIndex = 5;
1228
1229                         this.face = new enchant.Sprite(64, 64);
1230                         this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1231                         this.face.x = -CHARA_WIDTH / 2;
1232                         this.face.y = -CHARA_HEIGHT / 2;
1233                         this.face._style.zIndex = 0;
1234
1235                         this.faceStatus ={};
1236                         this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1237                         this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1238                         this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1239                         this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1240                         this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1241                         this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1242                         this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1243                         this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1244                         this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1245                         this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1246
1247
1248                         this.hear = new enchant.Sprite(64, 64);
1249                         this.hear.image = game.assets[EResPath.MARISA_HEAR];
1250                         this.hear.x = -CHARA_WIDTH / 2;
1251                         this.hear.y = -CHARA_HEIGHT / 2;
1252                         this.hear._style.zIndex = 0;
1253
1254                         this.okazari = new Okazari();
1255                         this.okazari.image._element.style.zIndex = 1;
1256
1257                         // this.imgGroup._style.zIndex = 1;
1258
1259                         this.imgGroup.addChild(this.shadow);
1260                         this.imgBody.addChild(this);
1261                         this.imgBody.addChild(this.face);
1262                         this.imgBody.addChild(this.hear);
1263                         this.imgBody.addChild(this.okazari);
1264                         this.imgGroup.addChild(this.imgBody);
1265                         backgroundMap.addChild(this.imgGroup);
1266                         this._tweet = new TTweet(148, 64);
1267                         this._tweet.image._element.style.zIndex = 20;
1268
1269                         this.imgGroup.addChild(this._tweet);
1270                         this.imgGroup.x = x;
1271                         this.imgGroup.y = y;
1272                         this.animation();
1273                         this.action = new Action(this);
1274                         this.id = guid();
1275                         ctl.addObj(this);
1276                 },
1277                 setFaceImage: function(eface){
1278                         var path = this.faceStatus[eface];
1279                         this.face.image = game.assets[path];
1280                 }
1281         });
1282         var Player = enchant.Class.create(Marisa,{
1283                 initialize: function(x, y){
1284                         // this.runEnterframe = function(){
1285                         // },
1286                         Marisa.call(this, x, y);
1287                         this.classname = "Player";
1288                         ctl.setPlayer(this);
1289                         // this.removeEventListener('enterframe',this.runEnterframe);
1290                         this.addEventListener('enterframe', function(){
1291
1292
1293                                 if(this.age%10 === 0 && this.age !== 0){
1294                                         // console.log("palyer:" + this.age);
1295                                 }
1296                                 this.act();
1297                                 ///////////////////////////////////////////////
1298                                 //Action pattern  debug
1299                                 // if(game.input.left){
1300                                 //      // this.changeFace(EResPath.MARISA_FACE_TIRED);
1301                                 //      this.moveX(-10);
1302                                 //      this.direction = EDirection.LEFT;
1303                                 // }
1304                                 // if(game.input.right){
1305                                 //      this.moveX(10);
1306                                 //      this.direction = EDirection.RIGHT;
1307                                 // }
1308                                 // if(game.input.up){
1309                                 //      this.moveY(-10);
1310                                 //      this.tweet("ゆっくりしていってね!");
1311
1312                                 // }
1313                                 // if(game.input.down){
1314                                 //      this.moveY(10);
1315                                 // }
1316                                 ///////////////////////////////////////////////
1317                                 // this.reverse();
1318                                 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1319                                 //      console.log("hit:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.height/2) );
1320                                 // }else{
1321                                 //      console.log("not:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.image.height/2));
1322                                 // }
1323                                 //- Display the circle of search range.
1324                                 // fieldBg.image.clear();
1325                                 // fieldBg.image.context.beginPath();
1326                                 // fieldBg.image.context.fillStyle = '#ff0000';
1327                                 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1328                                 // fieldBg.image.context.fill();
1329                         });
1330                 }
1331         });
1332         game.onload = function(){
1333                 def.Food = Food;
1334                 def.Place = Place;
1335                 mangTouch = new MangTouch(ctl);
1336                 mangMsg = new MangMsg(ctl);
1337                 ctl.setDefined(def);
1338                 backgroundMap.image = game.assets[EResPath.MAP0];
1339                 backgroundMap.loadData(_mapData);
1340                 backgroundMap.collisionData = _collisionData;
1341
1342                 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1343                 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1344                 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1345                 fieldBg.image = fieldSurface;
1346                 fieldBg.x = 0;
1347                 fieldBg.y = 0;
1348
1349                 windowFront.image = windowSurface;
1350                 windowFront.x = 0;
1351                 windowFront.y = 0;
1352                 windowFront.opacity = 0.5;
1353
1354                 windowSurface.context.fillStyle = '#000';
1355                 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1356
1357
1358                 menuSurface.context.fillStyle = '#000';
1359                 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1360                 menuBg.image = menuSurface;
1361                 menuBg.x = EMenuPos.X;
1362                 menuBg.y = EMenuPos.Y;
1363                 backgroundMap.addChild(fieldBg);
1364                 mangIcon = new MangIcon(ctl, menuBg);
1365
1366                 game.rootScene.addChild(backgroundMap);
1367                 game.rootScene.addChild(windowFront);
1368                 game.rootScene.addChild(menuBg);
1369
1370                 // var labelGroup = new LabelGroup();
1371                 mangLabel = new MangLabel(ctl, menuBg);
1372                 // var info = new Label("ゆっくり");
1373                 // info.color = "#ffffff";
1374                 // info.font = "14px 'Times New Roman'";
1375                 // info.x = 4;
1376                 // info.y = GAME_HEIGHT / 2;
1377                 // labelGroup.addChild(info);
1378                 // menuBg.addChild(labelGroup);
1379
1380
1381                 // var food = new def.Food("apple", 200, 250);
1382                 backgroundMap.addChild(foodGroup);
1383                 // backgroundMap.addChild(placeGroup);
1384                 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1385                 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y);
1386                 var touchX = 0;
1387
1388                 game.rootScene.addEventListener('touchstart', function (e) {
1389                         game.touched = true;
1390                         var mang = mangTouch.get(ctl.getCurrentCommand());
1391                         mang.touchstart(e);
1392                 });
1393                 game.rootScene.addEventListener('touchmove', function (e) {
1394                         var mang = mangTouch.get(ctl.getCurrentCommand());
1395                         mang.touchmove(e);
1396                 });
1397                 game.rootScene.addEventListener('touchend', function (e) {
1398                         var mang = mangTouch.get(ctl.getCurrentCommand());
1399                         mang.touchend(e);
1400                         game.touched = false;
1401                 });
1402
1403
1404                 game.rootScene.addEventListener('enterframe', function(){
1405                 //main frame
1406                         mangLabel.draw(player);
1407                 });
1408                 this.addEventListener('enterframe', function(){
1409                         //The priority processing of display instead of z-index
1410                         backgroundMap.childNodes.sort(
1411                                 function(a,b){
1412                                         if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1413                                                 return 0;
1414                                         }
1415                                         else if(typeof a.id === "undefined"){
1416                                                 return -1;
1417                                         }
1418                                         else if(typeof b.id === "undefined"){
1419                                                 return 1;
1420                                         }
1421                                         var ay = a.y;
1422                                         var by = b.y;
1423                                         if(a instanceof Place){
1424                                                 ay += Math.round(a.height * 0.7);
1425                                         }
1426                                         else if(b instanceof Place){
1427                                                 by += Math.round(b.height * 0.7);
1428                                         }
1429
1430                                         if(ay < by)return -1;
1431                                         if(ay > by)return 1;
1432                                         return 0;
1433                                 }
1434                         );
1435                 });
1436
1437         };
1438         game.start();
1439 };