2 //////////////////////////////////////
9 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
11 //////////////////////////////////////
13 //////////////////////////////////////
14 var PALYER_INIT_X = 100;
15 var PALYER_INIT_Y = 100;
17 var CHARA_HEIGHT = 64;
19 var GAME_HEIGHT = 600;
25 YUKKURI_BASE : './data/yukkuri_base.png',
26 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
27 YUKKURI_UNUN : './data/unun.png',
28 YUKKURI_SHADOW : './data/shadow.png',
29 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
30 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
31 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
32 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
33 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
34 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
35 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
36 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
37 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
38 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
39 MARISA_HEAR : './data/marisa/hear1.png',
40 OBJECT : './data/object.png',
41 MAP0 : './data/map0.png',
42 COMMAND : './data/command.png',
43 OKAZARI : './data/okazari.png',
77 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
88 MOVE_TO_EAT_START: 10,
89 MOVE_TO_EAT_UNDERWAY: 11,
93 UNUN_SMELL_START : 15,
114 include("./lang/ja.js");
115 window.onload = function(){
118 var def = new Object();
119 var foodGroup = new Group();
120 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
121 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
122 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
123 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
127 for(var _v in EResPath){
128 _loadArr[i] = EResPath[_v];
131 game.preload(_loadArr);
132 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
133 var backgroundMap = new MapGroup(16, 16);
134 include("./class.js");
135 include("./ctrl.js");
138 ctl.setBackgroundMap(backgroundMap);
139 var Action = enchant.Class.create({
140 initialize: function (yukkuri){
141 this.status = EAction.THINK;
142 this.yukkuri = yukkuri;
143 this.isMoving = false;
144 this.targetNode = null;
146 getStatus: function(){
149 setStatus: function(eaction){
150 this.status = eaction;
153 if(this.yukkuri.isDead()){
154 this.status = EAction.DEAD;
156 // else if(this.yukkuri.isSleep()){
157 // this.status = EAction.SLEEP;
168 if(this.yukkuri.age%2 === 0){
169 if(this.yukkuri.isSleep()){
170 this.setStatus(EAction.SLEEP_START);
172 else if(this.yukkuri.getUnun() >= 80){
173 this.setStatus(EAction.UNUN_START);
175 // this.yukkuri.param.yukkuri -= 1;
176 this.yukkuri.changeFace();
182 case EAction.MOVE_TO_EAT_START:
183 this.move_to_eat_start();
185 case EAction.MOVE_TO_EAT_UNDERWAY:
191 case EAction.SLEEP_START:
194 case EAction.SLEEP_WAIT:
199 case EAction.EAT_START:
202 case EAction.EAT_WAIT:
204 case EAction.UNUN_START:
207 case EAction.UNUN_WAIT:
209 case EAction.MOVE_TO_COMMAND:
210 this.move_to_command();
212 case EAction.UNUN_SMELL_START:
213 this.unun_smell_start();
218 move_to_eat_start : function(){
221 "targetNode": this.targetNode,
223 "myYukkuri": this.yukkuri
226 walk : function(retryCounter){
227 if(retryCounter > 15){
229 this.status = EAction.NONE;
230 console.log("retryCount over");
233 if(this.yukkuri.imgGroup.tl.queue.length === 0){
236 this.isMoving = false;
237 this.status = EAction.THINK;
241 // this.isMoving = true;
242 var xpos = 150 + rand(40) - (retryCounter * 10);
243 var ypos = 150 + rand(40) - (retryCounter * 10);
246 this.yukkuri.vy = -ypos;
248 else if(rand(8) == 1){
249 this.yukkuri.vx = xpos;
250 this.yukkuri.vy = -ypos;
251 this.yukkuri.direction = EDirection.RIGHT;
253 else if(rand(8) == 2){
254 this.yukkuri.vx = xpos;
256 this.yukkuri.direction = EDirection.RIGHT;
258 else if(rand(8) == 3){
259 this.yukkuri.vx = xpos;
260 this.yukkuri.vy = ypos;
261 this.yukkuri.direction = EDirection.RIGHT;
263 else if(rand(8) == 4){
265 this.yukkuri.vy = ypos;
267 else if(rand(8) == 5){
268 this.yukkuri.vx = -xpos;
269 this.yukkuri.vy = ypos;
270 this.yukkuri.direction = EDirection.LEFT;
272 else if(rand(8) == 6){
273 this.yukkuri.vx = -xpos;
275 this.yukkuri.direction = EDirection.LEFT;
277 else if(rand(8) == 7){
278 this.yukkuri.vx = -xpos;
279 this.yukkuri.vy = -ypos;
280 this.yukkuri.direction = EDirection.LEFT;
282 if (this.yukkuri.vx || this.yukkuri.vy) {
283 var map = ctl.backgroundMap;
284 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
285 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
286 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
287 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
288 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
289 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
290 // console.log("X:" + this.yukkuri.moveX);
291 // console.log("Y:" + this.yukkuri.moveY);
292 this.isMoving = true;
293 this.yukkuri.reverse();
294 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
295 mangMsg.output(this.yukkuri,EMsg.WALK);
297 this.targetNode = null;
299 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
300 this.walk(retryCounter+1);
306 sleep_start: function(){
309 "myYukkuri": this.yukkuri
314 mangMsg.output(this.yukkuri, EMsg.DEAD);
315 this.yukkuri.imgBody.tl.clear();
316 this.yukkuri.imgBody.tl.pause();
317 this.yukkuri.imgGroup.tl.clear();
318 this.yukkuri.imgGroup.tl.pause();
319 this.yukkuri.setBodyImage(EBody.DEAD);
321 eat_start: function(){
324 "targetNode": this.targetNode,
326 "myYukkuri": this.yukkuri
330 unun_start: function(){
333 "myYukkuri": this.yukkuri
336 unun_smell_start: function(){
339 "myYukkuri": this.yukkuri
342 move_to_command: function(){
346 var nodes = ctl.getObjs();
350 for (var key in nodes) {
351 var node = nodes[key];
353 && node instanceof Unun
354 && !(this.targetNode instanceof Unun)
355 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
357 this.targetNode = node;
358 this.setStatus(EAction.UNUN_SMELL_START);
361 else if (node instanceof Food) {
362 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
364 //A yukkuri to go to the food area
365 this.targetNode = node;
366 this.setStatus(EAction.MOVE_TO_EAT_START);
370 //not hunbry or not food.
374 this.status = EAction.WALK;
377 var Event = enchant.Class.create({
378 initialize: function (_data){
380 onactionstart:function(self){
382 if(typeof e === "undefined")return;
385 onactiontick:function(self){
387 if(typeof e === "undefined")return;
390 onactionend:function(self){
392 if(typeof e === "undefined")return;
396 var SleepEvent = enchant.Class.create(Event,{
397 initialize: function (_data){
399 this.yukkuri = _data.myYukkuri;
400 this.action = _data.action;
402 mangMsg.output(this.yukkuri, EMsg.SLEEP);
403 this.action.setStatus(EAction.SLEEP_WAIT);
404 this.yukkuri.setFaceImage(EFace.SLEEP);
405 this.yukkuri.tlPause();
407 // this.yukkuri.enterframe(function(){
408 // console.log("enterfmrae");
411 this.yukkuri.addEventListener('enterframe', function() {
412 var yukkuri = self.yukkuri;
413 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
414 if(yukkuri.param.sleep <= 0){
415 yukkuri.param.sleep = 0;
416 self.action.setStatus(EAction.WAIT);
417 mangMsg.output(self.yukkuri, EMsg.GET_UP);
418 self.yukkuri.setFaceImage(EFace.NORMAL);
420 this.removeEventListener("enterframe",arguments.callee);
421 self.action.setStatus(EAction.THINK);
425 onactionstart:function(self){
427 if(typeof e === "undefined")return;
428 console.log("astart");
431 onactiontick:function(self){
433 if(typeof e === "undefined")return;
436 onactionend:function(self){
438 if(typeof e === "undefined")return;
439 console.log("enddd");
443 // initialize: function (_data){
444 // console.log("init");
445 // this.data = _data;
446 // this.yukkuri = _data.myYukkuri;
447 // this.action = _data.action;
448 // this.action.setStatus(EAction.SLEEP_WAIT);
449 // mangMsg.output(this.yukkuri, EMsg.SLEEP);
450 // this.yukkuri.setFaceImage(EFace.SLEEP);
451 // this.yukkuri.tlPause();
453 // var sec = BASE_FPS * 1;
454 // console.log("sec:"+ sec);
455 // this.yukkuri.wait(sec, {
456 // "onactionstart": this.onactionstart(this),
457 // "onactiontick": this.onactiontick(this),
458 // "onactionend": this.onactionend(this)
461 // onactionstart:function(self){
462 // return function(e){
463 // console.log("start");
464 // if(typeof e === "undefined")return;
467 // onactiontick:function(self){
468 // return function(e){
469 // if(typeof e === "undefined")return;
470 // console.log("tick");
471 // var yukkuri = self.yukkuri;
472 // if(yukkuri.age%4 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
473 // if(yukkuri.param.sleep <= 0){
474 // yukkuri.param.sleep = 0;
478 // onactionend:function(self){
479 // return function(e){
480 // if(typeof e === "undefined")return;
481 // self.action.setStatus(EAction.WAIT);
482 // self.yukkuri.setFaceImage(EFace.NORMAL);
483 // mangMsg.output(self.yukkuri, EMsg.GET_UP);
484 // yukkuri.tlResume();
486 // "waitframe": FPS * 1.5,
487 // "action": self.action,
488 // "myYukkuri": self.yukkuri
494 var UnunEvent = enchant.Class.create(Event,{
495 initialize: function (_data){
497 this.yukkuri = _data.myYukkuri;
498 this.action = _data.action;
499 this.action.setStatus(EAction.UNUN_WAIT);
500 mangMsg.output(this.yukkuri, EMsg.UNUN);
501 this.yukkuri.setFaceImage(EFace.HAPPY2);
504 this.yukkuri.wait(sec, {
505 "onactionstart": this.onactionstart(this),
506 "onactiontick": this.onactiontick(this),
507 "onactionend": this.onactionend(this)
510 onactionstart:function(self){
512 if(typeof e === "undefined")return;
515 onactiontick:function(self){
517 if(typeof e === "undefined")return;
520 onactionend:function(self){
522 if(typeof e === "undefined")return;
524 self.action.setStatus(EAction.WAIT);
525 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
527 "waitframe": FPS * 1.5,
528 "action": self.action,
529 "myYukkuri": self.yukkuri
534 var WaitEvent = enchant.Class.create(Event,{
535 initialize: function (_data){
537 this.yukkuri = _data.myYukkuri;
538 this.action = _data.action;
539 this.waitframe = _data.waitframe;
540 this.yukkuri.wait(this.waitframe, {
541 "onactionstart": this.onactionstart(this),
542 "onactiontick": this.onactiontick(this),
543 "onactionend": this.onactionend(this)
546 onactionend:function(self){
548 if(typeof e === "undefined")return;
549 self.action.setStatus(EAction.THINK);
553 var UnunSmellEvent = enchant.Class.create(Event,{
554 initialize: function (_data){
556 this.yukkuri = _data.myYukkuri;
557 this.action = _data.action;
558 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
559 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
560 this.yukkuri.setFaceImage(EFace.CRY1);
562 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
563 this.yukkuri.wait(sec, {
564 "onactionstart": this.onactionstart(this),
565 "onactiontick": this.onactiontick(this),
566 "onactionend": this.onactionend(this)
569 onactionend:function(self){
571 if(typeof e === "undefined")return;
572 self.action.setStatus(EAction.THINK);
577 var EatEvent = enchant.Class.create(Event,{
578 initialize: function (_data){
580 this.yukkuri = _data.myYukkuri;
581 this.food = _data.targetNode;
582 this.action = _data.action;
583 this.action.setStatus(EAction.EAT_WAIT);
584 mangMsg.output(this.yukkuri, EMsg.EAT);
585 this.yukkuri.setFaceImage(EFace.EAT2);
587 // var sec = FPS * (this.yukkuri.param.hungry/10 + 3);
590 this.yukkuri.wait(sec, {
591 "onactionstart": this.onactionstart(this),
592 "onactiontick": this.onactiontick(this),
593 "onactionend": this.onactionend(this)
596 onactionstart:function(self){
598 if(typeof e === "undefined")return;
599 self.yukkuri.eat(self.food);
602 onactiontick:function(self){
604 if(typeof e === "undefined")return;
607 onactionend:function(self){
609 if(typeof e === "undefined")return;
610 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
611 self.action.setStatus(EAction.THINK);
612 self.yukkuri.setFaceImage(EFace.NORMAL);
614 self.action.setStatus(EAction.EAT_START);
621 * -When yukkuri find Food.
624 * targetNode: enchant.Node
628 var MoveToEatEvent = enchant.Class.create(Event,{
629 initialize: function (_data){
631 this.yukkuri = this.data.myYukkuri;
632 this.action = this.data.action;
634 var yukkuri = this.yukkuri;
635 var node = this.data.targetNode;
637 if(this.data.type == "food"){
638 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
639 yukkuri.vx = node.x - yukkuri.getX();
640 yukkuri.vy = node.y - yukkuri.getY();
641 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
642 var frame = distance + distance/5 + 1;
643 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
645 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
646 "onactionstart": this.onactionstart(this),
647 "onactiontick": this.onactiontick(this),
648 "onactionend": this.onactionend(this)
652 onactionstart:function(self){
654 if(typeof e === "undefined")return;
655 self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
658 onactiontick:function(self){
660 if(typeof e === "undefined")return;
663 onactionend:function(self){
665 if(typeof e === "undefined")return;
666 self.action.setStatus(EAction.EAT_START);
670 var MoveCommandEvent = enchant.Class.create(Event,{
671 initialize: function (_data){
673 this.yukkuri = this.data.myYukkuri;
674 this.action = this.data.action;
675 this.vx = this.data.vx;
676 this.vy = this.data.vy;
678 var yukkuri = this.yukkuri;
679 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
680 yukkuri.vx = node.x - yukkuri.getX();
681 yukkuri.vy = node.y - yukkuri.getY();
682 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
683 var frame = distance + 1;
684 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
685 "onactionstart": this.onactionstart(this),
686 "onactiontick": this.onactiontick(this),
687 "onactionend": this.onactionend(this)
690 onactionstart:function(self){
692 if(typeof e === "undefined")return;
695 onactiontick:function(self){
697 if(typeof e === "undefined")return;
700 onactionend:function(self){
702 if(typeof e === "undefined")return;
703 self.action.setStatus(EAction.THINK);
708 var ObjSprite = enchant.Class.create(enchant.Sprite,{
709 initialize: function (w, h){
710 enchant.Sprite.call(this, w, h);
714 removeAll: function(){
720 var Food = enchant.Class.create(ObjSprite,{
721 initialize: function (type, x, y){
722 this.classname = "Food";
723 ObjSprite.call(this,16,16);
724 this.image = game.assets[EResPath.OBJECT];
728 //一つにつきgiveの値分、hunguryを減少させられる
731 foodGroup.addChild(this);
732 this.addEventListener('enterframe', function(){
733 if(this.amount <= 0){
738 getAmount: function(){
745 var Unun = enchant.Class.create(ObjSprite,{
746 initialize: function (x, y){
747 this.classname = "Unun";
748 ObjSprite.call(this,32,32);
749 this.image = game.assets[EResPath.YUKKURI_UNUN];
752 backgroundMap.addChild(this);
755 var Okazari = enchant.Class.create(enchant.Sprite,{
756 initialize: function(){
757 this.classname = "Okazari";
758 enchant.Sprite.call(this, 64, 64);
759 this.image = game.assets[EResPath.OKAZARI];
760 this.x = -CHARA_WIDTH / 2;
761 this.y = -12 - CHARA_HEIGHT / 2;
764 var Yukkuri = enchant.Class.create(ObjSprite,{
765 initialize: function(x, y){
766 ObjSprite.call(this, 64, 64);
767 this.classname = "Yukkuri";
768 this.imgGroup = new SpriteGroup();
769 this.imgBody = new SpriteGroup();
770 this.imgGroup.id = guid();
771 this.imgBody.id = guid();
772 this.x = -CHARA_WIDTH / 2;
773 this.y = -CHARA_HEIGHT / 2;
776 this.image = game.assets[EResPath.YUKKURI_BASE];
777 this.direction = EDirection.RIGHT;
778 this.addEventListener('enterframe', this.runEnterframe);
779 this.isSleeping = false;
781 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
782 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
784 runEnterframe:function(){
786 if(this.isDead())return;
793 if(this.direction == EDirection.RIGHT){
794 this.imgBody.scaleX = 1;
796 else if(this.direction == EDirection.LEFT){
797 this.imgBody.scaleX = -1;
800 tweet:function(text){
801 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
803 moveTo:function(x, y, time){
804 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
806 moveBy:function(x, y, time, eventFunctions){
810 return self.imgGroup.x + x;
813 return self.imgGroup.y + y;
816 easing: enchant.Easing.SIN_EASEINOUT
818 //-Event register [onactionstart,onactiontick,onactionend]
819 if(eventFunctions !== undefined){
820 for(var key in eventFunctions){
821 params[key] = eventFunctions[key];
824 this.imgGroup.tl.tween(params);
827 wait:function(frame, eventFunctions){
828 this.moveBy(0,1,frame,eventFunctions);
833 animation: function(){
834 this.imgBody.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
835 // this.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
836 // this.okazari.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
837 // this.face.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
838 // this.hear.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
840 getWidth: function(){
843 getHeight: function(){
847 return this.imgGroup.x;
850 return this.imgGroup.y;
853 this.imgGroup.x += x;
855 // this.shadow.x += x;
856 // this._tweet.x += x;
859 this.imgGroup.y += y;
861 // this.shadow.y += y;
862 // this._tweet.y += y;
864 // changeFace: function(erespath){
865 // this.face.image = game.assets[erespath];
867 loadParamsXML: function(url){
868 var http = new JKL.ParseXML( url );
871 runYukkuri: function(){
872 if(this.param.hungry > 70){
873 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
874 this.param.yukkuri -= 1;
877 else if(this.param.hungry < 10){
878 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
881 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
882 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
884 runHungry: function(){
885 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
886 if(this.param.hungry >= 100)this.param.hungry = 100;
889 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
890 if(this.param.unun >= 100)this.param.unun = 100;
892 runSleep: function(){
893 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
894 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
895 if(this.param.sleep >= 100){
896 this.param.sleep = 100;
900 changeFace: function(){
901 if(this.param.yukkuri >= 80){
902 this.setFaceImage(EFace.HAPPY1);
904 else if(this.param.yukkuri >= 50){
905 this.setFaceImage(EFace.NORMAL);
907 else if(this.param.yukkuri >= 30){
908 this.setFaceImage(EFace.TIRED);
910 else if(this.param.yukkuri >= 10){
911 this.setFaceImage(EFace.CRY1);
913 else if(this.param.yukkuri >= 1){
914 this.setFaceImage(EFace.CRY2);
917 getRange: function(){
918 return this.param.range;
921 return this.param.sleep >= 100;
924 return this.param.yukkuri <= 0;
926 isManpuku: function(){
927 return this.param.hungry <= 20;
929 isKuhuku: function(){
930 return this.param.hungry >= 40;
932 getYukkuri: function(){
933 return this.param.yukkuri;
935 setYukkuri: function(yukkuri){
936 this.param.yukkuri = yukkuri;
937 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
939 getHungry: function(){
940 return this.param.hungry;
942 setHungry: function(hungry){
943 this.param.hungry = hungry;
944 if(this.param.hungry < 0)this.param.hungry = 0;
947 return this.param.unun;
949 setUnun: function(unun){
950 this.param.unun = unun;
951 if(this.param.unun < 0)this.param.unun = 0;
956 this.setHungry(this.param.hungry - food.getGive());
957 this.setUnun(this.getUnun() + food.getGive() / 4);
958 this.setYukkuri(this.getYukkuri() + 5);
961 if(this.direction == EDirection.RIGHT){
962 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
964 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
968 setBodyImage: function(ebody){
969 var path = this.bodyStatus[ebody];
970 this.image = game.assets[path];
973 this.imgBody.tl.pause();
974 this.imgGroup.tl.pause();
975 this.imgBody.tl.clear();
976 this.imgGroup.tl.clear();
978 tlResume: function(){
979 this.imgBody.tl.resume();
980 this.imgGroup.tl.resume();
983 destruct: function(){
987 var Marisa = enchant.Class.create(Yukkuri,{
988 initialize: function(x, y){
989 Yukkuri.call(this,x,y);
990 this.classname = "Marisa";
993 // var xml = this.loadParamsXML("./data/marisa/params.xml");
994 var json = net.load("./data/marisa/params.json");
995 this.param = json.root.param;
996 this.shadow = new enchant.Sprite(64, 64);
997 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
998 this.shadow.x = 0 + this.x;
999 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1000 this.shadow.image._element.style.zIndex = 2;
1002 this._style.zIndex = 5;
1004 this.face = new enchant.Sprite(64, 64);
1005 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1006 this.face.x = -CHARA_WIDTH / 2;
1007 this.face.y = -CHARA_HEIGHT / 2;
1008 this.face._style.zIndex = 0;
1010 this.faceStatus ={};
1011 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1012 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1013 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1014 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1015 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1016 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1017 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1018 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1019 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1020 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1023 this.hear = new enchant.Sprite(64, 64);
1024 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1025 this.hear.x = -CHARA_WIDTH / 2;
1026 this.hear.y = -CHARA_HEIGHT / 2;
1027 this.hear._style.zIndex = 0;
1029 this.okazari = new Okazari();
1030 this.okazari.image._element.style.zIndex = 1;
1032 // this.imgGroup._style.zIndex = 1;
1034 this.imgGroup.addChild(this.shadow);
1035 this.imgBody.addChild(this);
1036 this.imgBody.addChild(this.face);
1037 this.imgBody.addChild(this.hear);
1038 this.imgBody.addChild(this.okazari);
1039 this.imgGroup.addChild(this.imgBody);
1040 backgroundMap.addChild(this.imgGroup);
1041 this._tweet = new TTweet(148, 64);
1042 this._tweet.image._element.style.zIndex = 20;
1044 this.imgGroup.addChild(this._tweet);
1045 this.imgGroup.x = x;
1046 this.imgGroup.y = y;
1048 this.action = new Action(this);
1052 setFaceImage: function(eface){
1053 var path = this.faceStatus[eface];
1054 this.face.image = game.assets[path];
1057 var Player = enchant.Class.create(Marisa,{
1058 initialize: function(x, y){
1059 // this.runEnterframe = function(){
1061 Marisa.call(this, x, y);
1062 this.classname = "Player";
1063 ctl.setPlayer(this);
1064 // this.removeEventListener('enterframe',this.runEnterframe);
1065 this.addEventListener('enterframe', function(){
1066 if(this.age%10 === 0 && this.age !== 0){
1067 // console.log("palyer:" + this.age);
1071 ///////////////////////////////////////////////
1072 //Action pattern for debug
1073 if(game.input.left){
1074 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1076 this.direction = EDirection.LEFT;
1078 if(game.input.right){
1080 this.direction = EDirection.RIGHT;
1084 this.tweet("ゆっくりしていってね!");
1086 if(game.input.down){
1089 ///////////////////////////////////////////////
1091 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1092 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1094 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1096 //- Display the circle of search range.
1097 // fieldBg.image.clear();
1098 // fieldBg.image.context.beginPath();
1099 // fieldBg.image.context.fillStyle = '#ff0000';
1100 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1101 // fieldBg.image.context.fill();
1105 game.onload = function(){
1107 mangTouch = new MangTouch(ctl);
1108 mangMsg = new MangMsg(ctl);
1109 ctl.setDefined(def);
1110 backgroundMap.image = game.assets[EResPath.MAP0];
1111 backgroundMap.loadData(_mapData);
1112 backgroundMap.collisionData = _collisionData;
1114 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1115 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1116 fieldBg.image = fieldSurface;
1120 menuSurface.context.fillStyle = '#000';
1121 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1122 menuBg.image = menuSurface;
1123 menuBg.x = EMenuPos.X;
1124 menuBg.y = EMenuPos.Y;
1126 backgroundMap.addChild(fieldBg);
1127 mangIcon = new MangIcon(ctl, menuBg);
1129 game.rootScene.addChild(backgroundMap);
1130 game.rootScene.addChild(menuBg);
1132 // var labelGroup = new LabelGroup();
1133 mangLabel = new MangLabel(ctl, menuBg);
1134 // var info = new Label("ゆっくり");
1135 // info.color = "#ffffff";
1136 // info.font = "14px 'Times New Roman'";
1138 // info.y = GAME_HEIGHT / 2;
1139 // labelGroup.addChild(info);
1140 // menuBg.addChild(labelGroup);
1143 // var food = new def.Food("apple", 200, 250);
1144 backgroundMap.addChild(foodGroup);
1145 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1146 // new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y);
1149 game.rootScene.addEventListener('touchstart', function (e) {
1150 game.touched = true;
1151 var mang = mangTouch.get(ctl.getCurrentCommand());
1154 game.rootScene.addEventListener('touchmove', function (e) {
1155 var mang = mangTouch.get(ctl.getCurrentCommand());
1158 game.rootScene.addEventListener('touchend', function (e) {
1159 var mang = mangTouch.get(ctl.getCurrentCommand());
1161 game.touched = false;
1165 game.rootScene.addEventListener('enterframe', function(){
1167 mangLabel.draw(player);
1170 this.addEventListener('enterframe', function(){
1171 //The priority processing of display instead of z-index
1172 backgroundMap.childNodes.sort(
1174 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1177 else if(typeof a.id === "undefined"){
1180 else if(typeof b.id === "undefined"){
1183 if(a.y < b.y)return -1;
1184 if(a.y > b.y)return 1;