OSDN Git Service

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