OSDN Git Service

Spriteを組み合わせるFormSpriteを作成。
[yukkurioverwint/YukkuriOverwinter.git] / main.js
1 enchant();
2 //////////////////////////////////////
3 /*
4     CanvasLayer初期化後にcanvasのコンテキストを操作する
5 */
6 // var initCanvas = CanvasLayer.prototype.initialize;
7
8 // CanvasLayer.prototype.initialize = function() {
9 //     initCanvas.call(this);
10 //     console.log("canvas");
11
12 //     // 拡大時の処理をNearest Neighbor方式に切り替え
13 //     // ただしChromeとFireFoxでのみ動作
14 //     this.context.imageSmoothingEnabled = false;
15 //     this.context.webkitImageSmoothingEnabled = false;
16 //     this.context.mozImageSmoothingEnabled = false;
17 // };
18 //global
19 var ctl = null;
20 var mangIcon = null;
21 var mangTouch = null;
22 var mangLabel = null;
23 var mangMsg = null;
24 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
25 var net = new Net();
26 //////////////////////////////////////
27 //define
28 //////////////////////////////////////
29 var ADD_HUNGRY = 1;
30 var PALYER_INIT_X = 100;
31 var PALYER_INIT_Y = 100;
32 var CHARA_WIDTH = 64;
33 var CHARA_HEIGHT = 64;
34 var GAME_WIDTH = 800;
35 var GAME_HEIGHT = 600;
36 var FPS = 40;
37 var BASE_FPS = 20;
38 var HUNGRY_MAX = 100;
39 var TIME_SPEED = 4;
40 var MIN = BASE_FPS;
41 var HOUR = MIN * 60;
42 // var DAY = HOUR * 24;
43 var DAY = HOUR ;
44 var GAME_START_TIME = HOUR * 6;
45 //48x48 best?
46 var ICON_WIDTH = 48;
47 var ICON_HEIGHT = 48;
48
49 var EResPath = {
50         YUKKURI_BASE : './data/yukkuri_base.png',
51         YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
52         YUKKURI_UNUN : './data/unun.png',
53         YUKKURI_SHADOW : './data/shadow.png',
54         MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
55         MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
56         MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
57         MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
58         MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
59         MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
60         MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
61         MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
62         MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
63         MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
64         MARISA_HEAR : './data/marisa/hear1.png',
65         MARISA_OKAZARI : './data/marisa/okazari.png',
66         OBJECT : './data/object.png',
67         MAP0 : './data/map0.png',
68         COMMAND : './data/command.png',
69         PLACE_TREE : './data/system/place_tree.png',
70         GRASS : './data/system/grass.png',
71         PLAYER_BADGE : './data/system/player_badge.png',
72         KUKI : './data/system/kuki.png',
73         // PLACE_TREE : './data/system/rapture.png',
74 };
75 var EResPathReimu = {
76         getName: function(){
77                 return "reimu";
78         },
79         FACE_NORMAL : './data/reimu/face_normal1.png',
80         FACE_TIRED : './data/reimu/face_tired1.png',
81         FACE_ANGRY : './data/reimu/face_angry1.png',
82         FACE_CRY1 : './data/reimu/face_cry1.png',
83         FACE_CRY2 : './data/reimu/face_cry2.png',
84         FACE_EAT1 : './data/reimu/face_eat1.png',
85         FACE_EAT2 : './data/reimu/face_eat2.png',
86         FACE_HAPPY1 : './data/reimu/face_happy1.png',
87         FACE_HAPPY2 : './data/reimu/face_happy2.png',
88         FACE_SLEEP : './data/reimu/face_sleep1.png',
89         HEAR : './data/reimu/hear1.png',
90         OKAZARI : './data/reimu/okazari.png',
91         SUB1 : './data/reimu/sub1.png',
92
93 };
94
95 var EFace = {
96         NORMAL:0,
97         TIRED:1,
98         ANGRY:2,
99         CRY1:3,
100         CRY2:4,
101         EAT1:5,
102         EAT2:6,
103         HAPPY1:7,
104         HAPPY2:8,
105         SLEEP:9,
106 };
107 var EBody = {
108         NORMAL: 0,
109         DEAD: 1,
110 };
111
112 var ECommand = {
113         WORLD_CURSOR: 0,
114         WORLD_TARGET: 1,
115         WORLD_APPLE: 2,
116         WORLD_PLACE: 3,
117         WORLD_REMOVE: 4,
118         WORLD_PICOPICO_HUMMER: 5,
119 };
120
121 var EMenuPos = {
122         X : 600,
123         Y : 0,
124         WIDTH : 200,
125         HEIGHT : GAME_HEIGHT,
126 };
127 //width:200px;
128 var EFieldPos = {
129         X : 0,
130         Y : 0,
131         WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
132         HEIGHT: GAME_HEIGHT,
133 };
134 var EAction = {
135         WAIT : 0,
136         HUNT : 3,
137         THINK : 4,
138         WALK : 5,
139         DEAD: 6,
140         EAT_START : 8,
141         EAT_WAIT : 9,
142         MOVE_TO_EAT_START: 10,
143         MOVE_TO_EAT_UNDERWAY: 11,
144         MOVE_TO_COMMAND: 12,
145         UNUN_START : 13,
146         UNUN_WAIT : 14,
147         UNUN_SMELL_START : 15,
148         UNUN_SMELL_WAIT : 16,
149         SLEEP_START : 17,
150         SLEEP_WAIT : 18,
151         COMMUNICATE_START : 19,
152         COMMUNICATE_WAIT: 20,
153         COMMUNICATE_RECV: 21,
154         MOVE_TO_PLACE_START_HOMELESS: 22,
155         MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
156         DECLARE_PLACE_HOMELESS: 24,
157         MOVE_TO_HUNT_START: 25,
158         THINK_SCHEDULE: 26,
159         HUNT_START: 27,
160         MOVE_GOTO_HOME: 28,
161         IN_HOME: 29,
162         THINK_IN_HOME: 30,
163         EAT_IN_HOME: 31,
164         NONE: 9999
165 };
166 var EDirection = {
167         LEFT : 0,
168         RIGHT: 1,
169 };
170 var EMsg = {
171         WALK: 0,
172         SLEEP: 1,
173         EAT: 2,
174         GET_UP: 3,
175         DEAD: 4,
176         UNUN: 5,
177         UNUN_END: 6,
178         UNUN_SMELL: 7,
179         SEARCH_FOOD: 8,
180         EAT_FAILED: 9,
181         SAY_HELLO: 10,
182         TARGETING_EAT : 11,
183         DECLARE_PLACE: 12,
184         HUNT: 13,
185         REHUNT: 14,
186         HUNT_ESCAPE: 15,
187         YYUYYU: 16,
188         MOVE_GOTO_HOME:17,
189         HUNTING_MESSAGE:18,
190         LEARN_NO_FOOD_IN_PLACE:19,
191         REMOVE_YUKKURI:20,
192         LOST_HOUSE:21,
193         MOVE_TO_HUNTING:22,
194         DAMAGE:23,
195
196 };
197 var EWalkAnimation = {
198         START: 0,
199         END: 1,
200 };
201 var EGrow = {
202         ADULT : 0,
203         SUBADULT : 1,
204         CHILD : 2,
205         BABY : 3,
206         FRUIT_BABY : 4,
207 };
208 var EDate = {
209         MORNING : 0,
210         NOON : 1,
211         AFTERNOON : 2,
212         EVENING : 3,
213         NIGHT : 4,
214         MIDNIGHT : 5
215 };
216 var ESearch = {
217         UNUN: 0,
218         FOOD: 1,
219         YUKKURI: 2,
220         PLACE: 3
221 };
222 var EFood = {
223         BAD : 0,
224         NORMAL : 1,
225         GREAT : 2
226 };
227 var EExSkill = {
228         NO_FOOD_IN_PLACE : 1,
229         KEKKAI : 2,
230 };
231 var EMemory = {
232         FOOD_IN_PLACE : 1,
233 };
234 var EDamage = {
235         PICOHAN : 1
236 };
237 var ELooks = {
238         GOOD_YUKKURI : 0,
239         NORMAL_YUKKURI : 1,
240         BAD_YUKKURI : 2,
241 };
242 var EAnimStatus = {
243         UP : 0,
244         DOWN : 1,
245 };
246 include("./lib/Animation.js"); 
247 include("./lib/FormSprite.js"); 
248
249
250 var ObjSprite = enchant.Class.create(enchant.Sprite,{
251         initialize: function (w, h){
252                 enchant.Sprite.call(this, w, h);
253                 this.id = guid();
254                 ctl.addObj(this);
255                                 // // new BoxLabel(this.ctl,100, e.x, e.y);
256                                 // var box = new Box(this.ctl, 200, 200);
257                                 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
258         },
259         getStatusForDisplay: function (){
260                 return "";
261         },
262         getX: function(){
263                 return this.x;
264         },
265         getY: function(){
266                 return this.y;
267         },
268         getWidth: function(){
269                 return this.width;
270         },
271         getHeight: function(){
272                 return this.height;
273         },
274         isWorld: function(){
275                 return (this.id !== null && this.id !== undefined);
276         },
277         removeAll: function(){
278                 this.remove();
279                 ctl.removeObj(this);
280                 this.id = null;
281         },
282         undefineAll: function (){
283                 for(var key in this){
284                         // if(this.hasOwnProperty(key)){
285                                 delete this[key];
286                         // }
287                 }
288         }
289 });
290
291
292 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
293         var params = {
294                 x: function() {
295                         return this.x + x;
296                 },
297                 y: function() {
298                         return this.y + y;
299                 },
300                 time: time,
301                 easing: easing
302         };
303         //-Event register [onactionstart,onactiontick,onactionend]
304         if(eventFunctions !== undefined){
305                 for(var key in eventFunctions){
306                         params[key] = eventFunctions[key];
307                 }
308         }
309         return this.tween(params);
310 };
311 function plusFrameScale(frame, scale){
312         return (frame/2) * (1 - scale)
313 }
314
315
316
317 include("./lang/ja.js");
318 window.onload = function(){
319         var nodeSort = function (a, b){
320                 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
321                         return 0;
322                 }
323                 else if(typeof a.id === "undefined"){
324                         return -1;
325                 }
326                 else if(typeof b.id === "undefined"){
327                         return 1;
328                 }
329                 var ay = a.y;
330                 var by = b.y;
331                 if(a instanceof Box && b instanceof Box){
332                         return 0;
333                 }
334                 if(a instanceof Box){
335                         return 1;
336                 }
337                 if(b instanceof Box){
338                         return -1;
339                 }
340                 if(a.type == "shadow"){
341                         ay += -28 * a.scaleValue;
342                 }
343                 if(b.type == "shadow"){
344                         by += -28 * b.scaleValue;
345                 }
346                 if(a.classname == "Okazari"){
347                         ay += 11 * a.scaleValue;
348                 }
349                 if(b.classname == "Okazari"){
350                         by += 11 * b.scaleValue;
351                 }
352                 if(a.type == "body"){
353                         ay += 32 * a.scaleValue;
354                 }
355                 else if(a.type == "tweet"){
356                         ay += 148 * a.scaleValue;
357                 }
358                 if(b.type == "body"){
359                         by += 32 * b.scaleValue;
360                 }
361                 else if(b.type == "tweet"){
362                         by += 148 * b.scaleValue;
363                 }
364
365                 if(a instanceof SpriteGroup){
366                         ay = a.y;
367                         ay += a.height/2;
368                 }
369                 if(b instanceof SpriteGroup){
370                         by = b.y;
371                         by += b.height /2;
372                 }
373
374                 if(a instanceof Place){
375                         ay += Math.round(a.height * 0.7);
376                 }
377                 if(b instanceof Place){
378                         by += Math.round(b.height * 0.7);
379                 }
380                 if(a.flgMiYukkuri){
381                         ay += CHARA_HEIGHT;
382                 }
383                 if(b.flgMiYukkuri){
384                         by += CHARA_HEIGHT;
385                 }
386
387                 if(ay < by)return -1;
388                 else if(ay > by)return 1;
389                 if(a.id < b.id)return -1;
390                 else if(a.id > b.id)return 1;
391                 return 0;
392
393         }
394
395         //init game
396         var def = new Object();
397         var foodGroup = new Group();
398         var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
399         SpriteGroup.prototype.classname = "";
400         var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
401         var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
402         var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
403         game = new Game(GAME_WIDTH, GAME_HEIGHT);
404         game.fps = FPS;
405         var _loadArr = [];
406         var i=0;
407         var tmpName = EResPathReimu.getName();
408         i=0;
409         for(var _v in EResPathReimu){
410                 if(typeof EResPathReimu[_v] === "function")continue;
411                 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
412                 i++;
413         }
414         tmpName = null;
415
416         i=0;
417         for(var _v in EResPath){
418                 _loadArr[i] = EResPath[_v];
419                 i++;
420         }
421         game.preload(_loadArr);
422         var MapGroup = enchant.Class.mixClasses(Map, Group,true);
423         var backgroundMap = new MapGroup(16, 16);
424         App.backgroundMap = backgroundMap;
425         include("./class.js");
426         include("./ctrl.js");
427         ctl = new Ctrl();
428         ctl.init(game);
429         ctl.setBackgroundMap(backgroundMap);
430         var Action = enchant.Class.create({
431                 initialize: function (yukkuri){
432                         this.status = EAction.THINK;
433                         this.yukkuri = yukkuri;
434                         this.isMoving = false;
435                         this.targetNode = null;
436                 },
437                 getStatus: function(){
438                         return this.status;
439                 },
440                 setStatus: function(eaction){
441                         this.status = eaction;
442                 },
443                 observe: function(){
444                         if(this.yukkuri.isDead()){
445                                 this.status = EAction.DEAD;
446                         }
447                         // else if(this.yukkuri.isSleep()){
448                         //      this.status = EAction.SLEEP;
449                         // }
450
451                 },
452                 act : function(){
453                         this.observe();
454                         switch(this.status){
455                                 case EAction.WAIT:
456                                         this.waitCnt++;
457                                         if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
458                                                 this.waitCnt = 0;
459                                                 this.setStatus(EAction.THINK);
460                                                 console.log("wait cnt end");
461                                         }
462                                 break;
463                                 case EAction.THINK_IN_HOME:
464                                         this.waitCnt = 0;
465                                         this.search();
466                                         this.think_in_home();
467                                 break;
468                                 case EAction.EAT_IN_HOME:
469                                         this.eat_in_home();
470                                 break;
471                                 case EAction.THINK:
472                                         this.waitCnt = 0;
473                                         if(this.yukkuri.age%2 === 0){
474                                                 this.yukkuri.changeFace();
475                                                 this.search();
476                                                 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
477                                         }
478                                 break;
479                                 case EAction.MOVE_TO_EAT_START:
480                                         this.move_to_eat_start();
481                                 break;
482                                 case EAction.MOVE_TO_EAT_UNDERWAY:
483                                 break;
484                                 //Random Walk
485                                 case EAction.WALK:
486                                         this.walk(0);
487                                 break;
488                                 case EAction.SLEEP_START:
489                                         this.sleep_start();
490                                 break;
491                                 case EAction.SLEEP_WAIT:
492                                 break;
493                                 case EAction.DEAD:
494                                         this.dead();
495                                 break;
496                                 case EAction.EAT_START:
497                                         this.eat_start();
498                                 break;
499                                 case EAction.EAT_WAIT:
500                                 break;
501                                 case EAction.UNUN_START:
502                                         this.unun_start();
503                                 break;
504                                 case EAction.UNUN_WAIT:
505                                 break;
506                                 case EAction.MOVE_TO_COMMAND:
507                                         this.move_to_command();
508                                 break;
509                                 case EAction.UNUN_SMELL_START:
510                                         this.unun_smell_start();
511                                 break;
512                                 case EAction.COMMUNICATE_START:
513                                         this.communicate_start();
514                                 break;
515                                 case EAction.COMMUNICATE_WAIT:
516                                 case EAction.COMMUNICATE_RECV:
517                                 if(this.yukkuri.communicateYukkuri != null){
518                                         var _s = this.yukkuri.communicateYukkuri.action.getStatus();
519                                         if(this.yukkuri.communicateYukkuri.isDead()
520                                                 || (_s !== EAction.COMMUNICATE_START && _s !== EAction.COMMUNICATE_WAIT && _s !== EAction.COMMUNICATE_RECV)){
521                                                 this.setStatus(EAction.THINK);
522                                                 this.yukkuri.animation();
523                                         }
524                                 }
525                                 break;
526                                 case EAction.MOVE_TO_PLACE_START_HOMELESS:
527                                         this.move_to_place_start_homeless();
528                                 break;
529                                 case EAction.DECLARE_PLACE_HOMELESS:
530                                         this.declare_place_homeless();
531                                 break;
532                                 case EAction.MOVE_TO_HUNT_START:
533                                         this.move_to_hunt_start();
534                                 break;
535                                 case EAction.HUNT_START:
536                                         this.hunt_start();
537                                 break;
538                                 case EAction.MOVE_GOTO_HOME:
539                                         this.move_goto_home();
540                                 break;
541                                 case EAction.IN_HOME:
542                                         this.in_home();
543                                 break;
544
545                         }
546                         this.yukkuri.reverse();
547                 },
548                 // thinkHavePlace: function(){
549                 //      var date = ctl.getDate();
550                 //      if(this.yukkuri.isPlaceRange()){
551                 //      }else{
552                 //              //ゆっくりプレイスの範囲外
553                 //              if(date === EDate.EVENING
554                 //                      || date === EDate.NIGHT
555                 //                      || date === EDate.MIDNIGHT
556                 //                      ){
557                 //                      this.setStatus(EAction.MOVE_GOTO_HOME);
558                 //                      return;
559                 //              }
560                 //              else if(date === EDate.EVENING){
561                 //                      // if(this.yukkuri.isItemsMax()){
562                 //                      //      this.setStatus(EAction.IN_HOME);
563                 //                      // }
564                 //                      // else{
565                 //                      //      this.setStatus(EAction.MOVE_TO_HUNT_START);
566                 //                      // }
567                 //              }
568                 //      }
569                 //      if(this.yukkuri.isVeryKuhuku()){
570                 //              //食べ物探したい
571
572                 //              //なかったら
573                 //              this.setStatus(EAction.MOVE_GOTO_HOME);
574                 //      }
575                 //      else if(this.yukkuri.isSleep()){
576                 //              this.setStatus(EAction.SLEEP_START);
577                 //      }
578                 //      else if(this.yukkuri.getUnun() >= 80){
579                 //              this.setStatus(EAction.UNUN_START);
580                 //      }
581                 //      else{
582                 //              this.yukkuri.changeFace();
583                 //              this.search();
584                 //      }
585                 // },
586                 think_in_home: function(){
587                         var date = ctl.getDate();
588                         if((date === EDate.MIDNIGHT)
589                                 && !this.yukkuri.isSleep()
590                                 && !this.yukkuri.isVeryKuhuku()
591                                 ){
592                                 new SleepEvent({
593                                         "action": this,
594                                         "nextStatus":EAction.THINK_IN_HOME,
595                                         "myYukkuri": this.yukkuri
596                                 });
597                                 return;
598                         }
599                         else if(date === EDate.EVENING){
600                                 //QK
601                         }
602                         else if(this.yukkuri.isVeryKuhuku() && this.yukkuri.getPlace().isFood()){
603                                 this.setStatus(EAction.EAT_IN_HOME);
604                         }
605                         else{
606                                 //marisa is hunting move
607                                 if(this.yukkuri.beforeHuntingFood !== null){
608                                         new MoveToHuntEvent({
609                                                 "type": 'food',
610                                                 "targetNode": this.yukkuri.beforeHuntingFood,
611                                                 "action": this,
612                                                 "myYukkuri": this.yukkuri
613                                         });
614                                         return;
615                                 }else{
616                                         this.setStatus(EAction.WALK);
617                                 }
618                         }
619                 },
620                 eat_in_home: function(){
621                         new EatInHomeEvent({
622                                 "targetNode": this.yukkuri.getPlace(),
623                                 "action": this,
624                                 "myYukkuri": this.yukkuri
625                         });
626                 },
627                 move_to_eat_start : function(){
628                         new MoveToEatEvent({
629                                 "type": 'food',
630                                 "targetNode": this.targetNode,
631                                 "action": this,
632                                 "myYukkuri": this.yukkuri
633                         });
634                 },
635                 walkNew: function(){
636
637                 },
638                 walk : function(retryCounter){
639                         if(retryCounter > 15){
640                                 retryCounter = 0;
641                                 this.status = EAction.NONE;
642                                 console.log("retryCount over");
643                                 return;
644                         }
645                         if(this.yukkuri.formSprite.tlQueueLength() === 0){
646                         // if(this.yukkuri.imgGroup.tl.queue.length === 0){
647                                 var frame = 200;
648                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
649                                 if(this.isMoving){
650                                         this.isMoving = false;
651                                         this.status = EAction.THINK;
652                                         this.yukkuri.vx = 0;
653                                         this.yukkuri.vy = 0;
654                                 }else{
655                                         var xpos = 150 + rand(40) - (retryCounter * 10);
656                                         var ypos = 150 + rand(40) - (retryCounter * 10);
657                                         if(false){
658                                                 this.yukkuri.vx = xpos;
659                                                 this.yukkuri.vy = ypos;
660                                                 this.yukkuri.direction = EDirection.RIGHT;
661                                         }
662                                         else if(rand(8) === 0){
663                                                 this.yukkuri.vx = 0;
664                                                 this.yukkuri.vy = -ypos;
665                                         }
666                                         else if(rand(8) == 1){
667                                                 this.yukkuri.vx = xpos;
668                                                 this.yukkuri.vy = -ypos;
669                                                 this.yukkuri.direction = EDirection.RIGHT;
670                                         }
671                                         else if(rand(8) == 2){
672                                                 this.yukkuri.vx = xpos;
673                                                 this.yukkuri.vy = 0;
674                                                 this.yukkuri.direction = EDirection.RIGHT;
675                                         }
676                                         else if(rand(8) == 3){
677                                                 this.yukkuri.vx = xpos;
678                                                 this.yukkuri.vy = ypos;
679                                                 this.yukkuri.direction = EDirection.RIGHT;
680                                         }
681                                         else if(rand(8) == 4){
682                                                 this.yukkuri.vx = 0;
683                                                 this.yukkuri.vy = ypos;
684                                         }
685                                         else if(rand(8) == 5){
686                                                 this.yukkuri.vx = -xpos;
687                                                 this.yukkuri.vy = ypos;
688                                                 this.yukkuri.direction = EDirection.LEFT;
689                                         }
690                                         else if(rand(8) == 6){
691                                                 this.yukkuri.vx = -xpos;
692                                                 this.yukkuri.vy = 0;
693                                                 this.yukkuri.direction = EDirection.LEFT;
694                                         }
695                                         else if(rand(8) == 7){
696                                                 this.yukkuri.vx = -xpos;
697                                                 this.yukkuri.vy = -ypos;
698                                                 this.yukkuri.direction = EDirection.LEFT;
699                                         }
700                                         if (this.yukkuri.vx || this.yukkuri.vy) {
701                                                 var map = ctl.backgroundMap;
702                                                 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
703                                                 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
704                                                 var x = this.yukkuri.getX() + this.yukkuri.vx;
705                                                 var y = this.yukkuri.getY() + this.yukkuri.vy + this.yukkuri.getHeight() / 2;
706                                                 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
707                                                         // console.log("あたってないよ:"+ this.yukkuri.getX() + ":" + this.yukkuri.getY());
708                                                         // console.log("X:" + this.yukkuri.moveX);
709                                                         // console.log("Y:" + this.yukkuri.moveY);
710                                                         this.isMoving = true;
711                                                         this.yukkuri.reverse();
712                                                         this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
713                                                         mangMsg.output(this.yukkuri,EMsg.WALK);
714                                                         //うんうんくさい対策
715                                                         this.targetNode = null;
716                                                 }else{
717                                                         // console.log("HIT:"+ this.yukkuri.getX() + ":" + this.yukkuri.getY() + "," + this.yukkuri.vx + ":" + this.yukkuri.vy);
718                                                         this.walk(retryCounter+1);
719                                                 }
720                                         }
721                                 }
722                         }
723                 },
724                 sleep_start: function(){
725                         new SleepEvent({
726                                 "action": this,
727                                 "myYukkuri": this.yukkuri
728                         });
729                 },
730                 dead : function(){
731                         mangMsg.output(this.yukkuri, EMsg.DEAD);
732                         this.yukkuri.tlPause();
733                         this.yukkuri.setBodyImage(EBody.DEAD);
734                 },
735                 eat_start: function(){
736                         new EatEvent({
737                                 "type": 'eat',
738                                 "targetNode": this.targetNode,
739                                 "action": this,
740                                 "myYukkuri": this.yukkuri
741                         });
742
743                 },
744                 unun_start: function(){
745                         new UnunEvent({
746                                 "action": this,
747                                 "myYukkuri": this.yukkuri
748                         });
749                 },
750                 unun_smell_start: function(){
751                         new UnunSmellEvent({
752                                 "action": this,
753                                 "myYukkuri": this.yukkuri
754                         });
755                 },
756                 communicate_start:function(){
757                         new ComSayHelloSendEvent({
758                                 "type": 'greeting',
759                                 "targetNode": this.targetNode,
760                                 "action": this,
761                                 "myYukkuri": this.yukkuri
762                         });
763                 },
764                 move_to_place_start_homeless:function(){
765                         new MoveToPlaceStartHomelessEvent({
766                                 "targetNode": this.targetNode,
767                                 "action": this,
768                                 "myYukkuri": this.yukkuri
769                         });
770                 },
771                 declare_place_homeless:function(){
772                         new DeclarePlaceHomelessEvent({
773                                 "targetNode": this.targetNode,
774                                 "action": this,
775                                 "myYukkuri": this.yukkuri
776                         });
777                 },
778                 move_to_hunt_start:function(){
779                         new MoveToHuntEvent({
780                                 "type": 'food',
781                                 "targetNode": this.targetNode,
782                                 "action": this,
783                                 "myYukkuri": this.yukkuri
784                         });
785                 },
786                 hunt_start:function(){
787                         new HuntStartEvent({
788                                 "type": 'food',
789                                 "targetNode": this.targetNode,
790                                 "action": this,
791                                 "myYukkuri": this.yukkuri
792                         });
793                 },
794                 move_goto_home:function(){
795                         var place = this.yukkuri.getPlace();
796                         new MoveGotoHomeEvent({
797                                 "type": 'hunt_end',
798                                 "targetNode": place,
799                                 "action": this,
800                                 "myYukkuri": this.yukkuri
801                         });
802                 },
803                 in_home:function(){
804                         var place = this.yukkuri.getPlace();
805                         if(place != null && place.isWorld()){
806                                 new InHomeEvent({
807                                         "type": 'hunt_end',
808                                         "targetNode": place,
809                                         "action": this,
810                                         "myYukkuri": this.yukkuri
811                                 });
812                         }else{
813                                 if(place && !place.isWorld())place.undefineAll();
814                                 this.yukkuri.declarePlace(null);
815                                 this.setStatus(EAction.WAIT);
816                                 mangMsg.output(this.yukkuri, EMsg.LOST_HOUSE);
817                                 this.yukkuri.setFaceImage(EFace.CRY2);
818                                 new WaitEvent({
819                                         "waitframe": FPS * 3.0,
820                                         "action": this,
821                                         "myYukkuri": this.yukkuri
822                                 });
823                         }
824                 },
825                 move_to_command: function(){
826                         var obj = this.yukkuri.searchObjectMang.currentCmdObject;
827                         new MoveToCommandEvent({
828                                 "action": this,
829                                 "cmdObject": obj,
830                                 "myYukkuri": this.yukkuri
831                         });
832
833                 },
834                 search: function(){
835                         this.yukkuri.clearSearchObject();
836                         var nodes = ctl.getObjs();
837                         l = nodes.length;
838                         var ununFlg = false;
839                         for (var key in nodes) {
840                                 var node = nodes[key];
841                                 if(node === null || node === undefined)continue;
842                                 if(this.yukkuri.id === node.id)continue;
843                                 //うんうん臭いを検索
844                                 if (
845                                         node instanceof Unun
846                                         && !(this.targetNode instanceof Unun)
847                                         && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
848
849                                         this.yukkuri.addSearchObject(ESearch.UNUN, node);
850                                 }
851                                 //食べ物を検索
852                                 else if (node instanceof Food && node.amount > 0) {
853                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
854                                                 this.yukkuri.addSearchObject(ESearch.FOOD, node);
855                                         }
856                                 }
857                                 //ゆっくりを検索
858                                 else if(node instanceof Yukkuri){
859                                         if(node.grow != EGrow.FRUIT_BABY && this.yukkuri.within(node, this.yukkuri.getRange())){
860                                                 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
861                                         }
862                                 }
863                                 //ゆっくりプレイスを検索
864                                 else if(node instanceof Place){
865                                         if(this.yukkuri instanceof Player){
866                                         }
867                                         if(this.yukkuri.within(node, this.yukkuri.getRange())){
868                                                 this.yukkuri.addSearchObject(ESearch.PLACE, node);
869                                         }
870                                 }
871                         }
872                         this.status =  EAction.WALK;
873                 }
874         });
875 /**
876  * Range範囲内のObjSprを管理する
877  * 注意!:ゆっくりプレイスを持って入るもののみ使用される
878  * @param  {[type]} )
879  * @return {[type]}
880  */
881         var SearchObjectMang = enchant.Class.create({
882                 initialize: function (){
883                         this.init();
884                         this.currentCmdObject = null;
885                 },
886                 init:function(){
887                         this.datas = [];
888                         for(var key in ESearch){
889                                 var esearch = ESearch[key];
890                                 this.datas[esearch] = [];
891                         }
892                 },
893                 add :function(esearch, node){
894                         this.datas[esearch].push(node);
895                 },
896                 clear :function(){
897                         for(var key in ESearch){
898                                 var esearch = ESearch[key];
899                                 this.datas[esearch].length = 0;
900                         }
901                         // this.datas.length = 0;
902                         // this.init();
903                 },
904                 get:function (esearch){
905                         return this.datas[esearch];
906                 },
907                 getNear:function (esearch, yukkuri){
908                         var objects = this.datas[esearch];
909                         var nearDistance = null;
910                         var ret = null;
911                         for(var i=0;i<objects.length;i++){
912                                 var object = objects[i];
913                                 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
914                                 if(nearDistance === null || nearDistance > nowDistance){
915                                         nearDistance = nowDistance;
916                                         ret = object;
917                                 }
918                         }
919                         return ret;
920                 },
921                 callEvent: function(yukkuri){
922                         if(yukkuri.cmdQueue.length !== 0){
923                                 this.currentCmdObject = yukkuri.cmdQueue.shift();
924                                 yukkuri.action.setStatus(EAction.MOVE_TO_COMMAND);
925                                 return;
926                         }
927
928                         if(yukkuri.isItemsMax() && yukkuri.isPlace()){
929                                 yukkuri.action.targetNode = yukkuri.getPlace();
930                                 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
931                                 return;
932                         }
933                         if(yukkuri.isVeryKuhuku()){
934                                 //エサを探す
935                                 var foods = this.get(ESearch.FOOD);
936                                 if(foods.length > 0){
937                                         var foods = this.get(ESearch.FOOD);
938                                         food = this.getNear(ESearch.FOOD, yukkuri);
939                                         if(food !== null){
940                                                 yukkuri.action.targetNode = food;
941                                                 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
942                                                 return;
943                                         }
944                                 }
945                                 if(yukkuri.getMemory(EMemory.FOOD_IN_PLACE) === 0 && yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
946                                         yukkuri.action.setStatus(EAction.WALK);
947                                         return;
948                                 }
949
950                                 //家があるなら家に帰宅
951                                 if(foods.length === 0 && yukkuri.isPlace() && yukkuri.getPlace().isFood()){
952                                         yukkuri.action.targetNode = yukkuri.getPlace();
953                                         yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
954                                         return;
955                                 }
956                                 //たべものを探しに行く
957                                 yukkuri.action.setStatus(EAction.WALK);
958                                 return;
959                         }
960
961                         if(yukkuri.isSleep()){
962                                 yukkuri.action.setStatus(EAction.SLEEP_START);
963                                 return;
964                         }
965
966                         else if(yukkuri.getUnun() >= 80){
967                                 yukkuri.action.setStatus(EAction.UNUN_START);
968                                 return;
969                         }
970
971
972                         if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
973                                 food = this.getNear(ESearch.FOOD, yukkuri);
974                                 if(food !== null){
975                                         yukkuri.action.targetNode = food;
976                                         yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
977                                         return;
978                                 }
979                         }
980                         ununs = this.get(ESearch.UNUN);
981                         if(ununs.length !== 0){
982                                 yukkuri.action.targetNode = yukkuri.getPlace();
983                                 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
984                                 return;
985                         }
986                         var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
987                         if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
988                                 yukkuri.action.targetNode = searchYukkuri;
989                                 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
990                                 return;
991                         }
992                         if(!yukkuri.isPlace()){
993                                 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
994                                 if(searchYukkuri != null && !searchYukkuri.isOwner()){
995                                         yukkuri.action.targetNode = searchYukkuri;
996                                         yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
997                                         return;
998                                 }
999                         }
1000                         yukkuri.action.setStatus(EAction.WALK);
1001
1002                 }
1003
1004         });
1005         var Event = enchant.Class.create({
1006                 initialize: function (_data){
1007                         this.guid = guid();
1008                 },
1009                 onactionstart:function(self){
1010                         return this._onactionstart;
1011                 },
1012                 _onactionstart:function(e){
1013                         if(typeof e === "undefined")return;
1014                 },
1015                 onactiontick:function(self){
1016                         return function(e){
1017                                 if(typeof e === "undefined")return;
1018                         };
1019                 },
1020                 onactionend:function(self){
1021                         return function(e){
1022                                 if(typeof e === "undefined")return;
1023                         };
1024                 }
1025         });
1026         var WalkEvent = enchant.Class.create(Event,{
1027                 initialize: function (_data){
1028                         this.data = _data;
1029                         this.yukkuri = _data.myYukkuri;
1030                         this.action = _data.action;
1031
1032                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
1033                         this.action.setStatus(EAction.SLEEP_WAIT);
1034                         this.yukkuri.setFaceImage(EFace.SLEEP);
1035                         this.yukkuri.tlPause();
1036                         var self = this;
1037                         this.yukkuri.addEventListener('enterframe', function() {
1038                                 var yukkuri = self.yukkuri;
1039                                 self.run();
1040                         });
1041                 },
1042                 run : function(){
1043
1044                 }
1045         });
1046         var SleepEvent = enchant.Class.create(Event,{
1047                 initialize: function (_data){
1048                         this.data = _data;
1049                         this.yukkuri = _data.myYukkuri;
1050                         this.action = _data.action;
1051
1052                         mangMsg.output(this.yukkuri, EMsg.SLEEP);
1053                         this.action.setStatus(EAction.SLEEP_WAIT);
1054                         this.yukkuri.setFaceImage(EFace.SLEEP);
1055                         this.yukkuri.tlPause();
1056                         var sec = FPS * 3;
1057                         var self = this;
1058                         this.yukkuri.addEventListener('enterframe', function() {
1059                                 var yukkuri = self.yukkuri;
1060                                 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
1061                                 if(yukkuri.param.sleep <= 0){
1062                                         yukkuri.param.sleep = 0;
1063                                         this.removeEventListener("enterframe",arguments.callee);
1064                                         mangMsg.output(self.yukkuri, EMsg.GET_UP);
1065                                         yukkuri.setFaceImage(EFace.NORMAL);
1066                                         yukkuri.tlResume();
1067                                         // self.action.setStatus(EAction.WAIT);
1068                                         if(self.data.nextStatus !== undefined){
1069                                                 self.action.setStatus(self.data.nextStatus);
1070                                         }else{
1071                                                 self.action.setStatus(EAction.THINK);
1072                                         }
1073                                 }
1074                         });
1075                 }
1076         });
1077
1078         var UnunEvent = enchant.Class.create(Event,{
1079                 initialize: function (_data){
1080                         this.data = _data;
1081                         this.yukkuri = _data.myYukkuri;
1082                         this.action = _data.action;
1083                         this.action.setStatus(EAction.UNUN_WAIT);
1084                         mangMsg.output(this.yukkuri, EMsg.UNUN);
1085                         this.yukkuri.setFaceImage(EFace.HAPPY2);
1086                         var sec = FPS * 3;
1087
1088                         this.yukkuri.wait(sec, {
1089                                 "onactionend": this.onactionend(this)
1090                         });
1091                 },
1092                 onactionend:function(self){
1093                         return function(e){
1094                                 if(typeof e === "undefined")return;
1095                                 self.yukkuri.unun();
1096                                 self.action.setStatus(EAction.WAIT);
1097                                 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
1098                                 new WaitEvent({
1099                                         "waitframe": FPS * 1.5,
1100                                         "action": self.action,
1101                                         "myYukkuri": self.yukkuri
1102                                 });
1103                         };
1104                 }
1105         });
1106         var WaitEvent = enchant.Class.create(Event,{
1107                 initialize: function (_data){
1108                         this.data = _data;
1109                         this.yukkuri = _data.myYukkuri;
1110                         this.action = _data.action;
1111                         this.waitframe = _data.waitframe;
1112                         this.yukkuri.wait(this.waitframe, {
1113                                 "onactionstart": this.onactionstart(this),
1114                                 "onactiontick": this.onactiontick(this),
1115                                 "onactionend": this.onactionend(this)
1116                         });
1117                 },
1118                 onactionend:function(self){
1119                         return function(e){
1120                                 if(typeof e === "undefined")return;
1121                                 self.action.setStatus(EAction.THINK);
1122                         };
1123                 }
1124         });
1125         var UnunSmellEvent = enchant.Class.create(Event,{
1126                 initialize: function (_data){
1127                         this.data = _data;
1128                         this.yukkuri = _data.myYukkuri;
1129                         this.action = _data.action;
1130                         this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1131                         mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1132                         this.yukkuri.setFaceImage(EFace.CRY1);
1133                         var sec = FPS * 3;
1134                         this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1135                         this.yukkuri.wait(sec, {
1136                                 "onactionend": this.onactionend(this)
1137                         });
1138                 },
1139                 onactionend:function(self){
1140                         return function(e){
1141                                 if(typeof e === "undefined")return;
1142                                 self.action.setStatus(EAction.WALK);
1143                         };
1144                 }
1145         });
1146
1147         var EatEvent = enchant.Class.create(Event,{
1148                 initialize: function (_data){
1149                         this.data = _data;
1150                         this.yukkuri = _data.myYukkuri;
1151                         this.food = _data.targetNode;
1152                         this.action = _data.action;
1153                         this.action.setStatus(EAction.EAT_WAIT);
1154
1155                         var sec = BASE_FPS * 3;
1156                         if(this.yukkuri.eat(this.food)){
1157                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1158                                 this.yukkuri.setFaceImage(EFace.EAT2);
1159                         }else{
1160                                 sec = BASE_FPS * 6;
1161                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1162                                 this.yukkuri.setFaceImage(EFace.CRY2);
1163                         }
1164                         this.yukkuri.wait(sec, {
1165                                 "onactionend": this.onactionend(this)
1166                         });
1167                 },
1168                 onactionend:function(self){
1169                         return function(e){
1170                                 if(typeof e === "undefined")return;
1171                                 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku() || !self.food.isWorld()){
1172                                         self.action.setStatus(EAction.THINK);
1173                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1174                                 }else{
1175                                         self.action.setStatus(EAction.EAT_START);
1176                                 }
1177                         };
1178                 }
1179         });
1180         /**
1181          * Move Event
1182          * -When yukkuri find Food.
1183          * @param  _data
1184          * type: "food"
1185          * targetNode: enchant.Node
1186          * action:Action
1187          * myYukkuri:Yukkuri
1188          */
1189         var MoveToEatEvent = enchant.Class.create(Event,{
1190                 initialize: function (_data){
1191                         this.data = _data;
1192                         this.yukkuri = this.data.myYukkuri;
1193                         this.action = this.data.action;
1194
1195                         var yukkuri = this.yukkuri;
1196                         var node = this.data.targetNode;
1197                         //food distance
1198                         if(this.data.type == "food"){
1199                                 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1200                                 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1201                                 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1202                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1203                                 var frame = distance + distance/5 + 1;
1204                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1205                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1206                                 yukkuri.reverse();
1207                                 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1208
1209                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1210                                         "onactiontick": this.onactiontick(this),
1211                                         "onactionend": this.onactionend(this)
1212                                 });
1213                         }
1214                 },
1215                 onactiontick:function(self){
1216                         return function(e){
1217                                 if(typeof e === "undefined")return;
1218                         };
1219                 },
1220                 onactionend:function(self){
1221                         return function(e){
1222                                 if(typeof e === "undefined")return;
1223                                 self.action.setStatus(EAction.EAT_START);
1224                         };
1225                 }
1226         });
1227         var MoveToHuntEvent = enchant.Class.create(Event,{
1228                 initialize: function (_data){
1229                         this.data = _data;
1230                         this.yukkuri = this.data.myYukkuri;
1231                         this.action = this.data.action;
1232
1233                         var yukkuri = this.yukkuri;
1234                         var node = this.data.targetNode;
1235                         var nodeX = node.x;
1236                         var nodeY = node.y;
1237                         var nodeWidth = node.width;
1238                         var nodeHeight = node.height;
1239                         node = null;
1240
1241                         //food distance
1242                         if(this.data.type == "food"){
1243                                 this.action.setStatus(EAction.WAIT);
1244                                 yukkuri.vx = nodeX - yukkuri.getX();
1245                                 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1246                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1247                                 var frame = distance + distance/5 + 1;
1248                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1249                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1250                                 yukkuri.reverse();
1251                                 mangMsg.output(yukkuri, EMsg.MOVE_TO_HUNTING);
1252
1253                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1254                                         "onactionend": this.onactionend(this)
1255                                 });
1256                         }
1257                 },
1258                 onactionend:function(self){
1259                         return function(e){
1260                                 if(typeof e === "undefined")return;
1261                                 self.action.setStatus(EAction.HUNT_START);
1262                         };
1263                 }
1264         });
1265         var HuntStartEvent = enchant.Class.create(Event,{
1266                 initialize: function (_data){
1267                         Event.call(this, _data);
1268                         this.initCnt = 0;
1269                         this.data = _data;
1270                         this.yukkuri = _data.myYukkuri;
1271                         this.food = _data.targetNode;
1272                         this.action = _data.action;
1273                         this.action.setStatus(EAction.WAIT);
1274                         this.huntingStatus = "hunting";
1275                         this.tick = 0;
1276                         // this.yukkuri.beforeHuntingFood = this.food;
1277                         if(this.food.isWorld()){
1278                                 this.yukkuri.beforeHuntingFood = new MemoryFood(this.food);
1279                                 var sec = BASE_FPS * 8;
1280                                 if(this.yukkuri.hunt(this.food)){
1281                                         this.huntingStatus = "hunting";
1282                                         mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1283                                         this.yukkuri.setFaceImage(EFace.HAPPY1);
1284                                 }else{
1285                                         if(this.yukkuri.isItemsMax()){
1286                                                 sec = 1;
1287                                                 this.huntingStatus = "return";
1288                                                 // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1289                                                 this.yukkuri.setFaceImage(EFace.NORMAL);
1290                                         }else{
1291                                                 sec = BASE_FPS * 3;
1292                                                 this.huntingStatus = "cry";
1293                                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1294                                                 this.yukkuri.setFaceImage(EFace.CRY2);
1295                                         }
1296                                 }
1297
1298                         }else{
1299                                 this.yukkuri.beforeHuntingFood = null;
1300                                 sec = BASE_FPS * 3;
1301                                 this.huntingStatus = "cry";
1302                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1303                                 this.yukkuri.setFaceImage(EFace.CRY2);
1304                         }
1305
1306                         this.yukkuri.wait(sec, {
1307                                 "onactiontick": this.onactiontick(this),
1308                                 "onactionend": this.onactionend(this)
1309                         });
1310                 },
1311                 onactiontick:function(self){
1312                         return function(e){
1313                                 if(typeof e === "undefined")return;
1314                                 self.tick++;
1315                                 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1316                                         if(this.age%(BASE_FPS * 5) == 0){
1317                                                 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1318                                                 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1319                                         }
1320                                 }
1321                         };
1322                 },
1323                 onactionend:function(self){
1324                         return function(e){
1325                                 if(typeof e === "undefined")return;
1326                                 if(self.huntingStatus == "hunting"){
1327                                         if(self.yukkuri.isItemsMax()){
1328                                                 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1329                                                 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1330                                         }else{
1331                                                 self.action.setStatus(EAction.HUNT_START);
1332                                         }
1333                                 }
1334                                 else if(self.huntingStatus == "return"){
1335                                         self.action.setStatus(EAction.MOVE_GOTO_HOME);
1336                                 }
1337                                 else if(self.huntingStatus === "cry"){
1338                                         // self.action.setStatus(EAction.THINK);
1339                                         self.action.setStatus(EAction.WALK);
1340                                 }
1341                                 self.release();
1342                         };
1343                 },
1344                 release:function(){
1345                         this.action = null;
1346                         this.yukkuri = null;
1347                         this.food = null;
1348                         this.data = null;
1349                 }
1350         });
1351         var MoveGotoHomeEvent = enchant.Class.create(Event,{
1352                 initialize: function (_data){
1353                         this.data = _data;
1354                         this.yukkuri = this.data.myYukkuri;
1355                         this.action = this.data.action;
1356
1357                         var yukkuri = this.yukkuri;
1358                         var place = this.data.targetNode;
1359                         //food distance
1360                         if(this.data.type == "hunt_end"){
1361                                 this.action.setStatus(EAction.WAIT);
1362                                 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1363                                 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1364                                 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1365                                 var frame = distance + distance/2 + 1 ;
1366                                 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1367                                 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1368                                 yukkuri.reverse();
1369                                 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1370
1371                                 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1372                                         "onactiontick": this.onactiontick(this),
1373                                         "onactionend": this.onactionend(this)
1374                                 });
1375                         }
1376                 },
1377                 onactiontick:function(self){
1378                         return function(e){
1379                                 if(typeof e === "undefined")return;
1380                                 if(this.age%(BASE_FPS * 5) == 0){
1381                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1382                                 }
1383                         };
1384                 },
1385                 onactionend:function(self){
1386                         return function(e){
1387                                 if(typeof e === "undefined")return;
1388                                 self.action.setStatus(EAction.IN_HOME);
1389                                 self.release();
1390                         };
1391                 },
1392                 release:function(){
1393                         this.action = null;
1394                         this.yukkuri = null;
1395                         this.data = null;
1396                 }
1397         });
1398         var InHomeEvent = enchant.Class.create(Event,{
1399                 initialize: function (_data){
1400                         this.data = _data;
1401                         this.yukkuri = this.data.myYukkuri;
1402                         this.action = this.data.action;
1403
1404                         var yukkuri = this.yukkuri;
1405                         var place = this.data.targetNode;
1406
1407                         if(yukkuri.isVeryKuhuku()){
1408                                 if(place.isFood()){
1409                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1410                                         this.action.setStatus(EAction.EAT_IN_HOME);
1411                                         return;
1412                                 }else{
1413                                         yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1414                                         //experience skill
1415                                         if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1416                                                 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1417                                                 this.action.setStatus(EAction.THINK);
1418                                                 return;
1419                                         }else{
1420                                                 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1421                                                 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1422                                         }
1423
1424                                 }
1425                         }
1426                         this.action.setStatus(EAction.WAIT);
1427                         var items = this.yukkuri.getItems();
1428                         if(items.length > 0){
1429                                 place.setItems(items);
1430                         }else{
1431
1432                         }
1433                         var sec = BASE_FPS * 10;
1434                         if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1435                         this.yukkuri.wait(sec, {
1436                                 "onactiontick": this.onactiontick(this),
1437                                 "onactionend": this.onactionend(this)
1438                         });
1439                 },
1440                 onactiontick:function(self){
1441                         return function(e){
1442                                 if(typeof e === "undefined")return;
1443                                 if(this.age%(BASE_FPS * 5) == 0){
1444                                         mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1445                                 }
1446                         };
1447                 },
1448                 onactionend:function(self){
1449                         return function(e){
1450                                 if(typeof e === "undefined")return;
1451                                 self.action.setStatus(EAction.THINK_IN_HOME);
1452                         };
1453                 }
1454         });
1455         var EatInHomeEvent = enchant.Class.create(Event,{
1456                 initialize: function (_data){
1457                         this.data = _data;
1458                         this.yukkuri = _data.myYukkuri;
1459                         this.place = _data.targetNode;
1460                         this.action = _data.action;
1461                         this.action.setStatus(EAction.EAT_WAIT);
1462
1463                         var sec = BASE_FPS * 3;
1464                         var foodHash = this.place.getFoodHash();
1465                         if(foodHash !== false && this.yukkuri.eat(foodHash)){
1466                                 mangMsg.output(this.yukkuri, EMsg.EAT);
1467                                 this.yukkuri.setFaceImage(EFace.EAT2);
1468                         }else{
1469                                 sec = BASE_FPS * 6;
1470                                 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1471                                 this.yukkuri.setFaceImage(EFace.CRY2);
1472                         }
1473
1474                         this.yukkuri.wait(sec, {
1475                                 "onactionend": this.onactionend(this)
1476                         });
1477                 },
1478                 onactionend:function(self){
1479                         return function(e){
1480                                 if(typeof e === "undefined")return;
1481                                 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1482                                         self.action.setStatus(EAction.EAT_IN_HOME);
1483
1484                                         // new EatInHomeEvent({
1485                                         //      "targetNode": self.place,
1486                                         //      "action": self.action,
1487                                         //      "myYukkuri": self.yukkuri
1488                                         // });
1489                                 }else{
1490                                         self.action.setStatus(EAction.THINK_IN_HOME);
1491                                         self.yukkuri.setFaceImage(EFace.NORMAL);
1492                                 }
1493                         };
1494                 }
1495         });
1496
1497
1498         var MoveToCommandEvent = enchant.Class.create(Event,{
1499                 initialize: function (_data){
1500                         this.data = _data;
1501                         this.yukkuri = this.data.myYukkuri;
1502                         this.action = this.data.action;
1503                         // this.vx = this.data.cmdObject.vx;
1504                         // this.vy = this.data.cmdObject.vy;
1505                         // var vx = (-backgroundMap.x + e.x) - this.ctl.player.getX() ;
1506
1507
1508                         var yukkuri = this.yukkuri;
1509                         this.action.status = EAction.WAIT;
1510                         yukkuri.vx = this.data.cmdObject.touchX - this.yukkuri.getX();
1511                         yukkuri.vy = this.data.cmdObject.touchY - this.yukkuri.getY();
1512                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1513                         var frame = distance + distance/2 + 1;
1514                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1515
1516                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1517
1518                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1519                                 "onactiontick": this.onactiontick(this),
1520                                 "onactionend": this.onactionend(this)
1521                         });
1522                 },
1523                 onactiontick:function(self){
1524                         return function(e){
1525                                 if(typeof e === "undefined")return;
1526                         };
1527                 },
1528                 onactionend:function(self){
1529                         return function(e){
1530                                 if(typeof e === "undefined")return;
1531                                 self.action.setStatus(EAction.THINK);
1532                         };
1533                 }
1534         });
1535         /**
1536          * Say hello contact to send communication .
1537          */
1538         var ComSayHelloSendEvent = enchant.Class.create(Event,{
1539                 initialize: function (_data){
1540                         this.data = _data;
1541                         this.yukkuri = _data.myYukkuri;
1542                         this.targetYukkuri = _data.targetNode;
1543                         this.action = _data.action;
1544                         this.action.setStatus(EAction.COMMUNICATE_WAIT);
1545                         // this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1546                         // this.targetYukkuri.tlPause();
1547                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1548                         this.yukkuri.send(this.targetYukkuri, {
1549                                 "actionStatus":EAction.COMMUNICATE_RECV,
1550                                 "yukkuri":this.yukkuri
1551                         });
1552
1553
1554                         this.yukkuri.tlPause();
1555                         this.yukkuri.syncDirection(this.targetYukkuri);
1556
1557                         this.yukkuri.addAddress(this.targetYukkuri);
1558                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1559
1560                         var sec = BASE_FPS * 2;
1561                         this.yukkuri.wait(sec, {
1562                                 "onactiontick": this.onactiontick(this),
1563                                 "onactionend": this.onactionend(this)
1564                         });
1565                 },
1566                 onactiontick:function(self){
1567                         return function(e){
1568                                 if(typeof e === "undefined")return;
1569                         };
1570                 },
1571                 onactionend:function(self){
1572                         return function(e){
1573                                 if(typeof e === "undefined")return;
1574                                 new ComSayHelloRecvEvent({
1575                                         "type": 'greeting',
1576                                         "targetNode": self.yukkuri,
1577                                         "action": self.targetYukkuri.action,
1578                                         "myYukkuri": self.targetYukkuri
1579                                 });
1580                         };
1581                 }
1582         });
1583         var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1584                 initialize: function (_data){
1585                         this.data = _data;
1586                         this.yukkuri = _data.myYukkuri;
1587                         this.targetYukkuri = _data.targetNode;
1588                         this.action = _data.action;
1589                         mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1590                         this.yukkuri.addAddress(this.targetYukkuri);
1591                         this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1592
1593                         var sec = BASE_FPS * 2;
1594                         this.yukkuri.wait(sec, {
1595                                 "onactiontick": this.onactiontick(this),
1596                                 "onactionend": this.onactionend(this)
1597                         });
1598                 },
1599                 onactiontick:function(self){
1600                         return function(e){
1601                                 if(typeof e === "undefined")return;
1602                         };
1603                 },
1604                 onactionend:function(self){
1605                         return function(e){
1606                                 if(typeof e === "undefined")return;
1607                                 self.action.setStatus(EAction.THINK);
1608
1609                                 self.yukkuri.action.setStatus(EAction.THINK);
1610                                 self.yukkuri.animation();
1611                                 self.targetYukkuri.action.setStatus(EAction.THINK);
1612                                 self.targetYukkuri.animation();
1613                         };
1614                 }
1615         });
1616         var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1617                 initialize: function (_data){
1618                         this.data = _data;
1619                         this.yukkuri = this.data.myYukkuri;
1620                         this.action = this.data.action;
1621
1622                         var yukkuri = this.yukkuri;
1623                         var node = this.data.targetNode;
1624
1625                         this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1626                         yukkuri.vx = node.x + node.width /2  - yukkuri.getX();
1627                         yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1628                         var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1629                         var frame = distance + distance/5 + 1;
1630                         frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1631
1632                         yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1633                         yukkuri.reverse();
1634                         yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1635                                 "onactionend": this.onactionend(this)
1636                         });
1637                 },
1638                 onactionend:function(self){
1639                         return function(e){
1640                                 if(typeof e === "undefined")return;
1641                                 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1642                                 self.data = null;
1643                                 self.yukkuri = null;
1644                                 self.action = null;
1645                         };
1646                 }
1647         });
1648         var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1649                 initialize: function (_data){
1650                         this.data = _data;
1651                         this.yukkuri = _data.myYukkuri;
1652                         this.place = _data.targetNode;
1653                         this.action = _data.action;
1654                         this.action.setStatus(EAction.WAIT);
1655
1656
1657                         var sec = BASE_FPS * 3;
1658                         this.yukkuri.declarePlace(this.place);
1659                         this.place.setOwner(this.yukkuri);
1660                         mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1661
1662                         this.yukkuri.setFaceImage(EFace.NORMAL);
1663                         this.yukkuri.wait(sec, {
1664                                 "onactionend": this.onactionend(this)
1665                         });
1666                 },
1667                 onactionend:function(self){
1668                         return function(e){
1669                                 if(typeof e === "undefined")return;
1670                                 self.action.setStatus(EAction.THINK);
1671                         };
1672                 }
1673         });
1674
1675         var Food = enchant.Class.create(ObjSprite,{
1676                 initialize: function (type, x, y){
1677                         this.classname = "Food";
1678                         //一つにつきgiveの値分、hunguryを減少させられる
1679                         if(type == "apple"){
1680                                 ObjSprite.call(this,16,16);
1681                                 this.image = game.assets[EResPath.OBJECT];
1682                                 this.frame = 15;
1683                                 this.give = 40;
1684                                 this.amount = 3;
1685                         }else if(type == "grass"){
1686                                 ObjSprite.call(this,64,64);
1687                                 this.image = game.assets[EResPath.GRASS];
1688                                 this.frame = 0;
1689                                 this.give = 10;
1690                                 this.amount = 20;
1691                         }
1692                         this.x = x;
1693                         this.y = y;
1694                         foodGroup.addChild(this);
1695                         this.addEventListener('enterframe', function(){
1696                                 if(this.amount <= 0){
1697                                         this.removeAll();
1698                                 }
1699                         });
1700                 },
1701                 getAmount: function(){
1702                         return this.amount;
1703                 },
1704                 getGive: function(){
1705                         return this.give;
1706                 }
1707         });
1708         var MemoryPlace = enchant.Class.create({
1709                 // initialize: function (place){
1710                 //      if(place.x != null){
1711                 //              this.isWorld = true;
1712                 //      }else{
1713                 //              this.isWorld = false;
1714                 //      }
1715                 //      this.isWorld = (place.x != null);
1716                 //      this.x = place.x;
1717                 //      this.y = place.y;
1718                 //      this.width = place.width;
1719                 //      this.height = place.height;
1720                 // },
1721                 // isWorld: function(){
1722                 //      return this.isWorld;
1723                 // }
1724
1725         });
1726         var MemoryFood = enchant.Class.create({
1727                 initialize: function (food){
1728                         if(food.x != null){
1729                                 this.isWorld = true;
1730                         }else{
1731                                 this.isWorld = false;
1732                         }
1733                         this.isWorld = (food.x != null);
1734                         this.x = food.x;
1735                         this.y = food.y;
1736                         this.width = food.width;
1737                         this.height = food.height;
1738                 },
1739                 isWorld: function(){
1740                         return this.isWorld;
1741                 }
1742         });
1743         var Place = enchant.Class.create(ObjSprite,{
1744                 initialize: function (type, x, y){
1745                         ObjSprite.call(this,128,128);
1746                         this.image = game.assets[EResPath.PLACE_TREE];
1747                         this.x = x - this.width / 2;
1748                         this.y = y - this.height / 2;
1749                         backgroundMap.addChild(this);
1750                         this.owner = null;
1751                         this.foods = [];
1752                         for(var key in EFood){
1753                                 var efood = EFood[key];
1754                                 this.foods[efood] = 0;
1755                         }
1756                         // this.addEventListener('enterframe', function(){
1757                         //      if(this.age%10 === 0 && this.age !== 0){
1758                         //              console.log("x/y " + this.x + "/" + this.y);
1759                         //      }
1760                         //      if(game.input.left){
1761                         //              this.x -= 10;;
1762                         //      }
1763                         //      if(game.input.right){
1764                         //              this.x += 10;;
1765                         //      }
1766                         //      if(game.input.up){
1767                         //              this.y -= 10;;
1768                         //      }
1769                         //      if(game.input.down){
1770                         //              this.y += 10;;
1771                         //      }
1772                         // });
1773                 },
1774                 getStatusForDisplay: function(){
1775                         var ret = "";
1776                         var ownerId = "なし";
1777                         if(this.owner == null)ownerId = "なし";
1778                         else ownerId = this.owner.id;
1779                         ret += "プレイスID " + this.id + "\n";
1780                         ret += "オーナーID " + ownerId + "\n";
1781                         ret += "食料うめぇ  " + this.foods[EFood.GREAT] + "\n";
1782                         ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1783                         ret += "食料にがにが  " + this.foods[EFood.BAD] + "\n";
1784                         return ret;
1785                 },
1786                 setItems:function(items){
1787                         var len = items.length;
1788                         for(var i=0; i<len; i++){
1789                                 var item = items[i];
1790                                 if(item instanceof Food){
1791                                         this.foods[EFood.NORMAL]++;
1792                                 }
1793                         }
1794                         items.length = 0;
1795                 },
1796                 isFood:function(){
1797                         var ret = 0;
1798                         for(var key in EFood){
1799                                 var efood = EFood[key];
1800                                 ret += this.foods[efood];
1801                         }
1802                         return ret !== 0;
1803                 },
1804                 getFoodHash:function(){
1805                         if(this.foods[EFood.GREAT] !== 0){
1806                                 this.foods[EFood.GREAT]--;
1807                                 return {give:20,yukkuri:15,unun:20};
1808                         }
1809                         else if(this.foods[EFood.NORMAL] !== 0){
1810                                 this.foods[EFood.NORMAL]--;
1811                                 return {give:10,yukkuri:5,unun:10};
1812                         }
1813                         else if(this.foods[EFood.BAD] !== 0){
1814                                 this.foods[EFood.BAD]--;
1815                                 return {give:10,yukkuri:-2,unun:10};
1816                         }
1817                         return false;
1818                 },
1819                 setOwner: function(yukkuri){
1820                         this.owner = yukkuri;
1821                 },
1822                 isOwner: function(){
1823                         return this.owner !== null;
1824                 }
1825         });
1826         var Unun = enchant.Class.create(ObjSprite,{
1827                 initialize: function (x, y){
1828                         this.classname = "Unun";
1829                         ObjSprite.call(this,32,32);
1830                         this.image = game.assets[EResPath.YUKKURI_UNUN];
1831                         this.x = x;
1832                         this.y = y;
1833                         backgroundMap.addChild(this);
1834                         // this.lifetime = 30 * 24 * 3;
1835                         this.lifetime = 15 * 24;
1836                         this.addEventListener('enterframe', this.runEnterframe(this));
1837                         // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1838
1839                 },
1840                 runEnterframe:function(self){
1841                         return function(e){
1842                                 if(typeof e === "undefined")return;
1843                                 if(this.age%BASE_FPS === 0 && this.age !== 0){
1844                                         self.lifetime--;
1845                                         if(self.lifetime <= 0){
1846                                                 this.parentNode.removeChild(this);
1847                                                 ctl.backgroundMap.removeChild(this);
1848                                                 ctl.removeObj(this);
1849                                                 self.image = null;
1850                                         }
1851                                 }
1852
1853                         };
1854                 }
1855         });
1856         var Okazari = enchant.Class.create(enchant.Sprite,{
1857                 initialize: function(yukkuri){
1858                         this.classname = "Okazari";
1859                         if(yukkuri.myCode === "REIMU"){
1860                                 enchant.Sprite.call(this, 80, 32);
1861                                 this.image = game.assets[EResPathReimu.OKAZARI];
1862                                 this.x = -CHARA_WIDTH / 2 - 1;
1863                                 this.y = 0;
1864                         }else{
1865                                 enchant.Sprite.call(this, 64, 64);
1866                                 this.image = game.assets[EResPath.MARISA_OKAZARI];
1867                                 this.x = -CHARA_WIDTH / 2;
1868                                 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1869                         }
1870                         this.yukkuri = yukkuri;
1871                 },
1872                 getWidth: function(){
1873                         return this.width;
1874                         // return this.width * this.yukkuri.myScaleX;
1875                 },
1876                 getHeight: function(){
1877                         return this.height;
1878                         // return this.height * this.yukkuri.myScaleY;
1879                 }
1880         });
1881         var Kuki = enchant.Class.create(ObjSprite,{
1882                 initialize: function(yukkuri, x, y){
1883                         this.classname = "Kuki";
1884                         enchant.Sprite.call(this, 56, 40);
1885                         this.image = game.assets[EResPath.KUKI];
1886                         this.x = 0 + x;
1887                         this.y = -CHARA_HEIGHT / 2 -CHARA_HEIGHT / 4 + y;
1888                         this.owner = yukkuri;
1889                         this.miYukkuris = [];
1890                 },
1891                 addMiYukkuri: function(miYukkuri){
1892                         miYukkuri.setX(miYukkuri.getX() + 30);
1893                         miYukkuri.setY(miYukkuri.getY() - 30);
1894                         this.miYukkuris.push(miYukkuri);
1895                 },
1896                 getX : function(){
1897                         return this.x;
1898                 },
1899                 getY : function(){
1900                         return this.y;
1901                 },
1902                 getWidth: function(){
1903                         return this.width;
1904                         // return this.width * this.yukkuri.myScaleX;
1905                 },
1906                 getHeight: function(){
1907                         return this.height;
1908                         // return this.height * this.yukkuri.myScaleY;
1909                 }
1910         });
1911         var Address = enchant.Class.create({
1912                 initialize: function(yukkuri){
1913                         this.friendlyLv = 1;
1914                         this.yukkuri = yukkuri;
1915                         this.isGreeting = false;
1916                         this.greetingWaitFrame = 0;
1917                         this.comMatrix = {
1918                                 "beginSayHello" : false,
1919                                 "sayHello" : false,
1920                         };
1921                         this.evtHash = {};
1922                 },
1923                 set:function(key, value){
1924                         this.comMatrix[key] = value;
1925                 },
1926                 get:function(key){
1927                         return this.comMatrix[key];
1928                 }
1929         });
1930
1931         var Yukkuri = enchant.Class.create(ObjSprite,{
1932                 initialize: function(x, y, grow){
1933                         ObjSprite.call(this, 64, 64);
1934                         this.searchObjectMang = new SearchObjectMang();
1935                         this.grow = grow;
1936                         //base plyaer only
1937                         this.cmdQueue = [];
1938                         this.myCode = "YUKKURI";
1939                         this.myName = "ゆっくり";
1940                         this.beforeHuntingFood = null;
1941                         if(grow == EGrow.ADULT){
1942                                 this.myScaleX = 1;
1943                                 this.myScaleY = 1;
1944                                 this.mySize = "L";
1945                         }
1946                         else if(grow == EGrow.SUBADULT){
1947                                 this.myScaleX = 0.8;
1948                                 this.myScaleY = 0.8;
1949                                 this.mySize = "M";
1950                         }
1951                         else if(grow == EGrow.CHILD){
1952                                 this.myScaleX = 0.6;
1953                                 this.myScaleY = 0.6;
1954                                 this.mySize = "S";
1955                         }
1956                         else if(grow == EGrow.BABY){
1957                                 this.myScaleX = 0.3;
1958                                 this.myScaleY = 0.3;
1959                                 this.mySize = "SS";
1960                         }
1961                         else if(grow == EGrow.FRUIT_BABY){
1962                                 this.myScaleX = 0.2;
1963                                 this.myScaleY = 0.2;
1964                                 this.mySize = "SSS";
1965                         }
1966
1967                         // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1968                         this.classname = "Yukkuri";
1969                         this.addressBook = {};
1970                         // this.imgGroup = new SpriteGroup();
1971                         // this.imgBody = new SpriteGroup();
1972                         // this.imgGroup.id = guid();
1973                         // this.imgBody.id = guid();
1974                         this.x = -CHARA_WIDTH / 2;
1975                         this.y = -CHARA_HEIGHT / 2;
1976                         this.vx = 0;
1977                         this.vy = 0;
1978                         this.image = game.assets[EResPath.YUKKURI_BASE];
1979                         this.direction = EDirection.RIGHT;
1980                         this.addEventListener('enterframe', this.runEnterframe);
1981                         this.bodyStatus ={};
1982                         this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1983                         this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1984                         this.walkAnimationStatus = EWalkAnimation.END;
1985                         this.place = null;
1986                         this.items = [];
1987                         this.actionQueue = [];
1988                         this.exLvHash = {};
1989                         this.exValueHash = {};
1990                         this.memoryHash = {};
1991                         this.communicateYukkuri = {};
1992                         for(var _v in EExSkill){
1993                                 var key = EExSkill[_v];
1994                                 this.exLvHash[key] = 0;
1995                                 this.exValueHash[key] = 0;
1996                         }
1997                         this.kukis = [];
1998                         this.formSprite = new FormSprite();
1999                 },
2000                 runEnterframe:function(){
2001                         // console.log("runEnterframe");
2002                                 // this.formSprite.run();
2003                                 // this.formSprite.addX(1);
2004
2005                         // try{
2006                                 if(this.grow == EGrow.FRUIT_BABY){
2007                                 }else{
2008                                         if(this.kukis){
2009                                                 // this.kukis[0].miYukkuris[0].setX(this.getX());
2010                                                 // this.kukis[0].miYukkuris[0].setY(this.getY());
2011                                                 // var _x = this.imgBody.tl.node.x;
2012                                                 // var _y = this.imgBody.tl.node.y;
2013                                                 // var _gety = this.kukis[0].miYukkuris[0].getY();
2014                                                 // this.kukis[0].miYukkuris[0].setOldY();
2015                                                 // this.kukis[0].miYukkuris[0].animY(-_y);
2016                                         }
2017                                         // console.log(this.getX() + ":" + this.getY());
2018                                         this.act();
2019                                         if(this.isDead())return;
2020                                         this.runYukkuri();
2021                                         this.runHungry();
2022                                         this.runUnun();
2023                                         this.runSleep();
2024                                         this.runAddress();
2025                                         this.formSprite.animation();
2026
2027                                 }
2028                         // }catch(e){
2029                         //      console.log(e);
2030                         // }
2031                 },
2032                 reverse:function(){
2033                         if(this.direction == EDirection.RIGHT){
2034                                 this.formSprite.formScaleX(this.myScaleX);
2035                                 // this.formSprite.formScaleY(this.myScale);
2036
2037                                 // this.imgBody.scaleX = 1;
2038                         }
2039                         else if(this.direction == EDirection.LEFT){
2040                                 this.formSprite.formScaleX(-this.myScaleX);
2041                                 // this.formSprite.formScaleY(this.myScale);
2042                                 // this.imgBody.scaleX = -1;
2043                         }
2044                 },
2045                 tweet:function(text){
2046                         text = text.replace(/%name%/g, this.myName);
2047                         // this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
2048                         this._tweet.text(text, this.getX() - this._tweet.width/4, this.getY() - this._tweet.height);
2049                 },
2050                 moveTo:function(x, y, time){
2051                         this.formSprite.tlMoveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
2052                         // this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
2053                 },
2054                 moveBy:function(x, y, time, eventFunctions){
2055                         this.formSprite.tlMoveBy(x, y, time, eventFunctions);
2056                         // var self = this;
2057                         // var params = {
2058                         //      x: function() {
2059                         //              return self.getX() + x;
2060                         //              // return self.imgGroup.x + x;
2061                         //      },
2062                         //      y: function() {
2063                         //              return self.getY() + y;
2064                         //              // return self.imgGroup.y + y;
2065                         //      },
2066                         //      time: time,
2067                         //      easing: enchant.Easing.SIN_EASEINOUT
2068                         // };
2069                         // //-Event register [onactionstart,onactiontick,onactionend]
2070                         // if(eventFunctions !== undefined){
2071                         //      for(var key in eventFunctions){
2072                         //              params[key] = eventFunctions[key];
2073                         //      }
2074                         // }
2075                         // console.log("moveBy");
2076                         // console.log("self.x:" + self.getX());
2077                         // return this.formSprite.tlTween(params);
2078                         // // return this.imgGroup.tl.tween(params);
2079                 },
2080                 wait:function(frame, eventFunctions){
2081                         this.moveBy(0,0,frame,eventFunctions);
2082                 },
2083                 act: function(){
2084                         this.action.act();
2085                 },
2086
2087                 animation: function(){
2088                         this.formSprite.animation();
2089                         // var frame = 10;
2090                         // frame -= plusFrameScale(frame, this.getMyScale()) / 2;
2091                         // var move = 5;
2092                         // move -= plusFrameScale(move, this.getMyScale());
2093                         // if(this.walkAnimationStatus == EWalkAnimation.END){
2094                         //      this.imgBody.y = 0;
2095                         //      this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
2096                         //              "onactionstart": function(e){
2097                         //                      this.walkAnimationStatus = EWalkAnimation.START;
2098                         //              }
2099                         //      })
2100                         //      .moveByEx(0, move, frame, enchant.Easing.SWING,
2101                         //      {
2102                         //              "onactionend": function(e){
2103                         //                      this.walkAnimationStatus = EWalkAnimation.END;
2104                         //              }
2105                         //      }).loop();
2106                         // }else{
2107                         //      this.imgBody.tl.loop();
2108                         // }
2109                 },
2110                 getMyScale: function(){
2111                         return (this.myScaleX + this.myScaleY) / 2;
2112                 },
2113                 getWidth: function(){
2114                         return this.width * this.myScaleX;
2115                 },
2116                 getHeight: function(){
2117                         return this.height * this.myScaleY;
2118                 },
2119                 setX: function(x){
2120                         this.formSprite.setX(x);
2121                         // this.imgGroup.x = x;
2122                 },
2123                 setY: function(y){
2124                         this.formSprite.setY(y);
2125                         // this.imgGroup.y = y;
2126                 },
2127                 getX: function(){
2128                         return this.formSprite.getX();
2129                         // return this.imgGroup.x;
2130                 },
2131                 getY: function(){
2132                         return this.formSprite.getY();
2133                         // return this.imgGroup.y;
2134                 },
2135                 moveX: function(x){
2136                         this.formSprite.addX(x);
2137                         // this.imgGroup.x += x;
2138                 },
2139                 moveY: function(y){
2140                         this.formSprite.addY(y);
2141                         // this.imgGroup.y += y;
2142                 },
2143                 // changeFace: function(erespath){
2144                 //      this.face.image = game.assets[erespath];
2145                 // },
2146                 loadParamsXML: function(url){
2147                         var http = new JKL.ParseXML( url );
2148                         return http.parse();
2149                 },
2150                 runYukkuri: function(){
2151                         if(this.param.hungry > 70){
2152                                 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
2153                                         this.param.yukkuri -= 1;
2154                                 }
2155                         }
2156                         else if(this.param.hungry < 10){
2157                                 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
2158                         }
2159
2160                         if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
2161                         else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
2162                 },
2163                 runHungry: function(){
2164                         if(this.age%50 === 0 && this.age !== 0)this.param.hungry += ADD_HUNGRY;
2165                         if(this.param.hungry >= 100)this.param.hungry = 100;
2166                 },
2167                 runUnun: function(){
2168                         if(this.age%50 === 0 && this.age !== 0)this.param.unun += 1;
2169                         if(this.param.unun >= 100)this.param.unun = 100;
2170                 },
2171                 runSleep: function(){
2172                         if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
2173                                 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
2174                                 if(this.param.sleep >= 100){
2175                                         this.param.sleep = 100;
2176                                 }
2177                         }
2178                 },
2179                 runAddress: function(){
2180                         for(var key in this.addressBook){
2181                                 var address = this.addressBook[key];
2182                                 //挨拶時間。24時間に1度だけ。
2183                                 if(address.isGreeting){
2184                                         address.greetingWaitFrame++;
2185                                         if(address.greetingWaitFrame >= DAY){
2186                                                 address.greetingWaitFrame = 0;
2187                                                 address.isGreeting = false;
2188                                         }
2189                                 }
2190                         }
2191                 },
2192                 changeFace: function(){
2193                         if(this.param.yukkuri >= 80){
2194                                 this.setFaceImage(EFace.HAPPY1);
2195                         }
2196                         else if(this.param.yukkuri >= 50){
2197                                 this.setFaceImage(EFace.NORMAL);
2198                         }
2199                         else if(this.param.yukkuri >= 30){
2200                                 this.setFaceImage(EFace.TIRED);
2201                         }
2202                         else if(this.param.yukkuri >= 10){
2203                                 this.setFaceImage(EFace.CRY1);
2204                         }
2205                         else if(this.param.yukkuri >= 1){
2206                                 this.setFaceImage(EFace.CRY2);
2207                         }
2208                 },
2209                 getRange: function(){
2210                         return this.param.range;
2211                 },
2212                 isSleep: function(){
2213                         return this.param.sleep >= 100;
2214                 },
2215                 isDead: function(){
2216                         return this.param.yukkuri <= 0;
2217                 },
2218                 isManpuku: function(){
2219                         return this.param.hungry <= 20;
2220                 },
2221                 isKuhuku: function(){
2222                         return this.param.hungry >= 40;
2223                 },
2224                 isVeryKuhuku: function(){
2225                         return this.param.hungry >= 80;
2226                 },
2227                 getYukkuri: function(){
2228                         return this.param.yukkuri;
2229                 },
2230                 setYukkuri: function(yukkuri){
2231                         this.param.yukkuri = yukkuri;
2232                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2233                 },
2234                 addYukkuri: function(yukkuri){
2235                         this.param.yukkuri += yukkuri;
2236                         if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2237                 },
2238                 getHungry: function(){
2239                         return this.param.hungry;
2240                 },
2241                 setHungry: function(hungry){
2242                         this.param.hungry = hungry;
2243                         if(this.param.hungry < 0)this.param.hungry = 0;
2244                 },
2245                 getUnun: function(){
2246                         return this.param.unun;
2247                 },
2248                 setUnun: function(unun){
2249                         this.param.unun = unun;
2250                         if(this.param.unun < 0)this.param.unun = 0;
2251                 },
2252
2253                 eat:function(food){
2254                         if(food instanceof Food){
2255                                 //Food object case
2256                                 if(food.amount > 0){
2257                                         food.amount--;
2258                                         this.setHungry(this.param.hungry - food.getGive());
2259                                         this.setUnun(this.getUnun() + food.getGive() / 4);
2260                                         this.setYukkuri(this.getYukkuri() + 5);
2261                                         return true;
2262                                 }else{
2263                                         this.setYukkuri(this.getYukkuri() - 5);
2264                                         return false;
2265                                 }
2266                         }else{
2267                                 //hash case
2268                                 if(food != null){
2269                                         this.setHungry(this.param.hungry - food.give);
2270                                         this.setUnun(this.getUnun() + food.unun);
2271                                         this.setYukkuri(this.getYukkuri() + food.yukkuri);
2272                                         return true;
2273                                 }else{
2274                                         return false;
2275                                 }
2276                         }
2277                 },
2278                 hunt:function(food){
2279                         if(food.amount > 0){
2280                                 if(!this.isItemsMax()){
2281                                         food.amount--;
2282                                         this.items.push(food);
2283                                         this.setYukkuri(this.getYukkuri() + 1);
2284                                         return true;
2285                                 }
2286                         }
2287                         return false;
2288                 },
2289                 declarePlace: function(place){
2290                         this.place = place;
2291                 },
2292                 getPlace:function(){
2293                         return this.place;
2294                 },
2295                 isPlace: function(){
2296                         return this.place !== null;
2297                 },
2298
2299                 unun:function(){
2300                         if(this.direction == EDirection.RIGHT){
2301                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2302                         }else{
2303                                 new Unun(this.getX() -  this.getWidth()/5, this.getY() + this.getHeight()/5 );
2304                         }
2305                         // if(this.direction == EDirection.RIGHT){
2306                         //      new Unun(this.getX() + this.getWidth()/2 - this.getWidth()/5, this.getY() + this.getHeight() / 2 +  this.getHeight() / 5 );
2307                         // }else{
2308                         //      new Unun(this.getX() + this.getWidth()/2 - this.getWidth()/5, this.getY() + this.getHeight() / 2 + this.getHeight() / 5 );
2309                         // }
2310                         this.setUnun(0);
2311                 },
2312                 setBodyImage: function(ebody){
2313                         var path = this.bodyStatus[ebody];
2314                         this.image = game.assets[path];
2315                 },
2316                 tlPause:function(){
2317                         // this.imgBody.tl.clear();
2318                         // this.imgGroup.tl.clear();
2319                         // this.imgBody.tl.unloop();
2320                         // this.imgGroup.tl.unloop();
2321                         // this.imgBody.y = 0;
2322
2323                 },
2324                 tlResume: function(){
2325                         // this.imgBody.tl.resume();
2326                         // this.imgGroup.tl.resume();
2327                         this.animation();
2328                 },
2329                 syncDirection:function(senderYukkuri){
2330                         if(this.getX() > senderYukkuri.getX()){
2331                                 this.direction = EDirection.LEFT;
2332                                 senderYukkuri.direction = EDirection.RIGHT;
2333                         }else{
2334                                 this.direction = EDirection.RIGHT;
2335                                 senderYukkuri.direction = EDirection.LEFT;
2336                         }
2337                 },
2338                 isCommunication: function(yukkuri){
2339                         if(this.addressBook[yukkuri.id] === undefined) return true;
2340                         if(this.addressBook[yukkuri.id].isGreeting) return false;
2341                         return true;
2342                 },
2343                 addAddress: function(yukkuri){
2344                         this.addressBook[yukkuri.id] = new Address(yukkuri);
2345                 },
2346                 getAddress: function(yukkuri){
2347                         if(this.addressBook[yukkuri.id] === undefined)return null;
2348                         return this.addressBook[yukkuri.id];
2349                 },
2350                 getStatusForDisplay: function (){
2351                         var ret = "";
2352                         var placeId = (this.place==null)?"無し" : this.place.id;
2353                         ret += "ID " + this.id + "\n";
2354                         ret += "プレイス  " + placeId + "\n";
2355                         ret += "ゆっくり  " + this.getYukkuri() + "\n";
2356                         ret += "空腹  " + this.getHungry() + "\n";
2357                         ret += "うんうん  " + this.getUnun() + "\n";
2358                         ret += "もちもの  " + this.items.length + "\n";
2359                         ret += "debug  " + this.action.status + "\n";
2360                         return ret;
2361                 },
2362                 isItemsMax:function(){
2363                         return this.items.length >= this.param.items_max;
2364                 },
2365                 getItems:function(){
2366                         return this.items;
2367                 },
2368                 addSearchObject:function(esearch, node){
2369                         this.searchObjectMang.add(esearch, node)
2370                 },
2371                 clearSearchObject:function(){
2372                         this.searchObjectMang.clear()
2373                 },
2374                 setFaceImage: function(eface){
2375                         var path = this.faceStatus[eface];
2376                         this.face.image = game.assets[path];
2377                 },
2378                 myScale: function(_scaleX, _scaleY){
2379                         this.formSprite.scale(_scaleX, _scaleY);
2380                         // this.face.scale(_scaleX,_scaleY);
2381                         // if(this.myCode === "REIMU"){
2382                         //      // this.okazari.x = -this.okazari.width / 2;
2383                         //      // this.okazari.y = -CHARA_HEIGHT  / 2 + (this.okazari.height * (1 - _scaleY)) / 2;
2384                         // }else{
2385                         //      // this.okazari.x = -CHARA_WIDTH /2;
2386                         //      // this.okazari.y = -CHARA_HEIGHT / 2 - (CHARA_HEIGHT * _scaleY)/6;
2387                         // }
2388                         // if(this.sub1 != null){
2389                         //      this.sub1.scale(_scaleX,_scaleY);
2390                         // }
2391
2392                         // this.okazari.scale(_scaleX,_scaleY);
2393                         // this.hear.scale(_scaleX,_scaleY);
2394                         // this.scale(_scaleX,_scaleY);
2395                         // if(this.shadow)this.shadow.scale(_scaleX, _scaleY);
2396                 },
2397                 send: function(targetYukkuri, object, callback){
2398                         this.communicateYukkuri = targetYukkuri;
2399                         targetYukkuri.recv(object, callback);
2400                 },
2401                 recv: function(object, callback){
2402                         this.communicateYukkuri = object.yukkuri;
2403                         this.tlPause();
2404                         this.action.setStatus(object.actionStatus);
2405
2406                         // this.actionQueue.push({
2407                         //      object : object,
2408                         //      callback: callback
2409                         // });
2410                 },
2411                 addExValue: function(eexskill, plus){
2412                         this.exValueHash[eexskill] += plus;
2413                         if(this.exValueHash[eexskill] >= 100){
2414                                 this.exLvHash[eexskill] = 1;
2415                         }
2416                 },
2417                 getExValue: function(eexskill){
2418                         return this.exValueHash[eexskill];
2419                 },
2420                 getExSkill: function(eexskill){
2421                         return this.exLvHash[eexskill];
2422                 },
2423
2424                 setMemory: function(ememory, value){
2425                         this.memoryHash[ememory] = value;
2426                 },
2427                 getMemory: function(ememory){
2428                         return this.memoryHash[ememory];
2429                 },
2430                 damage: function(edamage){
2431                         if(edamage == EDamage.PICOHAN){
2432                                 mangMsg.output(this, EMsg.DAMAGE);
2433                                 this.setFaceImage(EFace.CRY1);
2434                                 this.addYukkuri(-1);
2435                                 //現在の行動パターンから躾対象かセレクトする
2436                         }
2437                 },
2438                 addKuki: function(){
2439                         for(var i=0;i<this.kukis.length;i++){
2440                                 if(this.kukis[i].opacity == 0){
2441                                         this.kukis[i].opacity = 1.0;
2442                                         var miMarisa = new MiMarisa(this.getX(), this.getY());
2443                                         
2444                                         // console.log(this.imgBody);
2445                                         // this.imgBody.addChild(miMarisa);
2446                                         this.kukis[i].addMiYukkuri(miMarisa);
2447                                         break;
2448                                 }
2449                         }
2450                 },
2451                 destruct: function(){
2452
2453                 }
2454         });
2455         // var MiYukkuri = enchant.Class.create(Yukkuri,{
2456         //      initialize: function(x, y, grow){
2457         //              Yukkuri.call(this,x,y, EGrow.FRUIT_BABY);
2458         //              this.oldX = x;
2459         //              this.oldY = y;
2460         //      },
2461         //      setOldY: function(){
2462         //              this.imgGroup.y = this.oldY;
2463
2464         //      },
2465         //      animX: function(x){
2466         //              this.oldX = this.imgGroup.x;
2467         //              this.imgGroup.x -= x;
2468         //      },
2469         //      animY: function(y){
2470         //              this.imgGroup.y = this.oldY;
2471         //              // this.oldY = this.imgGroup.y;
2472         //              this.imgGroup.y -= y;
2473         //      }
2474         // }); 
2475         // var MiMarisa = enchant.Class.create(MiYukkuri,{
2476         //      initialize: function(x, y, grow){
2477         //              MiYukkuri.call(this,x,y, EGrow.FRUIT_BABY);
2478         //              this.classname = "MiMarisa";
2479         //              this.myCode = "MIMARISA";
2480         //              this.myName = "実まりさ";
2481
2482         //              this.param = new MarisaParam();
2483         //              this.param.range = 0;
2484         //              this.param.looks = ELooks.GOOD_YUKKURI;
2485
2486
2487         //              this.face = new enchant.Sprite(64, 64);
2488         //              this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2489         //              this.face.x = -CHARA_WIDTH / 2;
2490         //              this.face.y = -CHARA_HEIGHT / 2;
2491
2492         //              this.faceStatus ={};
2493         //              this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2494         //              this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2495         //              this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2496         //              this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2497         //              this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2498         //              this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2499         //              this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2500         //              this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2501         //              this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2502         //              this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2503
2504         //              this.hear = new enchant.Sprite(64, 64);
2505         //              this.hear.image = game.assets[EResPath.MARISA_HEAR];
2506         //              this.hear.x = -CHARA_WIDTH / 2;
2507         //              this.hear.y = -CHARA_HEIGHT / 2;
2508
2509         //              this.okazari = new Okazari(this);
2510
2511
2512         //              // this.imgBody.addChild(this);
2513         //              // this.imgBody.addChild(this.face);
2514         //              // this.imgBody.addChild(this.hear);
2515         //              // this.imgBody.addChild(this.okazari);
2516         //              this.myScale(this.myScaleX, this.myScaleY)
2517         //              // this.imgGroup.width = this.getWidth();
2518         //              // this.imgGroup.height = this.getHeight();
2519         //              // this.imgGroup.addChild(this.imgBody);
2520         //              // this.imgGroup.flgMiYukkuri = true;
2521         //              // backgroundMap.addChild(this.imgGroup);
2522         //              this._tweet = new TTweet(148, 64);
2523
2524         //              this.imgGroup.addChild(this._tweet);
2525         //              this.imgGroup.x = x;
2526         //              this.imgGroup.y = y;
2527
2528         //              this.action = new Action(this);
2529         //              ctl.addObj(this);
2530         //      }
2531
2532         // });
2533         var Marisa = enchant.Class.create(Yukkuri,{
2534                 initialize: function(x, y, grow){
2535                         Yukkuri.call(this,x,y, grow);
2536                         this.classname = "Marisa";
2537                         this.myCode = "MARISA";
2538                         this.myName = "まりさ";
2539
2540                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2541                         // var json = net.load("./data/marisa/params.json");
2542                         // this.param = json.root.param;
2543                         this.param = new MarisaParam();
2544                         this.param.looks = ELooks.GOOD_YUKKURI;
2545                         if(this.grow == EGrow.BABY){
2546                                 this.myName = "まりちゃ";
2547                                 this.param.range /= 4;
2548                         }
2549                         else if(this.grow == EGrow.CHILD){
2550                                 this.param.range /= 3;
2551                         }
2552                         else if(this.grow == EGrow.SUBADULT){
2553                                 this.param.range *= 0.8;
2554                         }else{
2555                         }
2556                         this.shadow = new enchant.Sprite(64, 64);
2557                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2558                         this.shadow.x = 0 + this.x;
2559                         this.shadow.y = this.getHeight() / 16 + this.y;
2560
2561                         this._style.zIndex = 5;
2562
2563                         this.face = new enchant.Sprite(64, 64);
2564                         this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2565                         this.face.x = -CHARA_WIDTH / 2;
2566                         this.face.y = -CHARA_HEIGHT / 2;
2567
2568                         this.faceStatus ={};
2569                         this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2570                         this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2571                         this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2572                         this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2573                         this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2574                         this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2575                         this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2576                         this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2577                         this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2578                         this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2579
2580
2581                         this.hear = new enchant.Sprite(64, 64);
2582                         this.hear.image = game.assets[EResPath.MARISA_HEAR];
2583                         this.hear.x = -CHARA_WIDTH / 2;
2584                         this.hear.y = -CHARA_HEIGHT / 2;
2585
2586                         this.okazari = new Okazari(this);
2587
2588                         this.kukis = [];
2589                         this.kukis[0] = new Kuki(this, 0, 0);
2590                         this.kukis[1] = new Kuki(this, 10, 0);
2591                         this.kukis[2] = new Kuki(this, 5, 5);
2592                         this.kukis[3] = new Kuki(this, -5, 5);
2593                         this._tweet = new TTweet(this, 148, 64);
2594
2595                         this.formSprite.add(this.shadow,0,{type:"shadow",scaleValue:this.myScaleY});
2596                         this.formSprite.add(this, 1, {
2597                                 mainIndexFlg:true,
2598                                 type : "body",
2599                                 scaleValue:this.myScaleY
2600                         });
2601                         this.formSprite.add(this.face,2,{type:"body",scaleValue:this.myScaleY});
2602                         this.formSprite.add(this.hear,3,{type:"body",scaleValue:this.myScaleY});
2603                         this.formSprite.add(this.okazari,4,{type:"body",scaleValue:this.myScaleY});
2604                         this.formSprite.add(this._tweet,5,{type:"tweet",scaleValue:this.myScaleY});
2605                         this.formSprite.addChildAll();
2606                         this.formSprite.setX(x);
2607                         this.formSprite.setY(y);
2608                         // App.backgroundMap.addChild(this._tweet);
2609                         // this.imgGroup.addChild(this.shadow);
2610                         // this.imgBody.addChild(this);
2611                         // this.imgBody.addChild(this.face);
2612                         // this.imgBody.addChild(this.hear);
2613                         // this.imgBody.addChild(this.okazari);
2614                         // for(var i=0;i<this.kukis.length;i++){
2615                         //      this.imgBody.addChild(this.kukis[i]);
2616                         //      this.kukis[i].opacity = 0;
2617                         // }
2618                         // this.kuki = ;
2619                         // this.imgBody.addChild(new Kuki(this));
2620                         this.myScale(this.myScaleX, this.myScaleY)
2621                         if(this instanceof Player){
2622                                 // this.myScaleX = 0.5;
2623                                 // this.myScaleY = 0.5;
2624
2625                                 this.budge = new enchant.Sprite(16, 16);
2626                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2627                                 // this.imgBody.addChild(this.budge);
2628                                 this.budge.x -= this.getWidth()/2;
2629                                 this.budge.y -= this.getHeight()/2;
2630                                 this.budge.scale(this.myScaleX, this.myScaleX);
2631                         }
2632                         // this.imgGroup.width = this.getWidth();
2633                         // this.imgGroup.height = this.getHeight();
2634                         // this.imgGroup.addChild(this.imgBody);
2635
2636                         // backgroundMap.addChild(this.imgGroup);
2637                         // this._tweet = new TTweet(148, 64);
2638
2639                         // this.imgGroup.addChild(this._tweet);
2640                         // this.imgGroup.x = x;
2641                         // this.imgGroup.y = y;
2642
2643                         this.animation();
2644                         this.action = new Action(this);
2645                         ctl.addObj(this);
2646                 }
2647         });
2648         var Player = enchant.Class.create(Marisa,{
2649                 initialize: function(x, y, grow){
2650                         // this.runEnterframe = function(){
2651                         // },
2652                         if(grow === undefined)grow = EGrow.ADULT;
2653                         Marisa.call(this, x, y, grow);
2654                         this.classname = "Player";
2655                         ctl.setPlayer(this);
2656                         // this.removeEventListener('enterframe',this.runEnterframe);
2657                         this.addEventListener('enterframe', function(){
2658
2659                                 if(this.age%10 === 0 && this.age !== 0){
2660                                         // console.log("palyer:" + this.age);
2661                                 }
2662                                 // this.act();
2663                                 ///////////////////////////////////////////////
2664                                 //Action pattern  debug
2665                                 if(game.input.left){
2666                                         // this.changeFace(EResPath.MARISA_FACE_TIRED);
2667                                         this.moveX(-10);
2668                                         this.direction = EDirection.LEFT;
2669                                 }
2670                                 if(game.input.right){
2671                                         for(var i=0;i<this.formSprite.spriteArray.length;i++){
2672                                                 var spr = this.formSprite.spriteArray[i];
2673                                                 console.log(i+":spry:" + spr.y);
2674                                         }
2675                                         this.moveX(10);
2676                                         this.direction = EDirection.RIGHT;
2677                                 }
2678                                 if(game.input.up){
2679                                         this.moveY(-10);
2680                                 }
2681                                 if(game.input.down){
2682                                         this.moveY(10);
2683                                 }
2684
2685                                 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2686                                 ///////////////////////////////////////////////
2687                                 // this.reverse();
2688                                 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2689                                 //      console.log("hit:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.height/2) );
2690                                 // }else{
2691                                 //      console.log("not:" + this.imgGroup.x + ":" +  (this.imgGroup.y + this.image.height/2));
2692                                 // }
2693                                 //- Display the circle of search range.
2694                                 // fieldBg.image.clear();
2695                                 // fieldBg.image.context.beginPath();
2696                                 // fieldBg.image.context.fillStyle = '#ff0000';
2697                                 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2698                                 // fieldBg.image.context.fill();
2699                         });
2700                 }
2701         });
2702         var Reimu = enchant.Class.create(Yukkuri,{
2703                 initialize: function(x, y, grow){
2704                         Yukkuri.call(this,x,y, grow);
2705                         this.classname = "Reimu";
2706                         this.myCode = "REIMU";
2707                         this.myName = "れいむ";
2708
2709                         // var xml = this.loadParamsXML("./data/marisa/params.xml");
2710                         // var json = net.load("./data/reimu/params.json");
2711                         // this.param = json.root.param;
2712                         this.param = new ReimuParam();
2713                         if(this.grow == EGrow.BABY){
2714                                 this.myName = "れいみゅ";
2715                                 this.param.range /= 4;
2716                         }
2717                         else if(this.grow == EGrow.CHILD){
2718                                 this.param.range /= 3;
2719                         }
2720                         else if(this.grow == EGrow.SUBADULT){
2721                                 this.param.range *= 0.8;
2722                         }
2723                         this.shadow = new enchant.Sprite(64, 64);
2724                         this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2725                         this.shadow.x = 0 + this.x;
2726                         this.shadow.y = this.getWidth() / 16 + this.x;
2727                         this.shadow.image._element.style.zIndex = 2;
2728
2729                         this._style.zIndex = 5;
2730
2731                         this.face = new enchant.Sprite(64, 64);
2732                         this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2733                         this.face.x = -CHARA_WIDTH / 2;
2734                         this.face.y = -CHARA_HEIGHT / 2;
2735                         this.face._style.zIndex = 0;
2736
2737                         this.faceStatus ={};
2738                         this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2739                         this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2740                         this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2741                         this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2742                         this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2743                         this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2744                         this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2745                         this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2746                         this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2747                         this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2748
2749
2750                         this.hear = new enchant.Sprite(64, 64);
2751                         this.hear.image = game.assets[EResPathReimu.HEAR];
2752                         this.hear.x = -CHARA_WIDTH / 2;
2753                         this.hear.y = -CHARA_HEIGHT / 2;
2754
2755                         this.sub1 = new enchant.Sprite(64, 64);
2756                         this.sub1.image = game.assets[EResPathReimu.SUB1];
2757                         this.sub1.x = -CHARA_WIDTH / 2;
2758                         this.sub1.y = -CHARA_HEIGHT / 2;
2759
2760                         this.okazari = new Okazari(this);
2761
2762
2763                         // this.imgGroup.addChild(this.shadow);
2764                         // this.imgBody.addChild(this.okazari);
2765                         // this.imgBody.addChild(this);
2766                         // this.imgBody.addChild(this.face);
2767                         // this.imgBody.addChild(this.hear);
2768                         // this.imgBody.addChild(this.sub1);
2769                         this.myScale(this.myScaleX, this.myScaleY)
2770                         if(this instanceof Player){
2771                                 this.budge = new enchant.Sprite(16, 16);
2772                                 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2773                                 this.imgBody.addChild(this.budge);
2774                                 this.budge.x -= this.getWidth()/2;
2775                                 this.budge.y -= this.getHeight()/2;
2776                                 this.budge.scale(this.myScaleX, this.myScaleX);
2777                         }
2778                         // this.imgGroup.width = this.getWidth();
2779                         // this.imgGroup.height = this.getHeight();
2780                         // this.imgGroup.addChild(this.imgBody);
2781                         // backgroundMap.addChild(this.imgGroup);
2782                         this._tweet = new TTweet(this, 148, 64);
2783                         backgroundMap.addChild(this._tweet);
2784
2785
2786                         // this.imgGroup.addChild(this._tweet);
2787                         // this.imgGroup.x = x;
2788                         // this.imgGroup.y = y;
2789
2790                         this.animation();
2791                         this.action = new Action(this);
2792                         ctl.addObj(this);
2793                         this.exLvHash[EExSkill.KEKKAI] = 1;
2794                         this.exValueHash[EExSkill.KEKKAI] = 100;
2795                 }
2796         });
2797
2798         game.onload = function(){
2799                 def.Food = Food;
2800                 def.Unun = Unun;
2801                 def.Place = Place;
2802                 def.ObjSprite = ObjSprite;
2803                 def.Yukkuri = Yukkuri;
2804                 def.nodeSort = nodeSort;
2805                 mangTouch = new MangTouch(ctl);
2806                 mangMsg = new MangMsg(ctl);
2807                 ctl.setDefined(def);
2808                 backgroundMap.image = game.assets[EResPath.MAP0];
2809                 backgroundMap.loadData(_mapData);
2810                 backgroundMap.collisionData = _collisionData;
2811
2812                 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2813                 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2814                 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2815                 fieldBg.image = fieldSurface;
2816                 fieldBg.x = 0;
2817                 fieldBg.y = 0;
2818
2819                 windowFront.image = windowSurface;
2820                 windowFront.x = 0;
2821                 windowFront.y = 0;
2822                 windowFront.opacity = 0.5;
2823
2824                 windowSurface.context.fillStyle = '#000';
2825                 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2826
2827                 menuSurface.context.fillStyle = '#000';
2828                 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2829                 menuBg.image = menuSurface;
2830                 menuBg.x = EMenuPos.X;
2831                 menuBg.y = EMenuPos.Y;
2832                 backgroundMap.addChild(fieldBg);
2833                 mangIcon = new MangIcon(ctl, menuBg);
2834
2835                 game.rootScene.addChild(backgroundMap);
2836                 // game.rootScene.addChild(windowFront);
2837                 // game.rootScene.addChild(gwindow);
2838                 // var gwindow = new GWindow(ctl, {}, 0, 0, 80, 80);
2839                 game.rootScene.addChild(menuBg);
2840
2841                 // var labelGroup = new LabelGroup();
2842                 mangLabel = new MangLabel(ctl, menuBg);
2843                 // var info = new Label("ゆっくり");
2844                 // info.color = "#ffffff";
2845                 // info.font = "14px 'Times New Roman'";
2846                 // info.x = 4;
2847                 // info.y = GAME_HEIGHT / 2;
2848                 // labelGroup.addChild(info);
2849                 // menuBg.addChild(labelGroup);
2850
2851
2852                 // var food = new def.Food("apple", 200, 250);
2853                 backgroundMap.addChild(foodGroup);
2854                 // backgroundMap.addChild(placeGroup);
2855                 var player = new Player(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
2856                 // var player = new Player(0, 0);
2857                 // console.log(player.getX());
2858                 // player.addKuki();
2859                 // player.createKuki();
2860                 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2861                 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2862                 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2863                 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
2864                 // // new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2865                 // new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
2866                 // new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);
2867                 // new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
2868                 // new Unun(100, 100);
2869                 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2870                 var touchX = 0;
2871                 // var input = new Label("<form name='hoge' style='background-color:#ff0000;'>" +
2872                 //              "<input type='text' name='text'>" +
2873                 //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
2874                 //              "</from>");
2875                 // input.y = 0;
2876                 // input.element.innerHTML = "<form name='hoge' style='background-color:#ff0000;'>" +
2877                 //              "<input type='text' name='text'>" +
2878                 //              // "<select name='input_item' id='input_item'><option name='none'>りんご</option></select>" +
2879                 //              "</from>";
2880                 // menuBg.addChild(input);
2881                 // game.rootScene.addChild(input);
2882                 // var inputEvent = new Label('');
2883                 // output.y = 64;
2884                 // game.rootScene.addChild(output);
2885                 // output.onenterframe = function(e) {
2886                 //              output.text = document.hoge.text.value;
2887                 //      };
2888                 // };
2889                 // enchant.Node.GAddEvent = function(){
2890                 // }
2891                 var popupStatus = null;
2892                 var testFlg = false;
2893                 var iconText = [];
2894                 game._element.addEventListener('mousemove', function (e) {
2895                         var mang = mangTouch.get(ctl.getCurrentCommand());
2896                         if(EMenuPos.X < e.layerX){
2897                                 var ex = e.layerX - EMenuPos.X;
2898                                 var ey = e.layerY;
2899                                 var hitFlg = false;
2900                                 for(var i=0;i<mangIcon.cmdIcons.length;i++){
2901                                         var icon = mangIcon.cmdIcons[i];
2902                                         if(icon.x <= ex && ex <= (icon.x + ICON_WIDTH)
2903                                                 && icon.y <= ey && ey <= (icon.y + ICON_HEIGHT)
2904                                                 ){
2905                                                 hitFlg = true;
2906                                                 if(popupStatus !== i){
2907                                                         ctl.popup.renew(game.rootScene, EMenuPos.X + 5, e.layerY + ICON_HEIGHT / 2, 80, 80);
2908                                                         ctl.popup.setText(icon.text);
2909                                                         popupStatus = i;
2910                                                         break;
2911                                                 }
2912                                         }
2913                                 }
2914
2915                                 if(hitFlg){
2916                                         ctl.popup.opacity = 0.9;
2917                                         ctl.popup.drawText();
2918                                 }
2919                                 else {
2920                                         ctl.popup.opacity = 0;
2921                                 }
2922                                 // console.log(e.layerX + ":" + e.layerY);
2923                         }
2924                 });
2925                 // enchant.Core.instance._element.addEventListener('mousemove', function(e) {
2926
2927                 // game.rootScene.addEventListener('mousemove', function (e) {
2928                 //      console.log("mmmmmmmmm");
2929                 // });
2930
2931
2932                 game.rootScene.addEventListener('touchstart', function (e) {
2933                         game.touched = true;
2934                         var mang = mangTouch.get(ctl.getCurrentCommand());
2935                         mang.touchstart(e);
2936                 });
2937                 game.rootScene.addEventListener('touchmove', function (e) {
2938                         var mang = mangTouch.get(ctl.getCurrentCommand());
2939                         mang.touchmove(e);
2940                 });
2941                 game.rootScene.addEventListener('touchend', function (e) {
2942                         var mang = mangTouch.get(ctl.getCurrentCommand());
2943                         mang.touchend(e);
2944                         game.touched = false;
2945                 });
2946
2947
2948                 game.rootScene.addEventListener('enterframe', function(e){
2949                         //main frame
2950                         mangLabel.draw(player);
2951                         if(this.age%BASE_FPS == 0 ){
2952                                 ctl.calcTime();
2953                         }
2954                         ctl.time += TIME_SPEED;
2955                 });
2956                 this.addEventListener('enterframe', function(){
2957                         //The priority processing of display instead of z-index
2958
2959                         backgroundMap.childNodes.sort(nodeSort);
2960                 });
2961
2962         };
2963         game.start();
2964 };
2965
2966