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,
107 MOVE_TO_PLACE_START_HOMELESS: 22,
108 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
109 DECLARE_PLACE_HOMELESS: 24,
110 MOVE_TO_HUNT_START: 25,
133 var EWalkAnimation = {
137 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
148 //-Event register [onactionstart,onactiontick,onactionend]
149 if(eventFunctions !== undefined){
150 for(var key in eventFunctions){
151 params[key] = eventFunctions[key];
154 return this.tween(params);
159 include("./lang/ja.js");
160 window.onload = function(){
163 var def = new Object();
164 var foodGroup = new Group();
165 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
166 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
167 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
168 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
169 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
173 for(var _v in EResPath){
174 _loadArr[i] = EResPath[_v];
177 game.preload(_loadArr);
178 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
179 var backgroundMap = new MapGroup(16, 16);
180 include("./class.js");
181 include("./ctrl.js");
184 ctl.setBackgroundMap(backgroundMap);
185 var Action = enchant.Class.create({
186 initialize: function (yukkuri){
187 this.status = EAction.THINK;
188 this.yukkuri = yukkuri;
189 this.isMoving = false;
190 this.targetNode = null;
192 getStatus: function(){
195 setStatus: function(eaction){
196 this.status = eaction;
199 if(this.yukkuri.isDead()){
200 this.status = EAction.DEAD;
202 // else if(this.yukkuri.isSleep()){
203 // this.status = EAction.SLEEP;
208 // console.log("status:" + this.status + ":" + this.yukkuri.id);
216 if(this.yukkuri.age%2 === 0){
217 if(this.yukkuri.isSleep()){
218 this.setStatus(EAction.SLEEP_START);
220 else if(this.yukkuri.getUnun() >= 80){
221 this.setStatus(EAction.UNUN_START);
224 // this.yukkuri.param.yukkuri -= 1;
225 this.yukkuri.changeFace();
231 case EAction.MOVE_TO_EAT_START:
232 this.move_to_eat_start();
234 case EAction.MOVE_TO_EAT_UNDERWAY:
240 case EAction.SLEEP_START:
243 case EAction.SLEEP_WAIT:
248 case EAction.EAT_START:
251 case EAction.EAT_WAIT:
253 case EAction.UNUN_START:
256 case EAction.UNUN_WAIT:
258 case EAction.MOVE_TO_COMMAND:
259 this.move_to_command();
261 case EAction.UNUN_SMELL_START:
262 this.unun_smell_start();
264 case EAction.COMMUNICATE_START:
265 this.communicate_start();
267 case EAction.COMMUNICATE_WAIT:
269 case EAction.COMMUNICATE_RECV:
271 case EAction.MOVE_TO_PLACE_START_HOMELESS:
272 this.move_to_place_start_homeless();
274 case EAction.DECLARE_PLACE_HOMELESS:
275 this.declare_place_homeless();
279 this.yukkuri.reverse();
282 move_to_eat_start : function(){
285 "targetNode": this.targetNode,
287 "myYukkuri": this.yukkuri
293 walk : function(retryCounter){
294 if(retryCounter > 15){
296 this.status = EAction.NONE;
297 console.log("retryCount over");
300 if(this.yukkuri.imgGroup.tl.queue.length === 0){
303 this.isMoving = false;
304 this.status = EAction.THINK;
308 var xpos = 150 + rand(40) - (retryCounter * 10);
309 var ypos = 150 + rand(40) - (retryCounter * 10);
312 this.yukkuri.vy = -ypos;
314 else if(rand(8) == 1){
315 this.yukkuri.vx = xpos;
316 this.yukkuri.vy = -ypos;
317 this.yukkuri.direction = EDirection.RIGHT;
319 else if(rand(8) == 2){
320 this.yukkuri.vx = xpos;
322 this.yukkuri.direction = EDirection.RIGHT;
324 else if(rand(8) == 3){
325 this.yukkuri.vx = xpos;
326 this.yukkuri.vy = ypos;
327 this.yukkuri.direction = EDirection.RIGHT;
329 else if(rand(8) == 4){
331 this.yukkuri.vy = ypos;
333 else if(rand(8) == 5){
334 this.yukkuri.vx = -xpos;
335 this.yukkuri.vy = ypos;
336 this.yukkuri.direction = EDirection.LEFT;
338 else if(rand(8) == 6){
339 this.yukkuri.vx = -xpos;
341 this.yukkuri.direction = EDirection.LEFT;
343 else if(rand(8) == 7){
344 this.yukkuri.vx = -xpos;
345 this.yukkuri.vy = -ypos;
346 this.yukkuri.direction = EDirection.LEFT;
348 if (this.yukkuri.vx || this.yukkuri.vy) {
349 var map = ctl.backgroundMap;
350 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
351 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
352 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
353 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
354 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
355 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
356 // console.log("X:" + this.yukkuri.moveX);
357 // console.log("Y:" + this.yukkuri.moveY);
358 this.isMoving = true;
359 this.yukkuri.reverse();
360 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
361 mangMsg.output(this.yukkuri,EMsg.WALK);
363 this.targetNode = null;
365 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
366 this.walk(retryCounter+1);
372 sleep_start: function(){
375 "myYukkuri": this.yukkuri
380 mangMsg.output(this.yukkuri, EMsg.DEAD);
381 this.yukkuri.tlPause();
382 this.yukkuri.setBodyImage(EBody.DEAD);
384 eat_start: function(){
387 "targetNode": this.targetNode,
389 "myYukkuri": this.yukkuri
393 unun_start: function(){
396 "myYukkuri": this.yukkuri
399 unun_smell_start: function(){
402 "myYukkuri": this.yukkuri
405 communicate_start:function(){
406 new ComSayHelloSendEvent({
408 "targetNode": this.targetNode,
410 "myYukkuri": this.yukkuri
413 move_to_place_start_homeless:function(){
414 new MoveToPlaceStartHomelessEvent({
415 "targetNode": this.targetNode,
417 "myYukkuri": this.yukkuri
420 declare_place_homeless:function(){
421 new DeclarePlaceHomelessEvent({
422 "targetNode": this.targetNode,
424 "myYukkuri": this.yukkuri
427 move_to_command: function(){
431 var nodes = ctl.getObjs();
435 for (var key in nodes) {
436 var node = nodes[key];
437 if(this.yukkuri.id === node.id)continue;
439 && node instanceof Unun
440 && !(this.targetNode instanceof Unun)
441 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
443 this.targetNode = node;
444 this.setStatus(EAction.UNUN_SMELL_START);
447 else if (node instanceof Food) {
448 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
450 //A yukkuri to go to the food area
451 this.targetNode = node;
452 this.setStatus(EAction.MOVE_TO_EAT_START);
456 //not hunbry or not food.
459 else if(node instanceof Yukkuri){
460 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
461 this.targetNode = node;
462 this.setStatus(EAction.COMMUNICATE_START);
466 else if(node instanceof Place){
467 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
468 console.log("place!");
469 this.targetNode = node;
470 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
475 this.status = EAction.WALK;
478 var Event = enchant.Class.create({
479 initialize: function (_data){
481 onactionstart:function(self){
483 if(typeof e === "undefined")return;
486 onactiontick:function(self){
488 if(typeof e === "undefined")return;
491 onactionend:function(self){
493 if(typeof e === "undefined")return;
497 var WalkEvent = enchant.Class.create(Event,{
498 initialize: function (_data){
500 this.yukkuri = _data.myYukkuri;
501 this.action = _data.action;
503 mangMsg.output(this.yukkuri, EMsg.SLEEP);
504 this.action.setStatus(EAction.SLEEP_WAIT);
505 this.yukkuri.setFaceImage(EFace.SLEEP);
506 this.yukkuri.tlPause();
508 this.yukkuri.addEventListener('enterframe', function() {
509 var yukkuri = self.yukkuri;
517 var SleepEvent = enchant.Class.create(Event,{
518 initialize: function (_data){
520 this.yukkuri = _data.myYukkuri;
521 this.action = _data.action;
523 mangMsg.output(this.yukkuri, EMsg.SLEEP);
524 this.action.setStatus(EAction.SLEEP_WAIT);
525 this.yukkuri.setFaceImage(EFace.SLEEP);
526 this.yukkuri.tlPause();
529 this.yukkuri.addEventListener('enterframe', function() {
530 var yukkuri = self.yukkuri;
531 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
532 if(yukkuri.param.sleep <= 0){
533 yukkuri.param.sleep = 0;
534 this.removeEventListener("enterframe",arguments.callee);
535 mangMsg.output(self.yukkuri, EMsg.GET_UP);
536 yukkuri.setFaceImage(EFace.NORMAL);
538 // self.action.setStatus(EAction.WAIT);
539 self.action.setStatus(EAction.THINK);
545 var UnunEvent = enchant.Class.create(Event,{
546 initialize: function (_data){
548 this.yukkuri = _data.myYukkuri;
549 this.action = _data.action;
550 this.action.setStatus(EAction.UNUN_WAIT);
551 mangMsg.output(this.yukkuri, EMsg.UNUN);
552 this.yukkuri.setFaceImage(EFace.HAPPY2);
555 this.yukkuri.wait(sec, {
556 "onactionend": this.onactionend(this)
559 onactionend:function(self){
561 if(typeof e === "undefined")return;
563 self.action.setStatus(EAction.WAIT);
564 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
566 "waitframe": FPS * 1.5,
567 "action": self.action,
568 "myYukkuri": self.yukkuri
573 var WaitEvent = enchant.Class.create(Event,{
574 initialize: function (_data){
576 this.yukkuri = _data.myYukkuri;
577 this.action = _data.action;
578 this.waitframe = _data.waitframe;
579 this.yukkuri.wait(this.waitframe, {
580 "onactionstart": this.onactionstart(this),
581 "onactiontick": this.onactiontick(this),
582 "onactionend": this.onactionend(this)
585 onactionend:function(self){
587 if(typeof e === "undefined")return;
588 self.action.setStatus(EAction.THINK);
592 var UnunSmellEvent = enchant.Class.create(Event,{
593 initialize: function (_data){
595 this.yukkuri = _data.myYukkuri;
596 this.action = _data.action;
597 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
598 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
599 this.yukkuri.setFaceImage(EFace.CRY1);
601 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
602 this.yukkuri.wait(sec, {
603 "onactionstart": this.onactionstart(this),
604 "onactiontick": this.onactiontick(this),
605 "onactionend": this.onactionend(this)
608 onactionend:function(self){
610 if(typeof e === "undefined")return;
611 self.action.setStatus(EAction.THINK);
616 var EatEvent = enchant.Class.create(Event,{
617 initialize: function (_data){
619 this.yukkuri = _data.myYukkuri;
620 this.food = _data.targetNode;
621 this.action = _data.action;
622 this.action.setStatus(EAction.EAT_WAIT);
625 var sec = BASE_FPS * 3;
626 if(this.yukkuri.eat(this.food)){
627 mangMsg.output(this.yukkuri, EMsg.EAT);
628 this.yukkuri.setFaceImage(EFace.EAT2);
631 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
632 this.yukkuri.setFaceImage(EFace.CRY2);
634 this.yukkuri.wait(sec, {
635 "onactionend": this.onactionend(this)
638 onactionend:function(self){
640 if(typeof e === "undefined")return;
641 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
642 self.action.setStatus(EAction.THINK);
643 self.yukkuri.setFaceImage(EFace.NORMAL);
645 self.action.setStatus(EAction.EAT_START);
652 * -When yukkuri find Food.
655 * targetNode: enchant.Node
659 var MoveToEatEvent = enchant.Class.create(Event,{
660 initialize: function (_data){
662 this.yukkuri = this.data.myYukkuri;
663 this.action = this.data.action;
665 var yukkuri = this.yukkuri;
666 var node = this.data.targetNode;
668 if(this.data.type == "food"){
669 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
670 yukkuri.vx = node.x - yukkuri.getX();
671 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
672 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
673 var frame = distance + distance/5 + 1;
674 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
677 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
678 "onactionstart": this.onactionstart(this),
679 "onactiontick": this.onactiontick(this),
680 "onactionend": this.onactionend(this)
684 onactionstart:function(self){
686 if(typeof e === "undefined")return;
687 mangMsg.output(EMsg.TARGETING_EAT);
688 // self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
691 onactiontick:function(self){
693 if(typeof e === "undefined")return;
696 onactionend:function(self){
698 if(typeof e === "undefined")return;
699 self.action.setStatus(EAction.EAT_START);
703 var MoveCommandEvent = enchant.Class.create(Event,{
704 initialize: function (_data){
706 this.yukkuri = this.data.myYukkuri;
707 this.action = this.data.action;
708 this.vx = this.data.vx;
709 this.vy = this.data.vy;
711 var yukkuri = this.yukkuri;
712 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
713 yukkuri.vx = node.x - yukkuri.getX();
714 yukkuri.vy = node.y - yukkuri.getY();
715 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
716 var frame = distance + 1;
717 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
718 "onactionstart": this.onactionstart(this),
719 "onactiontick": this.onactiontick(this),
720 "onactionend": this.onactionend(this)
723 onactionstart:function(self){
725 if(typeof e === "undefined")return;
728 onactiontick:function(self){
730 if(typeof e === "undefined")return;
733 onactionend:function(self){
735 if(typeof e === "undefined")return;
736 self.action.setStatus(EAction.THINK);
741 * Say hello contact to send communication .
743 var ComSayHelloSendEvent = enchant.Class.create(Event,{
744 initialize: function (_data){
746 this.yukkuri = _data.myYukkuri;
747 this.targetYukkuri = _data.targetNode;
748 this.action = _data.action;
749 this.action.setStatus(EAction.COMMUNICATE_WAIT);
751 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
753 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
754 this.targetYukkuri.tlPause();
755 this.yukkuri.tlPause();
756 this.yukkuri.syncDirection(this.targetYukkuri);
758 this.yukkuri.addAddress(this.targetYukkuri);
759 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
761 var sec = BASE_FPS * 2;
762 this.yukkuri.wait(sec, {
763 "onactiontick": this.onactiontick(this),
764 "onactionend": this.onactionend(this)
767 onactiontick:function(self){
769 if(typeof e === "undefined")return;
772 onactionend:function(self){
774 if(typeof e === "undefined")return;
775 new ComSayHelloRecvEvent({
777 "targetNode": self.yukkuri,
778 "action": self.targetYukkuri.action,
779 "myYukkuri": self.targetYukkuri
784 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
785 initialize: function (_data){
787 this.yukkuri = _data.myYukkuri;
788 this.targetYukkuri = _data.targetNode;
789 this.action = _data.action;
790 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
791 this.yukkuri.addAddress(this.targetYukkuri);
792 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
794 var sec = BASE_FPS * 2;
795 this.yukkuri.wait(sec, {
796 "onactiontick": this.onactiontick(this),
797 "onactionend": this.onactionend(this)
800 onactiontick:function(self){
802 if(typeof e === "undefined")return;
805 onactionend:function(self){
807 if(typeof e === "undefined")return;
808 self.action.setStatus(EAction.THINK);
810 self.yukkuri.action.setStatus(EAction.THINK);
811 self.yukkuri.animation();
812 self.targetYukkuri.action.setStatus(EAction.THINK);
813 self.targetYukkuri.animation();
817 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
818 initialize: function (_data){
820 this.yukkuri = this.data.myYukkuri;
821 this.action = this.data.action;
823 var yukkuri = this.yukkuri;
824 var node = this.data.targetNode;
826 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
827 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
828 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
829 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
830 var frame = distance + distance/5 + 1;
831 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
834 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
835 "onactionend": this.onactionend(this)
838 onactionend:function(self){
840 if(typeof e === "undefined")return;
841 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
848 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
849 initialize: function (_data){
851 this.yukkuri = _data.myYukkuri;
852 this.place = _data.targetNode;
853 this.action = _data.action;
854 this.action.setStatus(EAction.WAIT);
857 var sec = BASE_FPS * 3;
858 this.yukkuri.declarePlace(this.place);
859 this.place.setOwner(this.yukkuri);
860 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
862 this.yukkuri.setFaceImage(EFace.NORMAL);
863 this.yukkuri.wait(sec, {
864 "onactionend": this.onactionend(this)
867 onactionend:function(self){
869 if(typeof e === "undefined")return;
870 self.action.setStatus(EAction.THINK);
874 var ObjSprite = enchant.Class.create(enchant.Sprite,{
875 initialize: function (w, h){
876 enchant.Sprite.call(this, w, h);
880 removeAll: function(){
886 var Food = enchant.Class.create(ObjSprite,{
887 initialize: function (type, x, y){
888 this.classname = "Food";
889 ObjSprite.call(this,16,16);
890 this.image = game.assets[EResPath.OBJECT];
894 //一つにつきgiveの値分、hunguryを減少させられる
897 foodGroup.addChild(this);
898 this.addEventListener('enterframe', function(){
899 if(this.amount <= 0){
904 getAmount: function(){
911 var Place= enchant.Class.create(ObjSprite,{
912 initialize: function (type, x, y){
913 ObjSprite.call(this,128,128);
914 this.image = game.assets[EResPath.PLACE_TREE];
915 this.x = x - this.width / 2;
916 this.y = y - this.height / 2;
917 backgroundMap.addChild(this);
919 // this.addEventListener('enterframe', function(){
920 // if(this.age%10 === 0 && this.age !== 0){
921 // console.log("x/y " + this.x + "/" + this.y);
923 // if(game.input.left){
926 // if(game.input.right){
929 // if(game.input.up){
932 // if(game.input.down){
937 setOwner: function(yukkuri){
938 this.owner = yukkuri;
941 return this.owner !== null;
944 var Unun = enchant.Class.create(ObjSprite,{
945 initialize: function (x, y){
946 this.classname = "Unun";
947 ObjSprite.call(this,32,32);
948 this.image = game.assets[EResPath.YUKKURI_UNUN];
951 backgroundMap.addChild(this);
954 var Okazari = enchant.Class.create(enchant.Sprite,{
955 initialize: function(){
956 this.classname = "Okazari";
957 enchant.Sprite.call(this, 64, 64);
958 this.image = game.assets[EResPath.OKAZARI];
959 this.x = -CHARA_WIDTH / 2;
960 this.y = -12 - CHARA_HEIGHT / 2;
963 var Address = enchant.Class.create({
964 initialize: function(yukkuri){
966 this.yukkuri = yukkuri;
967 this.isGreeting = false;
968 this.greetingWaitFrame = 0;
970 "beginSayHello" : false,
975 set:function(key, value){
976 this.comMatrix[key] = value;
979 return this.comMatrix[key];
983 var Yukkuri = enchant.Class.create(ObjSprite,{
984 initialize: function(x, y){
985 ObjSprite.call(this, 64, 64);
986 this.classname = "Yukkuri";
987 this.addressBook = {};
988 this.imgGroup = new SpriteGroup();
989 this.imgBody = new SpriteGroup();
990 this.imgGroup.id = guid();
991 this.imgBody.id = guid();
992 this.x = -CHARA_WIDTH / 2;
993 this.y = -CHARA_HEIGHT / 2;
996 this.image = game.assets[EResPath.YUKKURI_BASE];
997 this.direction = EDirection.RIGHT;
998 this.addEventListener('enterframe', this.runEnterframe);
1000 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1001 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1002 this.walkAnimationStatus = EWalkAnimation.END;
1005 runEnterframe:function(){
1007 if(this.isDead())return;
1015 if(this.direction == EDirection.RIGHT){
1016 this.imgBody.scaleX = 1;
1018 else if(this.direction == EDirection.LEFT){
1019 this.imgBody.scaleX = -1;
1022 tweet:function(text){
1023 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1025 moveTo:function(x, y, time){
1026 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1028 moveBy:function(x, y, time, eventFunctions){
1032 return self.imgGroup.x + x;
1035 return self.imgGroup.y + y;
1038 easing: enchant.Easing.SIN_EASEINOUT
1040 //-Event register [onactionstart,onactiontick,onactionend]
1041 if(eventFunctions !== undefined){
1042 for(var key in eventFunctions){
1043 params[key] = eventFunctions[key];
1046 return this.imgGroup.tl.tween(params);
1048 wait:function(frame, eventFunctions){
1049 this.moveBy(0,1,frame,eventFunctions);
1054 animation: function(){
1055 if(this.walkAnimationStatus == EWalkAnimation.END){
1057 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
1058 "onactionstart": function(e){
1059 this.walkAnimationStatus = EWalkAnimation.START;
1062 .moveByEx(0, 5, 10, enchant.Easing.SWING,
1064 "onactionend": function(e){
1065 this.walkAnimationStatus = EWalkAnimation.END;
1070 this.imgBody.tl.loop();
1073 getWidth: function(){
1076 getHeight: function(){
1080 return this.imgGroup.x;
1083 return this.imgGroup.y;
1086 this.imgGroup.x += x;
1088 // this.shadow.x += x;
1089 // this._tweet.x += x;
1092 this.imgGroup.y += y;
1094 // this.shadow.y += y;
1095 // this._tweet.y += y;
1097 // changeFace: function(erespath){
1098 // this.face.image = game.assets[erespath];
1100 loadParamsXML: function(url){
1101 var http = new JKL.ParseXML( url );
1102 return http.parse();
1104 runYukkuri: function(){
1105 if(this.param.hungry > 70){
1106 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1107 this.param.yukkuri -= 1;
1110 else if(this.param.hungry < 10){
1111 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1114 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1115 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1117 runHungry: function(){
1118 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1119 if(this.param.hungry >= 100)this.param.hungry = 100;
1121 runUnun: function(){
1122 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1123 if(this.param.unun >= 100)this.param.unun = 100;
1125 runSleep: function(){
1126 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1127 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1128 if(this.param.sleep >= 100){
1129 this.param.sleep = 100;
1133 runAddress: function(){
1134 for(var key in this.addressBook){
1135 var address = this.addressBook[key];
1137 if(address.isGreeting){
1138 address.greetingWaitFrame++;
1139 if(address.greetingWaitFrame >= DAY){
1140 address.greetingWaitFrame = 0;
1141 address.isGreeting = false;
1146 changeFace: function(){
1147 if(this.param.yukkuri >= 80){
1148 this.setFaceImage(EFace.HAPPY1);
1150 else if(this.param.yukkuri >= 50){
1151 this.setFaceImage(EFace.NORMAL);
1153 else if(this.param.yukkuri >= 30){
1154 this.setFaceImage(EFace.TIRED);
1156 else if(this.param.yukkuri >= 10){
1157 this.setFaceImage(EFace.CRY1);
1159 else if(this.param.yukkuri >= 1){
1160 this.setFaceImage(EFace.CRY2);
1163 getRange: function(){
1164 return this.param.range;
1166 isSleep: function(){
1167 return this.param.sleep >= 100;
1170 return this.param.yukkuri <= 0;
1172 isManpuku: function(){
1173 return this.param.hungry <= 20;
1175 isKuhuku: function(){
1176 return this.param.hungry >= 40;
1178 getYukkuri: function(){
1179 return this.param.yukkuri;
1181 setYukkuri: function(yukkuri){
1182 this.param.yukkuri = yukkuri;
1183 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1185 getHungry: function(){
1186 return this.param.hungry;
1188 setHungry: function(hungry){
1189 this.param.hungry = hungry;
1190 if(this.param.hungry < 0)this.param.hungry = 0;
1192 getUnun: function(){
1193 return this.param.unun;
1195 setUnun: function(unun){
1196 this.param.unun = unun;
1197 if(this.param.unun < 0)this.param.unun = 0;
1201 if(food.amount > 0){
1203 this.setHungry(this.param.hungry - food.getGive());
1204 this.setUnun(this.getUnun() + food.getGive() / 4);
1205 this.setYukkuri(this.getYukkuri() + 5);
1208 this.setYukkuri(this.getYukkuri() - 5);
1212 declarePlace: function(place){
1215 isPlace: function(){
1216 return this.place !== null;
1220 if(this.direction == EDirection.RIGHT){
1221 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1223 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1227 setBodyImage: function(ebody){
1228 var path = this.bodyStatus[ebody];
1229 this.image = game.assets[path];
1232 // this.imgBody.tl.pause();
1233 // this.imgGroup.tl.pause();
1234 // this.imgBody.tl.clear();
1235 // this.imgGroup.tl.clear();
1236 this.imgBody.tl.unloop();
1237 this.imgGroup.tl.unloop();
1239 tlResume: function(){
1240 // this.imgBody.tl.resume();
1241 // this.imgGroup.tl.resume();
1244 syncDirection:function(senderYukkuri){
1245 if(this.getX() > senderYukkuri.getX()){
1246 this.direction = EDirection.LEFT;
1247 senderYukkuri.direction = EDirection.RIGHT;
1249 this.direction = EDirection.RIGHT;
1250 senderYukkuri.direction = EDirection.LEFT;
1253 isCommunication: function(yukkuri){
1254 if(this.addressBook[yukkuri.id] === undefined) return true;
1255 if(this.addressBook[yukkuri.id].isGreeting) return false;
1258 addAddress: function(yukkuri){
1259 this.addressBook[yukkuri.id] = new Address(yukkuri);
1261 getAddress: function(yukkuri){
1262 if(this.addressBook[yukkuri.id] === undefined)return null;
1263 return this.addressBook[yukkuri.id];
1265 destruct: function(){
1269 var Marisa = enchant.Class.create(Yukkuri,{
1270 initialize: function(x, y){
1271 Yukkuri.call(this,x,y);
1272 this.classname = "Marisa";
1275 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1276 var json = net.load("./data/marisa/params.json");
1277 this.param = json.root.param;
1278 this.shadow = new enchant.Sprite(64, 64);
1279 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1280 this.shadow.x = 0 + this.x;
1281 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1282 this.shadow.image._element.style.zIndex = 2;
1284 this._style.zIndex = 5;
1286 this.face = new enchant.Sprite(64, 64);
1287 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1288 this.face.x = -CHARA_WIDTH / 2;
1289 this.face.y = -CHARA_HEIGHT / 2;
1290 this.face._style.zIndex = 0;
1292 this.faceStatus ={};
1293 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1294 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1295 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1296 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1297 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1298 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1299 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1300 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1301 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1302 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1305 this.hear = new enchant.Sprite(64, 64);
1306 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1307 this.hear.x = -CHARA_WIDTH / 2;
1308 this.hear.y = -CHARA_HEIGHT / 2;
1309 this.hear._style.zIndex = 0;
1311 this.okazari = new Okazari();
1312 this.okazari.image._element.style.zIndex = 1;
1314 // this.imgGroup._style.zIndex = 1;
1316 this.imgGroup.addChild(this.shadow);
1317 this.imgBody.addChild(this);
1318 this.imgBody.addChild(this.face);
1319 this.imgBody.addChild(this.hear);
1320 this.imgBody.addChild(this.okazari);
1321 this.imgGroup.addChild(this.imgBody);
1322 backgroundMap.addChild(this.imgGroup);
1323 this._tweet = new TTweet(148, 64);
1324 this._tweet.image._element.style.zIndex = 20;
1326 this.imgGroup.addChild(this._tweet);
1327 this.imgGroup.x = x;
1328 this.imgGroup.y = y;
1330 this.action = new Action(this);
1334 setFaceImage: function(eface){
1335 var path = this.faceStatus[eface];
1336 this.face.image = game.assets[path];
1339 var Player = enchant.Class.create(Marisa,{
1340 initialize: function(x, y){
1341 // this.runEnterframe = function(){
1343 Marisa.call(this, x, y);
1344 this.classname = "Player";
1345 ctl.setPlayer(this);
1346 // this.removeEventListener('enterframe',this.runEnterframe);
1347 this.addEventListener('enterframe', function(){
1350 if(this.age%10 === 0 && this.age !== 0){
1351 // console.log("palyer:" + this.age);
1354 ///////////////////////////////////////////////
1355 //Action pattern debug
1356 if(game.input.left){
1357 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1359 this.direction = EDirection.LEFT;
1361 if(game.input.right){
1363 this.direction = EDirection.RIGHT;
1368 if(game.input.down){
1371 ///////////////////////////////////////////////
1373 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1374 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1376 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1378 //- Display the circle of search range.
1379 // fieldBg.image.clear();
1380 // fieldBg.image.context.beginPath();
1381 // fieldBg.image.context.fillStyle = '#ff0000';
1382 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1383 // fieldBg.image.context.fill();
1387 game.onload = function(){
1390 mangTouch = new MangTouch(ctl);
1391 mangMsg = new MangMsg(ctl);
1392 ctl.setDefined(def);
1393 backgroundMap.image = game.assets[EResPath.MAP0];
1394 backgroundMap.loadData(_mapData);
1395 backgroundMap.collisionData = _collisionData;
1397 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1398 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1399 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1400 fieldBg.image = fieldSurface;
1404 windowFront.image = windowSurface;
1407 windowFront.opacity = 0.5;
1409 windowSurface.context.fillStyle = '#000';
1410 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1413 menuSurface.context.fillStyle = '#000';
1414 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1415 menuBg.image = menuSurface;
1416 menuBg.x = EMenuPos.X;
1417 menuBg.y = EMenuPos.Y;
1418 backgroundMap.addChild(fieldBg);
1419 mangIcon = new MangIcon(ctl, menuBg);
1421 game.rootScene.addChild(backgroundMap);
1422 game.rootScene.addChild(windowFront);
1423 game.rootScene.addChild(menuBg);
1425 // var labelGroup = new LabelGroup();
1426 mangLabel = new MangLabel(ctl, menuBg);
1427 // var info = new Label("ゆっくり");
1428 // info.color = "#ffffff";
1429 // info.font = "14px 'Times New Roman'";
1431 // info.y = GAME_HEIGHT / 2;
1432 // labelGroup.addChild(info);
1433 // menuBg.addChild(labelGroup);
1436 // var food = new def.Food("apple", 200, 250);
1437 backgroundMap.addChild(foodGroup);
1438 // backgroundMap.addChild(placeGroup);
1439 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1440 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
1441 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
1444 game.rootScene.addEventListener('touchstart', function (e) {
1445 game.touched = true;
1446 var mang = mangTouch.get(ctl.getCurrentCommand());
1449 game.rootScene.addEventListener('touchmove', function (e) {
1450 var mang = mangTouch.get(ctl.getCurrentCommand());
1453 game.rootScene.addEventListener('touchend', function (e) {
1454 var mang = mangTouch.get(ctl.getCurrentCommand());
1456 game.touched = false;
1460 game.rootScene.addEventListener('enterframe', function(){
1462 mangLabel.draw(player);
1464 this.addEventListener('enterframe', function(){
1465 //The priority processing of display instead of z-index
1466 backgroundMap.childNodes.sort(
1468 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1471 else if(typeof a.id === "undefined"){
1474 else if(typeof b.id === "undefined"){
1479 if(a instanceof Place){
1480 ay += Math.round(a.height * 0.7);
1482 else if(b instanceof Place){
1483 by += Math.round(b.height * 0.7);
1486 if(ay < by)return -1;
1487 if(ay > by)return 1;