OSDN Git Service

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