OSDN Git Service

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