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,
97 COMMUNICATE_START : 19,
116 include("./lang/ja.js");
117 window.onload = function(){
120 var def = new Object();
121 var foodGroup = new Group();
122 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
123 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
124 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
125 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
126 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
130 for(var _v in EResPath){
131 _loadArr[i] = EResPath[_v];
134 game.preload(_loadArr);
135 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
136 var backgroundMap = new MapGroup(16, 16);
137 include("./class.js");
138 include("./ctrl.js");
141 ctl.setBackgroundMap(backgroundMap);
142 var Action = enchant.Class.create({
143 initialize: function (yukkuri){
144 this.status = EAction.THINK;
145 this.yukkuri = yukkuri;
146 this.isMoving = false;
147 this.targetNode = null;
149 getStatus: function(){
152 setStatus: function(eaction){
153 this.status = eaction;
156 if(this.yukkuri.isDead()){
157 this.status = EAction.DEAD;
159 // else if(this.yukkuri.isSleep()){
160 // this.status = EAction.SLEEP;
171 if(this.yukkuri.age%2 === 0){
172 if(this.yukkuri.isSleep()){
173 this.setStatus(EAction.SLEEP_START);
175 else if(this.yukkuri.getUnun() >= 80){
176 this.setStatus(EAction.UNUN_START);
178 // this.yukkuri.param.yukkuri -= 1;
179 this.yukkuri.changeFace();
185 case EAction.MOVE_TO_EAT_START:
186 this.move_to_eat_start();
188 case EAction.MOVE_TO_EAT_UNDERWAY:
194 case EAction.SLEEP_START:
197 case EAction.SLEEP_WAIT:
202 case EAction.EAT_START:
205 case EAction.EAT_WAIT:
207 case EAction.UNUN_START:
210 case EAction.UNUN_WAIT:
212 case EAction.MOVE_TO_COMMAND:
213 this.move_to_command();
215 case EAction.UNUN_SMELL_START:
216 this.unun_smell_start();
218 case EAction.COMMUNICATE_START:
219 this.communicate_start();
223 this.yukkuri.reverse();
226 move_to_eat_start : function(){
229 "targetNode": this.targetNode,
231 "myYukkuri": this.yukkuri
237 walk : function(retryCounter){
238 if(retryCounter > 15){
240 this.status = EAction.NONE;
241 console.log("retryCount over");
244 if(this.yukkuri.imgGroup.tl.queue.length === 0){
247 this.isMoving = false;
248 this.status = EAction.THINK;
252 var xpos = 150 + rand(40) - (retryCounter * 10);
253 var ypos = 150 + rand(40) - (retryCounter * 10);
256 this.yukkuri.vy = -ypos;
258 else if(rand(8) == 1){
259 this.yukkuri.vx = xpos;
260 this.yukkuri.vy = -ypos;
261 this.yukkuri.direction = EDirection.RIGHT;
263 else if(rand(8) == 2){
264 this.yukkuri.vx = xpos;
266 this.yukkuri.direction = EDirection.RIGHT;
268 else if(rand(8) == 3){
269 this.yukkuri.vx = xpos;
270 this.yukkuri.vy = ypos;
271 this.yukkuri.direction = EDirection.RIGHT;
273 else if(rand(8) == 4){
275 this.yukkuri.vy = ypos;
277 else if(rand(8) == 5){
278 this.yukkuri.vx = -xpos;
279 this.yukkuri.vy = ypos;
280 this.yukkuri.direction = EDirection.LEFT;
282 else if(rand(8) == 6){
283 this.yukkuri.vx = -xpos;
285 this.yukkuri.direction = EDirection.LEFT;
287 else if(rand(8) == 7){
288 this.yukkuri.vx = -xpos;
289 this.yukkuri.vy = -ypos;
290 this.yukkuri.direction = EDirection.LEFT;
292 if (this.yukkuri.vx || this.yukkuri.vy) {
293 var map = ctl.backgroundMap;
294 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
295 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
296 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
297 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
298 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
299 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
300 // console.log("X:" + this.yukkuri.moveX);
301 // console.log("Y:" + this.yukkuri.moveY);
302 this.isMoving = true;
303 this.yukkuri.reverse();
304 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
305 mangMsg.output(this.yukkuri,EMsg.WALK);
307 this.targetNode = null;
309 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
310 this.walk(retryCounter+1);
316 sleep_start: function(){
319 "myYukkuri": this.yukkuri
324 mangMsg.output(this.yukkuri, EMsg.DEAD);
325 this.yukkuri.imgBody.tl.clear();
326 this.yukkuri.imgBody.tl.pause();
327 this.yukkuri.imgGroup.tl.clear();
328 this.yukkuri.imgGroup.tl.pause();
329 this.yukkuri.setBodyImage(EBody.DEAD);
331 eat_start: function(){
334 "targetNode": this.targetNode,
336 "myYukkuri": this.yukkuri
340 unun_start: function(){
343 "myYukkuri": this.yukkuri
346 unun_smell_start: function(){
349 "myYukkuri": this.yukkuri
352 communicate_start:function(){
353 new CommunicationEvent({
355 "targetNode": this.targetNode,
357 "myYukkuri": this.yukkuri
360 move_to_command: function(){
364 var nodes = ctl.getObjs();
368 for (var key in nodes) {
369 var node = nodes[key];
371 && node instanceof Unun
372 && !(this.targetNode instanceof Unun)
373 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
375 this.targetNode = node;
376 this.setStatus(EAction.UNUN_SMELL_START);
379 else if (node instanceof Food) {
380 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
382 //A yukkuri to go to the food area
383 this.targetNode = node;
384 this.setStatus(EAction.MOVE_TO_EAT_START);
388 //not hunbry or not food.
391 // else if(node instanceof Yukkuri){
392 // if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
393 // this.targetNode = node;
394 // this.setStatus(EAction.COMMUNICATE_START);
401 this.status = EAction.WALK;
404 var Event = enchant.Class.create({
405 initialize: function (_data){
407 onactionstart:function(self){
409 if(typeof e === "undefined")return;
412 onactiontick:function(self){
414 if(typeof e === "undefined")return;
417 onactionend:function(self){
419 if(typeof e === "undefined")return;
423 var WalkEvent = enchant.Class.create(Event,{
424 initialize: function (_data){
426 this.yukkuri = _data.myYukkuri;
427 this.action = _data.action;
429 mangMsg.output(this.yukkuri, EMsg.SLEEP);
430 this.action.setStatus(EAction.SLEEP_WAIT);
431 this.yukkuri.setFaceImage(EFace.SLEEP);
432 this.yukkuri.tlPause();
434 this.yukkuri.addEventListener('enterframe', function() {
435 var yukkuri = self.yukkuri;
443 var SleepEvent = enchant.Class.create(Event,{
444 initialize: function (_data){
446 this.yukkuri = _data.myYukkuri;
447 this.action = _data.action;
449 mangMsg.output(this.yukkuri, EMsg.SLEEP);
450 this.action.setStatus(EAction.SLEEP_WAIT);
451 this.yukkuri.setFaceImage(EFace.SLEEP);
452 this.yukkuri.tlPause();
455 this.yukkuri.addEventListener('enterframe', function() {
456 var yukkuri = self.yukkuri;
457 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
458 if(yukkuri.param.sleep <= 0){
459 yukkuri.param.sleep = 0;
460 this.removeEventListener("enterframe",arguments.callee);
461 mangMsg.output(self.yukkuri, EMsg.GET_UP);
462 yukkuri.setFaceImage(EFace.NORMAL);
464 // self.action.setStatus(EAction.WAIT);
465 self.action.setStatus(EAction.THINK);
471 var UnunEvent = enchant.Class.create(Event,{
472 initialize: function (_data){
474 this.yukkuri = _data.myYukkuri;
475 this.action = _data.action;
476 this.action.setStatus(EAction.UNUN_WAIT);
477 mangMsg.output(this.yukkuri, EMsg.UNUN);
478 this.yukkuri.setFaceImage(EFace.HAPPY2);
481 this.yukkuri.wait(sec, {
482 "onactionstart": this.onactionstart(this),
483 "onactiontick": this.onactiontick(this),
484 "onactionend": this.onactionend(this)
487 onactionstart:function(self){
489 if(typeof e === "undefined")return;
492 onactiontick:function(self){
494 if(typeof e === "undefined")return;
497 onactionend:function(self){
499 if(typeof e === "undefined")return;
501 self.action.setStatus(EAction.WAIT);
502 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
504 "waitframe": FPS * 1.5,
505 "action": self.action,
506 "myYukkuri": self.yukkuri
511 var WaitEvent = enchant.Class.create(Event,{
512 initialize: function (_data){
514 this.yukkuri = _data.myYukkuri;
515 this.action = _data.action;
516 this.waitframe = _data.waitframe;
517 this.yukkuri.wait(this.waitframe, {
518 "onactionstart": this.onactionstart(this),
519 "onactiontick": this.onactiontick(this),
520 "onactionend": this.onactionend(this)
523 onactionend:function(self){
525 if(typeof e === "undefined")return;
526 self.action.setStatus(EAction.THINK);
530 var UnunSmellEvent = enchant.Class.create(Event,{
531 initialize: function (_data){
533 this.yukkuri = _data.myYukkuri;
534 this.action = _data.action;
535 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
536 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
537 this.yukkuri.setFaceImage(EFace.CRY1);
539 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
540 this.yukkuri.wait(sec, {
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);
554 var EatEvent = enchant.Class.create(Event,{
555 initialize: function (_data){
557 this.yukkuri = _data.myYukkuri;
558 this.food = _data.targetNode;
559 this.action = _data.action;
560 this.action.setStatus(EAction.EAT_WAIT);
563 var sec = BASE_FPS * 3;
564 if(this.yukkuri.eat(this.food)){
565 mangMsg.output(this.yukkuri, EMsg.EAT);
566 this.yukkuri.setFaceImage(EFace.EAT2);
569 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
570 this.yukkuri.setFaceImage(EFace.CRY2);
572 this.yukkuri.wait(sec, {
573 "onactionend": this.onactionend(this)
576 onactionend:function(self){
578 if(typeof e === "undefined")return;
579 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
580 self.action.setStatus(EAction.THINK);
581 self.yukkuri.setFaceImage(EFace.NORMAL);
583 self.action.setStatus(EAction.EAT_START);
590 * -When yukkuri find Food.
593 * targetNode: enchant.Node
597 var MoveToEatEvent = enchant.Class.create(Event,{
598 initialize: function (_data){
600 this.yukkuri = this.data.myYukkuri;
601 this.action = this.data.action;
603 var yukkuri = this.yukkuri;
604 var node = this.data.targetNode;
606 if(this.data.type == "food"){
607 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
608 yukkuri.vx = node.x - yukkuri.getX();
609 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
610 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
611 var frame = distance + distance/5 + 1;
612 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
615 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
616 "onactionstart": this.onactionstart(this),
617 "onactiontick": this.onactiontick(this),
618 "onactionend": this.onactionend(this)
622 onactionstart:function(self){
624 if(typeof e === "undefined")return;
625 self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
628 onactiontick:function(self){
630 if(typeof e === "undefined")return;
633 onactionend:function(self){
635 if(typeof e === "undefined")return;
636 self.action.setStatus(EAction.EAT_START);
640 var MoveCommandEvent = enchant.Class.create(Event,{
641 initialize: function (_data){
643 this.yukkuri = this.data.myYukkuri;
644 this.action = this.data.action;
645 this.vx = this.data.vx;
646 this.vy = this.data.vy;
648 var yukkuri = this.yukkuri;
649 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
650 yukkuri.vx = node.x - yukkuri.getX();
651 yukkuri.vy = node.y - yukkuri.getY();
652 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
653 var frame = distance + 1;
654 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
655 "onactionstart": this.onactionstart(this),
656 "onactiontick": this.onactiontick(this),
657 "onactionend": this.onactionend(this)
660 onactionstart:function(self){
662 if(typeof e === "undefined")return;
665 onactiontick:function(self){
667 if(typeof e === "undefined")return;
670 onactionend:function(self){
672 if(typeof e === "undefined")return;
673 self.action.setStatus(EAction.THINK);
677 var CommunicationEvent = enchant.Class.create(Event,{
678 initialize: function (_data){
680 this.yukkuri = _data.myYukkuri;
681 this.food = _data.targetNode;
682 this.action = _data.action;
683 this.action.setStatus(EAction.EAT_WAIT);
684 mangMsg.output(this.yukkuri, EMsg.EAT);
685 this.yukkuri.setFaceImage(EFace.EAT2);
687 // var sec = FPS * (this.yukkuri.param.hungry/10 + 3);
690 this.yukkuri.wait(sec, {
691 "onactionstart": this.onactionstart(this),
692 "onactiontick": this.onactiontick(this),
693 "onactionend": this.onactionend(this)
696 onactionstart:function(self){
698 if(typeof e === "undefined")return;
699 self.yukkuri.eat(self.food);
702 onactiontick:function(self){
704 if(typeof e === "undefined")return;
707 onactionend:function(self){
709 if(typeof e === "undefined")return;
710 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
711 self.action.setStatus(EAction.THINK);
712 self.yukkuri.setFaceImage(EFace.NORMAL);
714 self.action.setStatus(EAction.EAT_START);
720 var ObjSprite = enchant.Class.create(enchant.Sprite,{
721 initialize: function (w, h){
722 enchant.Sprite.call(this, w, h);
726 removeAll: function(){
732 var Food = enchant.Class.create(ObjSprite,{
733 initialize: function (type, x, y){
734 this.classname = "Food";
735 ObjSprite.call(this,16,16);
736 this.image = game.assets[EResPath.OBJECT];
740 //一つにつきgiveの値分、hunguryを減少させられる
743 foodGroup.addChild(this);
744 this.addEventListener('enterframe', function(){
745 if(this.amount <= 0){
750 getAmount: function(){
757 var Unun = enchant.Class.create(ObjSprite,{
758 initialize: function (x, y){
759 this.classname = "Unun";
760 ObjSprite.call(this,32,32);
761 this.image = game.assets[EResPath.YUKKURI_UNUN];
764 backgroundMap.addChild(this);
767 var Okazari = enchant.Class.create(enchant.Sprite,{
768 initialize: function(){
769 this.classname = "Okazari";
770 enchant.Sprite.call(this, 64, 64);
771 this.image = game.assets[EResPath.OKAZARI];
772 this.x = -CHARA_WIDTH / 2;
773 this.y = -12 - CHARA_HEIGHT / 2;
776 var Yukkuri = enchant.Class.create(ObjSprite,{
777 initialize: function(x, y){
778 ObjSprite.call(this, 64, 64);
779 this.classname = "Yukkuri";
780 this.imgGroup = new SpriteGroup();
781 this.imgBody = new SpriteGroup();
782 this.imgGroup.id = guid();
783 this.imgBody.id = guid();
784 this.x = -CHARA_WIDTH / 2;
785 this.y = -CHARA_HEIGHT / 2;
788 this.image = game.assets[EResPath.YUKKURI_BASE];
789 this.direction = EDirection.RIGHT;
790 this.addEventListener('enterframe', this.runEnterframe);
792 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
793 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
795 runEnterframe:function(){
797 if(this.isDead())return;
804 if(this.direction == EDirection.RIGHT){
805 this.imgBody.scaleX = 1;
807 else if(this.direction == EDirection.LEFT){
808 this.imgBody.scaleX = -1;
811 tweet:function(text){
812 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
814 moveTo:function(x, y, time){
815 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
817 moveBy:function(x, y, time, eventFunctions){
821 return self.imgGroup.x + x;
824 return self.imgGroup.y + y;
827 easing: enchant.Easing.SIN_EASEINOUT
829 //-Event register [onactionstart,onactiontick,onactionend]
830 if(eventFunctions !== undefined){
831 for(var key in eventFunctions){
832 params[key] = eventFunctions[key];
835 this.imgGroup.tl.tween(params);
838 wait:function(frame, eventFunctions){
839 this.moveBy(0,1,frame,eventFunctions);
844 animation: function(){
845 this.imgBody.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
846 // this.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
847 // this.okazari.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
848 // this.face.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
849 // this.hear.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
851 getWidth: function(){
854 getHeight: function(){
858 return this.imgGroup.x;
861 return this.imgGroup.y;
864 this.imgGroup.x += x;
866 // this.shadow.x += x;
867 // this._tweet.x += x;
870 this.imgGroup.y += y;
872 // this.shadow.y += y;
873 // this._tweet.y += y;
875 // changeFace: function(erespath){
876 // this.face.image = game.assets[erespath];
878 loadParamsXML: function(url){
879 var http = new JKL.ParseXML( url );
882 runYukkuri: function(){
883 if(this.param.hungry > 70){
884 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
885 this.param.yukkuri -= 1;
888 else if(this.param.hungry < 10){
889 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
892 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
893 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
895 runHungry: function(){
896 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
897 if(this.param.hungry >= 100)this.param.hungry = 100;
900 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
901 if(this.param.unun >= 100)this.param.unun = 100;
903 runSleep: function(){
904 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
905 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
906 if(this.param.sleep >= 100){
907 this.param.sleep = 100;
911 changeFace: function(){
912 if(this.param.yukkuri >= 80){
913 this.setFaceImage(EFace.HAPPY1);
915 else if(this.param.yukkuri >= 50){
916 this.setFaceImage(EFace.NORMAL);
918 else if(this.param.yukkuri >= 30){
919 this.setFaceImage(EFace.TIRED);
921 else if(this.param.yukkuri >= 10){
922 this.setFaceImage(EFace.CRY1);
924 else if(this.param.yukkuri >= 1){
925 this.setFaceImage(EFace.CRY2);
928 getRange: function(){
929 return this.param.range;
932 return this.param.sleep >= 100;
935 return this.param.yukkuri <= 0;
937 isManpuku: function(){
938 return this.param.hungry <= 20;
940 isKuhuku: function(){
941 return this.param.hungry >= 40;
943 getYukkuri: function(){
944 return this.param.yukkuri;
946 setYukkuri: function(yukkuri){
947 this.param.yukkuri = yukkuri;
948 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
950 getHungry: function(){
951 return this.param.hungry;
953 setHungry: function(hungry){
954 this.param.hungry = hungry;
955 if(this.param.hungry < 0)this.param.hungry = 0;
958 return this.param.unun;
960 setUnun: function(unun){
961 this.param.unun = unun;
962 if(this.param.unun < 0)this.param.unun = 0;
968 this.setHungry(this.param.hungry - food.getGive());
969 this.setUnun(this.getUnun() + food.getGive() / 4);
970 this.setYukkuri(this.getYukkuri() + 5);
973 this.setYukkuri(this.getYukkuri() - 5);
978 if(this.direction == EDirection.RIGHT){
979 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
981 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
985 setBodyImage: function(ebody){
986 var path = this.bodyStatus[ebody];
987 this.image = game.assets[path];
990 this.imgBody.tl.pause();
991 this.imgGroup.tl.pause();
992 this.imgBody.tl.clear();
993 this.imgGroup.tl.clear();
995 tlResume: function(){
996 this.imgBody.tl.resume();
997 this.imgGroup.tl.resume();
1000 destruct: function(){
1004 var Marisa = enchant.Class.create(Yukkuri,{
1005 initialize: function(x, y){
1006 Yukkuri.call(this,x,y);
1007 this.classname = "Marisa";
1010 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1011 var json = net.load("./data/marisa/params.json");
1012 this.param = json.root.param;
1013 this.shadow = new enchant.Sprite(64, 64);
1014 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1015 this.shadow.x = 0 + this.x;
1016 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1017 this.shadow.image._element.style.zIndex = 2;
1019 this._style.zIndex = 5;
1021 this.face = new enchant.Sprite(64, 64);
1022 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1023 this.face.x = -CHARA_WIDTH / 2;
1024 this.face.y = -CHARA_HEIGHT / 2;
1025 this.face._style.zIndex = 0;
1027 this.faceStatus ={};
1028 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1029 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1030 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1031 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1032 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1033 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1034 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1035 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1036 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1037 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1040 this.hear = new enchant.Sprite(64, 64);
1041 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1042 this.hear.x = -CHARA_WIDTH / 2;
1043 this.hear.y = -CHARA_HEIGHT / 2;
1044 this.hear._style.zIndex = 0;
1046 this.okazari = new Okazari();
1047 this.okazari.image._element.style.zIndex = 1;
1049 // this.imgGroup._style.zIndex = 1;
1051 this.imgGroup.addChild(this.shadow);
1052 this.imgBody.addChild(this);
1053 this.imgBody.addChild(this.face);
1054 this.imgBody.addChild(this.hear);
1055 this.imgBody.addChild(this.okazari);
1056 this.imgGroup.addChild(this.imgBody);
1057 backgroundMap.addChild(this.imgGroup);
1058 this._tweet = new TTweet(148, 64);
1059 this._tweet.image._element.style.zIndex = 20;
1061 this.imgGroup.addChild(this._tweet);
1062 this.imgGroup.x = x;
1063 this.imgGroup.y = y;
1065 this.action = new Action(this);
1069 setFaceImage: function(eface){
1070 var path = this.faceStatus[eface];
1071 this.face.image = game.assets[path];
1074 var Player = enchant.Class.create(Marisa,{
1075 initialize: function(x, y){
1076 // this.runEnterframe = function(){
1078 Marisa.call(this, x, y);
1079 this.classname = "Player";
1080 ctl.setPlayer(this);
1081 // this.removeEventListener('enterframe',this.runEnterframe);
1082 this.addEventListener('enterframe', function(){
1083 if(this.age%10 === 0 && this.age !== 0){
1084 // console.log("palyer:" + this.age);
1087 ///////////////////////////////////////////////
1088 //Action pattern for debug
1089 if(game.input.left){
1090 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1092 this.direction = EDirection.LEFT;
1094 if(game.input.right){
1096 this.direction = EDirection.RIGHT;
1100 this.tweet("ゆっくりしていってね!");
1103 if(game.input.down){
1106 ///////////////////////////////////////////////
1108 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1109 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1111 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1113 //- Display the circle of search range.
1114 // fieldBg.image.clear();
1115 // fieldBg.image.context.beginPath();
1116 // fieldBg.image.context.fillStyle = '#ff0000';
1117 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1118 // fieldBg.image.context.fill();
1122 game.onload = function(){
1124 mangTouch = new MangTouch(ctl);
1125 mangMsg = new MangMsg(ctl);
1126 ctl.setDefined(def);
1127 backgroundMap.image = game.assets[EResPath.MAP0];
1128 backgroundMap.loadData(_mapData);
1129 backgroundMap.collisionData = _collisionData;
1131 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1132 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1133 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1134 fieldBg.image = fieldSurface;
1138 windowFront.image = windowSurface;
1141 windowFront.opacity = 0.5;
1143 windowSurface.context.fillStyle = '#000';
1144 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1147 menuSurface.context.fillStyle = '#000';
1148 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1149 menuBg.image = menuSurface;
1150 menuBg.x = EMenuPos.X;
1151 menuBg.y = EMenuPos.Y;
1152 backgroundMap.addChild(fieldBg);
1153 mangIcon = new MangIcon(ctl, menuBg);
1155 game.rootScene.addChild(backgroundMap);
1156 game.rootScene.addChild(windowFront);
1157 game.rootScene.addChild(menuBg);
1159 // var labelGroup = new LabelGroup();
1160 mangLabel = new MangLabel(ctl, menuBg);
1161 // var info = new Label("ゆっくり");
1162 // info.color = "#ffffff";
1163 // info.font = "14px 'Times New Roman'";
1165 // info.y = GAME_HEIGHT / 2;
1166 // labelGroup.addChild(info);
1167 // menuBg.addChild(labelGroup);
1170 // var food = new def.Food("apple", 200, 250);
1171 backgroundMap.addChild(foodGroup);
1172 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1173 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y);
1176 game.rootScene.addEventListener('touchstart', function (e) {
1177 game.touched = true;
1178 var mang = mangTouch.get(ctl.getCurrentCommand());
1181 game.rootScene.addEventListener('touchmove', function (e) {
1182 var mang = mangTouch.get(ctl.getCurrentCommand());
1185 game.rootScene.addEventListener('touchend', function (e) {
1186 var mang = mangTouch.get(ctl.getCurrentCommand());
1188 game.touched = false;
1192 game.rootScene.addEventListener('enterframe', function(){
1194 mangLabel.draw(player);
1197 this.addEventListener('enterframe', function(){
1198 //The priority processing of display instead of z-index
1199 backgroundMap.childNodes.sort(
1201 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1204 else if(typeof a.id === "undefined"){
1207 else if(typeof b.id === "undefined"){
1210 if(a.y < b.y)return -1;
1211 if(a.y > b.y)return 1;