OSDN Git Service

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