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 // var DAY = HOUR * 24;
29 YUKKURI_BASE : './data/yukkuri_base.png',
30 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
31 YUKKURI_UNUN : './data/unun.png',
32 YUKKURI_SHADOW : './data/shadow.png',
33 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
34 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
35 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
36 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
37 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
38 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
39 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
40 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
41 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
42 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
43 MARISA_HEAR : './data/marisa/hear1.png',
44 OBJECT : './data/object.png',
45 MAP0 : './data/map0.png',
46 COMMAND : './data/command.png',
47 OKAZARI : './data/okazari.png',
48 PLACE_TREE : './data/system/place_tree.png',
49 // PLACE_TREE : './data/system/rapture.png',
84 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
95 MOVE_TO_EAT_START: 10,
96 MOVE_TO_EAT_UNDERWAY: 11,
100 UNUN_SMELL_START : 15,
101 UNUN_SMELL_WAIT : 16,
104 COMMUNICATE_START : 19,
105 COMMUNICATE_WAIT: 20,
106 COMMUNICATE_RECV: 21,
126 var EWalkAnimation = {
130 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
141 //-Event register [onactionstart,onactiontick,onactionend]
142 if(eventFunctions !== undefined){
143 for(var key in eventFunctions){
144 params[key] = eventFunctions[key];
147 return this.tween(params);
152 include("./lang/ja.js");
153 window.onload = function(){
156 var def = new Object();
157 var foodGroup = new Group();
158 // var placeGroup = new Group();
159 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
160 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
161 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
162 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
163 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
167 for(var _v in EResPath){
168 _loadArr[i] = EResPath[_v];
171 game.preload(_loadArr);
172 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
173 var backgroundMap = new MapGroup(16, 16);
174 include("./class.js");
175 include("./ctrl.js");
178 ctl.setBackgroundMap(backgroundMap);
179 var Action = enchant.Class.create({
180 initialize: function (yukkuri){
181 this.status = EAction.THINK;
182 this.yukkuri = yukkuri;
183 this.isMoving = false;
184 this.targetNode = null;
186 getStatus: function(){
189 setStatus: function(eaction){
190 this.status = eaction;
193 if(this.yukkuri.isDead()){
194 this.status = EAction.DEAD;
196 // else if(this.yukkuri.isSleep()){
197 // this.status = EAction.SLEEP;
202 // console.log("status:" + this.status + ":" + this.yukkuri.id);
210 if(this.yukkuri.age%2 === 0){
211 if(this.yukkuri.isSleep()){
212 this.setStatus(EAction.SLEEP_START);
214 else if(this.yukkuri.getUnun() >= 80){
215 this.setStatus(EAction.UNUN_START);
217 // this.yukkuri.param.yukkuri -= 1;
218 this.yukkuri.changeFace();
224 case EAction.MOVE_TO_EAT_START:
225 this.move_to_eat_start();
227 case EAction.MOVE_TO_EAT_UNDERWAY:
233 case EAction.SLEEP_START:
236 case EAction.SLEEP_WAIT:
241 case EAction.EAT_START:
244 case EAction.EAT_WAIT:
246 case EAction.UNUN_START:
249 case EAction.UNUN_WAIT:
251 case EAction.MOVE_TO_COMMAND:
252 this.move_to_command();
254 case EAction.UNUN_SMELL_START:
255 this.unun_smell_start();
257 case EAction.COMMUNICATE_START:
258 this.communicate_start();
260 case EAction.COMMUNICATE_WAIT:
262 case EAction.COMMUNICATE_RECV:
266 this.yukkuri.reverse();
269 move_to_eat_start : function(){
272 "targetNode": this.targetNode,
274 "myYukkuri": this.yukkuri
280 walk : function(retryCounter){
281 if(retryCounter > 15){
283 this.status = EAction.NONE;
284 console.log("retryCount over");
287 if(this.yukkuri.imgGroup.tl.queue.length === 0){
290 this.isMoving = false;
291 this.status = EAction.THINK;
295 var xpos = 150 + rand(40) - (retryCounter * 10);
296 var ypos = 150 + rand(40) - (retryCounter * 10);
299 this.yukkuri.vy = -ypos;
301 else if(rand(8) == 1){
302 this.yukkuri.vx = xpos;
303 this.yukkuri.vy = -ypos;
304 this.yukkuri.direction = EDirection.RIGHT;
306 else if(rand(8) == 2){
307 this.yukkuri.vx = xpos;
309 this.yukkuri.direction = EDirection.RIGHT;
311 else if(rand(8) == 3){
312 this.yukkuri.vx = xpos;
313 this.yukkuri.vy = ypos;
314 this.yukkuri.direction = EDirection.RIGHT;
316 else if(rand(8) == 4){
318 this.yukkuri.vy = ypos;
320 else if(rand(8) == 5){
321 this.yukkuri.vx = -xpos;
322 this.yukkuri.vy = ypos;
323 this.yukkuri.direction = EDirection.LEFT;
325 else if(rand(8) == 6){
326 this.yukkuri.vx = -xpos;
328 this.yukkuri.direction = EDirection.LEFT;
330 else if(rand(8) == 7){
331 this.yukkuri.vx = -xpos;
332 this.yukkuri.vy = -ypos;
333 this.yukkuri.direction = EDirection.LEFT;
335 if (this.yukkuri.vx || this.yukkuri.vy) {
336 var map = ctl.backgroundMap;
337 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
338 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
339 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
340 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
341 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
342 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
343 // console.log("X:" + this.yukkuri.moveX);
344 // console.log("Y:" + this.yukkuri.moveY);
345 this.isMoving = true;
346 this.yukkuri.reverse();
347 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
348 mangMsg.output(this.yukkuri,EMsg.WALK);
350 this.targetNode = null;
352 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
353 this.walk(retryCounter+1);
359 sleep_start: function(){
362 "myYukkuri": this.yukkuri
367 mangMsg.output(this.yukkuri, EMsg.DEAD);
368 this.yukkuri.tlPause();
369 this.yukkuri.setBodyImage(EBody.DEAD);
371 eat_start: function(){
374 "targetNode": this.targetNode,
376 "myYukkuri": this.yukkuri
380 unun_start: function(){
383 "myYukkuri": this.yukkuri
386 unun_smell_start: function(){
389 "myYukkuri": this.yukkuri
392 communicate_start:function(){
393 new ComFirstSendEvent({
395 "targetNode": this.targetNode,
397 "myYukkuri": this.yukkuri
400 move_to_command: function(){
404 var nodes = ctl.getObjs();
408 for (var key in nodes) {
409 var node = nodes[key];
410 if(this.yukkuri.id === node.id)continue;
412 && node instanceof Unun
413 && !(this.targetNode instanceof Unun)
414 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
416 this.targetNode = node;
417 this.setStatus(EAction.UNUN_SMELL_START);
420 else if (node instanceof Food) {
421 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
423 //A yukkuri to go to the food area
424 this.targetNode = node;
425 this.setStatus(EAction.MOVE_TO_EAT_START);
429 //not hunbry or not food.
432 else if(node instanceof Yukkuri){
433 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
434 this.targetNode = node;
435 this.setStatus(EAction.COMMUNICATE_START);
440 this.status = EAction.WALK;
443 var Event = enchant.Class.create({
444 initialize: function (_data){
445 this.progress = null;
447 setProgress: function(progress){
448 this.progress = progress;
450 onactionstart:function(self){
452 if(typeof e === "undefined")return;
455 onactiontick:function(self){
457 if(typeof e === "undefined")return;
460 onactionend:function(self){
462 if(typeof e === "undefined")return;
466 var WalkEvent = enchant.Class.create(Event,{
467 initialize: function (_data){
469 this.yukkuri = _data.myYukkuri;
470 this.action = _data.action;
472 mangMsg.output(this.yukkuri, EMsg.SLEEP);
473 this.action.setStatus(EAction.SLEEP_WAIT);
474 this.yukkuri.setFaceImage(EFace.SLEEP);
475 this.yukkuri.tlPause();
477 this.yukkuri.addEventListener('enterframe', function() {
478 var yukkuri = self.yukkuri;
486 var SleepEvent = enchant.Class.create(Event,{
487 initialize: function (_data){
489 this.yukkuri = _data.myYukkuri;
490 this.action = _data.action;
492 mangMsg.output(this.yukkuri, EMsg.SLEEP);
493 this.action.setStatus(EAction.SLEEP_WAIT);
494 this.yukkuri.setFaceImage(EFace.SLEEP);
495 this.yukkuri.tlPause();
498 this.yukkuri.addEventListener('enterframe', function() {
499 var yukkuri = self.yukkuri;
500 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
501 if(yukkuri.param.sleep <= 0){
502 yukkuri.param.sleep = 0;
503 this.removeEventListener("enterframe",arguments.callee);
504 mangMsg.output(self.yukkuri, EMsg.GET_UP);
505 yukkuri.setFaceImage(EFace.NORMAL);
507 // self.action.setStatus(EAction.WAIT);
508 self.action.setStatus(EAction.THINK);
514 var UnunEvent = enchant.Class.create(Event,{
515 initialize: function (_data){
517 this.yukkuri = _data.myYukkuri;
518 this.action = _data.action;
519 this.action.setStatus(EAction.UNUN_WAIT);
520 mangMsg.output(this.yukkuri, EMsg.UNUN);
521 this.yukkuri.setFaceImage(EFace.HAPPY2);
524 this.yukkuri.wait(sec, {
525 "onactionstart": this.onactionstart(this),
526 "onactiontick": this.onactiontick(this),
527 "onactionend": this.onactionend(this)
530 onactionstart:function(self){
532 if(typeof e === "undefined")return;
535 onactiontick:function(self){
537 if(typeof e === "undefined")return;
540 onactionend:function(self){
542 if(typeof e === "undefined")return;
544 self.action.setStatus(EAction.WAIT);
545 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
547 "waitframe": FPS * 1.5,
548 "action": self.action,
549 "myYukkuri": self.yukkuri
554 var WaitEvent = enchant.Class.create(Event,{
555 initialize: function (_data){
557 this.yukkuri = _data.myYukkuri;
558 this.action = _data.action;
559 this.waitframe = _data.waitframe;
560 this.yukkuri.wait(this.waitframe, {
561 "onactionstart": this.onactionstart(this),
562 "onactiontick": this.onactiontick(this),
563 "onactionend": this.onactionend(this)
566 onactionend:function(self){
568 if(typeof e === "undefined")return;
569 self.action.setStatus(EAction.THINK);
573 var UnunSmellEvent = enchant.Class.create(Event,{
574 initialize: function (_data){
576 this.yukkuri = _data.myYukkuri;
577 this.action = _data.action;
578 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
579 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
580 this.yukkuri.setFaceImage(EFace.CRY1);
582 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
583 this.yukkuri.wait(sec, {
584 "onactionstart": this.onactionstart(this),
585 "onactiontick": this.onactiontick(this),
586 "onactionend": this.onactionend(this)
589 onactionend:function(self){
591 if(typeof e === "undefined")return;
592 self.action.setStatus(EAction.THINK);
597 var EatEvent = enchant.Class.create(Event,{
598 initialize: function (_data){
600 this.yukkuri = _data.myYukkuri;
601 this.food = _data.targetNode;
602 this.action = _data.action;
603 this.action.setStatus(EAction.EAT_WAIT);
606 var sec = BASE_FPS * 3;
607 if(this.yukkuri.eat(this.food)){
608 mangMsg.output(this.yukkuri, EMsg.EAT);
609 this.yukkuri.setFaceImage(EFace.EAT2);
612 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
613 this.yukkuri.setFaceImage(EFace.CRY2);
615 this.yukkuri.wait(sec, {
616 "onactionend": this.onactionend(this)
619 onactionend:function(self){
621 if(typeof e === "undefined")return;
622 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
623 self.action.setStatus(EAction.THINK);
624 self.yukkuri.setFaceImage(EFace.NORMAL);
626 self.action.setStatus(EAction.EAT_START);
633 * -When yukkuri find Food.
636 * targetNode: enchant.Node
640 var MoveToEatEvent = enchant.Class.create(Event,{
641 initialize: function (_data){
643 this.yukkuri = this.data.myYukkuri;
644 this.action = this.data.action;
646 var yukkuri = this.yukkuri;
647 var node = this.data.targetNode;
649 if(this.data.type == "food"){
650 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
651 yukkuri.vx = node.x - yukkuri.getX();
652 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
653 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
654 var frame = distance + distance/5 + 1;
655 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
658 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
659 "onactionstart": this.onactionstart(this),
660 "onactiontick": this.onactiontick(this),
661 "onactionend": this.onactionend(this)
665 onactionstart:function(self){
667 if(typeof e === "undefined")return;
668 self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
671 onactiontick:function(self){
673 if(typeof e === "undefined")return;
676 onactionend:function(self){
678 if(typeof e === "undefined")return;
679 self.action.setStatus(EAction.EAT_START);
683 var MoveCommandEvent = enchant.Class.create(Event,{
684 initialize: function (_data){
686 this.yukkuri = this.data.myYukkuri;
687 this.action = this.data.action;
688 this.vx = this.data.vx;
689 this.vy = this.data.vy;
691 var yukkuri = this.yukkuri;
692 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
693 yukkuri.vx = node.x - yukkuri.getX();
694 yukkuri.vy = node.y - yukkuri.getY();
695 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
696 var frame = distance + 1;
697 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
698 "onactionstart": this.onactionstart(this),
699 "onactiontick": this.onactiontick(this),
700 "onactionend": this.onactionend(this)
703 onactionstart:function(self){
705 if(typeof e === "undefined")return;
708 onactiontick:function(self){
710 if(typeof e === "undefined")return;
713 onactionend:function(self){
715 if(typeof e === "undefined")return;
716 self.action.setStatus(EAction.THINK);
721 * First contact to send communication .
723 var ComFirstSendEvent = enchant.Class.create(Event,{
724 initialize: function (_data){
726 this.yukkuri = _data.myYukkuri;
727 this.targetYukkuri = _data.targetNode;
728 this.action = _data.action;
729 this.action.setStatus(EAction.COMMUNICATE_WAIT);
730 this.setProgress("start");
731 mangMsg.output(this.yukkuri, EMsg.GREETING);
732 // this.targetYukkuri.recvCommunication(this.yukkuri, this);
734 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
735 this.targetYukkuri.tlPause();
736 this.yukkuri.tlPause();
737 this.yukkuri.syncDirection(this.targetYukkuri);
739 this.yukkuri.addAddress(this.targetYukkuri);
740 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
742 var sec = BASE_FPS * 2;
743 this.yukkuri.wait(sec, {
744 "onactiontick": this.onactiontick(this),
745 "onactionend": this.onactionend(this)
748 onactiontick:function(self){
750 if(typeof e === "undefined")return;
751 self.setProgress("tick");
754 onactionend:function(self){
756 if(typeof e === "undefined")return;
757 self.setProgress("end");
758 new ComFirstRecvEvent({
760 "targetNode": self.yukkuri,
761 "action": self.targetYukkuri.action,
762 "myYukkuri": self.targetYukkuri
765 // self.targetYukkuri.recvCommunication(self.yukkuri, self);
769 var ComFirstRecvEvent = enchant.Class.create(Event,{
770 initialize: function (_data){
772 this.yukkuri = _data.myYukkuri;
773 this.targetYukkuri = _data.targetNode;
774 this.action = _data.action;
775 this.setProgress("start");
776 mangMsg.output(this.yukkuri, EMsg.GREETING);
777 this.yukkuri.addAddress(this.targetYukkuri);
778 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
780 var sec = BASE_FPS * 2;
781 this.yukkuri.wait(sec, {
782 "onactiontick": this.onactiontick(this),
783 "onactionend": this.onactionend(this)
786 onactiontick:function(self){
788 if(typeof e === "undefined")return;
789 self.setProgress("tick");
792 onactionend:function(self){
794 if(typeof e === "undefined")return;
795 self.setProgress("end");
796 self.action.setStatus(EAction.THINK);
798 self.yukkuri.action.setStatus(EAction.THINK);
799 self.yukkuri.animation();
800 self.targetYukkuri.action.setStatus(EAction.THINK);
801 self.targetYukkuri.animation();
802 // self.targetYukkuri.recvCommunication(self.yukkuri, self);
808 var ObjSprite = enchant.Class.create(enchant.Sprite,{
809 initialize: function (w, h){
810 enchant.Sprite.call(this, w, h);
814 removeAll: function(){
820 var Food = enchant.Class.create(ObjSprite,{
821 initialize: function (type, x, y){
822 this.classname = "Food";
823 ObjSprite.call(this,16,16);
824 this.image = game.assets[EResPath.OBJECT];
828 //一つにつきgiveの値分、hunguryを減少させられる
831 foodGroup.addChild(this);
832 this.addEventListener('enterframe', function(){
833 if(this.amount <= 0){
838 getAmount: function(){
845 var Place= enchant.Class.create(ObjSprite,{
846 initialize: function (type, x, y){
847 ObjSprite.call(this,128,128);
848 this.image = game.assets[EResPath.PLACE_TREE];
849 this.x = x - this.width / 2;
850 this.y = y - this.height / 2;
851 // placeGroup.addChild(this);
852 backgroundMap.addChild(this);
854 // this.addEventListener('enterframe', function(){
857 // if(this.age%10 === 0 && this.age !== 0){
858 // console.log("x/y " + this.x + "/" + this.y);
860 // if(game.input.left){
863 // if(game.input.right){
866 // if(game.input.up){
869 // if(game.input.down){
876 var Unun = enchant.Class.create(ObjSprite,{
877 initialize: function (x, y){
878 this.classname = "Unun";
879 ObjSprite.call(this,32,32);
880 this.image = game.assets[EResPath.YUKKURI_UNUN];
883 backgroundMap.addChild(this);
886 var Okazari = enchant.Class.create(enchant.Sprite,{
887 initialize: function(){
888 this.classname = "Okazari";
889 enchant.Sprite.call(this, 64, 64);
890 this.image = game.assets[EResPath.OKAZARI];
891 this.x = -CHARA_WIDTH / 2;
892 this.y = -12 - CHARA_HEIGHT / 2;
895 var Address = enchant.Class.create({
896 initialize: function(yukkuri){
898 this.yukkuri = yukkuri;
899 this.isGreeting = false;
900 this.greetingWaitFrame = 0;
904 var Yukkuri = enchant.Class.create(ObjSprite,{
905 initialize: function(x, y){
906 ObjSprite.call(this, 64, 64);
907 this.classname = "Yukkuri";
908 this.addressBook = {};
909 this.imgGroup = new SpriteGroup();
910 this.imgBody = new SpriteGroup();
911 this.imgGroup.id = guid();
912 this.imgBody.id = guid();
913 this.x = -CHARA_WIDTH / 2;
914 this.y = -CHARA_HEIGHT / 2;
917 this.image = game.assets[EResPath.YUKKURI_BASE];
918 this.direction = EDirection.RIGHT;
919 this.addEventListener('enterframe', this.runEnterframe);
921 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
922 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
923 this.walkAnimationStatus = EWalkAnimation.END;
925 runEnterframe:function(){
927 if(this.isDead())return;
935 if(this.direction == EDirection.RIGHT){
936 this.imgBody.scaleX = 1;
938 else if(this.direction == EDirection.LEFT){
939 this.imgBody.scaleX = -1;
942 tweet:function(text){
943 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
945 moveTo:function(x, y, time){
946 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
948 moveBy:function(x, y, time, eventFunctions){
952 return self.imgGroup.x + x;
955 return self.imgGroup.y + y;
958 easing: enchant.Easing.SIN_EASEINOUT
960 //-Event register [onactionstart,onactiontick,onactionend]
961 if(eventFunctions !== undefined){
962 for(var key in eventFunctions){
963 params[key] = eventFunctions[key];
966 return this.imgGroup.tl.tween(params);
968 wait:function(frame, eventFunctions){
969 this.moveBy(0,1,frame,eventFunctions);
974 animation: function(){
975 if(this.walkAnimationStatus == EWalkAnimation.END){
976 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
977 "onactionstart": function(e){
978 this.walkAnimationStatus = EWalkAnimation.START;
981 .moveByEx(0, 5, 10, enchant.Easing.SWING,
983 "onactionend": function(e){
984 this.walkAnimationStatus = EWalkAnimation.END;
989 this.imgBody.tl.loop();
991 // this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING)
992 // this.imgBody.tl.moveByEx(0, 5, 10, enchant.Easing.SWING);
993 // this.imgBody.tl.loop();
994 // this.moveBy(0, -5, 10).moveBy(0, 5, 10).loop();
997 getWidth: function(){
1000 getHeight: function(){
1004 return this.imgGroup.x;
1007 return this.imgGroup.y;
1010 this.imgGroup.x += x;
1012 // this.shadow.x += x;
1013 // this._tweet.x += x;
1016 this.imgGroup.y += y;
1018 // this.shadow.y += y;
1019 // this._tweet.y += y;
1021 // changeFace: function(erespath){
1022 // this.face.image = game.assets[erespath];
1024 loadParamsXML: function(url){
1025 var http = new JKL.ParseXML( url );
1026 return http.parse();
1028 runYukkuri: function(){
1029 if(this.param.hungry > 70){
1030 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1031 this.param.yukkuri -= 1;
1034 else if(this.param.hungry < 10){
1035 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1038 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1039 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1041 runHungry: function(){
1042 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1043 if(this.param.hungry >= 100)this.param.hungry = 100;
1045 runUnun: function(){
1046 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1047 if(this.param.unun >= 100)this.param.unun = 100;
1049 runSleep: function(){
1050 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1051 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1052 if(this.param.sleep >= 100){
1053 this.param.sleep = 100;
1057 runAddress: function(){
1058 for(var key in this.addressBook){
1059 var address = this.addressBook[key];
1061 if(address.isGreeting){
1062 address.greetingWaitFrame++;
1063 if(address.greetingWaitFrame >= DAY){
1064 address.greetingWaitFrame = 0;
1065 address.isGreeting = false;
1070 changeFace: function(){
1071 if(this.param.yukkuri >= 80){
1072 this.setFaceImage(EFace.HAPPY1);
1074 else if(this.param.yukkuri >= 50){
1075 this.setFaceImage(EFace.NORMAL);
1077 else if(this.param.yukkuri >= 30){
1078 this.setFaceImage(EFace.TIRED);
1080 else if(this.param.yukkuri >= 10){
1081 this.setFaceImage(EFace.CRY1);
1083 else if(this.param.yukkuri >= 1){
1084 this.setFaceImage(EFace.CRY2);
1087 getRange: function(){
1088 return this.param.range;
1090 isSleep: function(){
1091 return this.param.sleep >= 100;
1094 return this.param.yukkuri <= 0;
1096 isManpuku: function(){
1097 return this.param.hungry <= 20;
1099 isKuhuku: function(){
1100 return this.param.hungry >= 40;
1102 getYukkuri: function(){
1103 return this.param.yukkuri;
1105 setYukkuri: function(yukkuri){
1106 this.param.yukkuri = yukkuri;
1107 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1109 getHungry: function(){
1110 return this.param.hungry;
1112 setHungry: function(hungry){
1113 this.param.hungry = hungry;
1114 if(this.param.hungry < 0)this.param.hungry = 0;
1116 getUnun: function(){
1117 return this.param.unun;
1119 setUnun: function(unun){
1120 this.param.unun = unun;
1121 if(this.param.unun < 0)this.param.unun = 0;
1125 if(food.amount > 0){
1127 this.setHungry(this.param.hungry - food.getGive());
1128 this.setUnun(this.getUnun() + food.getGive() / 4);
1129 this.setYukkuri(this.getYukkuri() + 5);
1132 this.setYukkuri(this.getYukkuri() - 5);
1137 if(this.direction == EDirection.RIGHT){
1138 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1140 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1144 setBodyImage: function(ebody){
1145 var path = this.bodyStatus[ebody];
1146 this.image = game.assets[path];
1149 // this.imgBody.tl.pause();
1150 // this.imgGroup.tl.pause();
1151 // this.imgBody.tl.clear();
1152 // this.imgGroup.tl.clear();
1153 this.imgBody.tl.unloop();
1154 this.imgGroup.tl.unloop();
1156 tlResume: function(){
1157 // this.imgBody.tl.resume();
1158 // this.imgGroup.tl.resume();
1161 syncDirection:function(senderYukkuri){
1162 if(this.getX() > senderYukkuri.getX()){
1163 this.direction = EDirection.LEFT;
1164 senderYukkuri.direction = EDirection.RIGHT;
1166 this.direction = EDirection.RIGHT;
1167 senderYukkuri.direction = EDirection.LEFT;
1170 // recvCommunication: function(senderYukkuri, event){
1171 // if(event instanceof ComFirstSendEvent){
1172 // if(event.progress == "start"){
1173 // this.action.setStatus(EAction.COMMUNICATE_RECV);
1175 // this.syncDirection(senderYukkuri);
1178 // else if(event.progress == "end"){
1179 // new ComFirstRecvEvent({
1180 // "type": 'greeting',
1181 // "targetNode": senderYukkuri,
1182 // "action": this.action,
1183 // "myYukkuri": this
1187 // if(event instanceof ComFirstRecvEvent){
1188 // if(event.progress == "end"){
1189 // senderYukkuri.action.setStatus(EAction.THINK);
1190 // senderYukkuri.animation();
1191 // this.action.setStatus(EAction.THINK);
1192 // this.animation();
1197 isCommunication: function(yukkuri){
1198 if(this.addressBook[yukkuri.id] === undefined) return true;
1199 if(this.addressBook[yukkuri.id].isGreeting) return false;
1202 addAddress: function(yukkuri){
1203 this.addressBook[yukkuri.id] = new Address(yukkuri);
1205 getAddress: function(yukkuri){
1206 return this.addressBook[yukkuri.id];
1208 destruct: function(){
1212 var Marisa = enchant.Class.create(Yukkuri,{
1213 initialize: function(x, y){
1214 Yukkuri.call(this,x,y);
1215 this.classname = "Marisa";
1218 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1219 var json = net.load("./data/marisa/params.json");
1220 this.param = json.root.param;
1221 this.shadow = new enchant.Sprite(64, 64);
1222 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1223 this.shadow.x = 0 + this.x;
1224 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1225 this.shadow.image._element.style.zIndex = 2;
1227 this._style.zIndex = 5;
1229 this.face = new enchant.Sprite(64, 64);
1230 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1231 this.face.x = -CHARA_WIDTH / 2;
1232 this.face.y = -CHARA_HEIGHT / 2;
1233 this.face._style.zIndex = 0;
1235 this.faceStatus ={};
1236 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1237 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1238 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1239 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1240 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1241 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1242 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1243 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1244 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1245 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1248 this.hear = new enchant.Sprite(64, 64);
1249 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1250 this.hear.x = -CHARA_WIDTH / 2;
1251 this.hear.y = -CHARA_HEIGHT / 2;
1252 this.hear._style.zIndex = 0;
1254 this.okazari = new Okazari();
1255 this.okazari.image._element.style.zIndex = 1;
1257 // this.imgGroup._style.zIndex = 1;
1259 this.imgGroup.addChild(this.shadow);
1260 this.imgBody.addChild(this);
1261 this.imgBody.addChild(this.face);
1262 this.imgBody.addChild(this.hear);
1263 this.imgBody.addChild(this.okazari);
1264 this.imgGroup.addChild(this.imgBody);
1265 backgroundMap.addChild(this.imgGroup);
1266 this._tweet = new TTweet(148, 64);
1267 this._tweet.image._element.style.zIndex = 20;
1269 this.imgGroup.addChild(this._tweet);
1270 this.imgGroup.x = x;
1271 this.imgGroup.y = y;
1273 this.action = new Action(this);
1277 setFaceImage: function(eface){
1278 var path = this.faceStatus[eface];
1279 this.face.image = game.assets[path];
1282 var Player = enchant.Class.create(Marisa,{
1283 initialize: function(x, y){
1284 // this.runEnterframe = function(){
1286 Marisa.call(this, x, y);
1287 this.classname = "Player";
1288 ctl.setPlayer(this);
1289 // this.removeEventListener('enterframe',this.runEnterframe);
1290 this.addEventListener('enterframe', function(){
1293 if(this.age%10 === 0 && this.age !== 0){
1294 // console.log("palyer:" + this.age);
1297 ///////////////////////////////////////////////
1298 //Action pattern debug
1299 // if(game.input.left){
1300 // // this.changeFace(EResPath.MARISA_FACE_TIRED);
1302 // this.direction = EDirection.LEFT;
1304 // if(game.input.right){
1306 // this.direction = EDirection.RIGHT;
1308 // if(game.input.up){
1310 // this.tweet("ゆっくりしていってね!");
1313 // if(game.input.down){
1316 ///////////////////////////////////////////////
1318 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1319 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1321 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1323 //- Display the circle of search range.
1324 // fieldBg.image.clear();
1325 // fieldBg.image.context.beginPath();
1326 // fieldBg.image.context.fillStyle = '#ff0000';
1327 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1328 // fieldBg.image.context.fill();
1332 game.onload = function(){
1335 mangTouch = new MangTouch(ctl);
1336 mangMsg = new MangMsg(ctl);
1337 ctl.setDefined(def);
1338 backgroundMap.image = game.assets[EResPath.MAP0];
1339 backgroundMap.loadData(_mapData);
1340 backgroundMap.collisionData = _collisionData;
1342 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1343 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1344 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1345 fieldBg.image = fieldSurface;
1349 windowFront.image = windowSurface;
1352 windowFront.opacity = 0.5;
1354 windowSurface.context.fillStyle = '#000';
1355 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1358 menuSurface.context.fillStyle = '#000';
1359 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1360 menuBg.image = menuSurface;
1361 menuBg.x = EMenuPos.X;
1362 menuBg.y = EMenuPos.Y;
1363 backgroundMap.addChild(fieldBg);
1364 mangIcon = new MangIcon(ctl, menuBg);
1366 game.rootScene.addChild(backgroundMap);
1367 game.rootScene.addChild(windowFront);
1368 game.rootScene.addChild(menuBg);
1370 // var labelGroup = new LabelGroup();
1371 mangLabel = new MangLabel(ctl, menuBg);
1372 // var info = new Label("ゆっくり");
1373 // info.color = "#ffffff";
1374 // info.font = "14px 'Times New Roman'";
1376 // info.y = GAME_HEIGHT / 2;
1377 // labelGroup.addChild(info);
1378 // menuBg.addChild(labelGroup);
1381 // var food = new def.Food("apple", 200, 250);
1382 backgroundMap.addChild(foodGroup);
1383 // backgroundMap.addChild(placeGroup);
1384 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1385 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y);
1388 game.rootScene.addEventListener('touchstart', function (e) {
1389 game.touched = true;
1390 var mang = mangTouch.get(ctl.getCurrentCommand());
1393 game.rootScene.addEventListener('touchmove', function (e) {
1394 var mang = mangTouch.get(ctl.getCurrentCommand());
1397 game.rootScene.addEventListener('touchend', function (e) {
1398 var mang = mangTouch.get(ctl.getCurrentCommand());
1400 game.touched = false;
1404 game.rootScene.addEventListener('enterframe', function(){
1406 mangLabel.draw(player);
1408 this.addEventListener('enterframe', function(){
1409 //The priority processing of display instead of z-index
1410 backgroundMap.childNodes.sort(
1412 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1415 else if(typeof a.id === "undefined"){
1418 else if(typeof b.id === "undefined"){
1423 if(a instanceof Place){
1424 ay += Math.round(a.height * 0.7);
1426 else if(b instanceof Place){
1427 by += Math.round(b.height * 0.7);
1430 if(ay < by)return -1;
1431 if(ay > by)return 1;