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 GRASS : './data/system/grass.png',
50 PLAYER_BADGE : './data/system/player_badge.png',
51 // PLACE_TREE : './data/system/rapture.png',
86 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
97 MOVE_TO_EAT_START: 10,
98 MOVE_TO_EAT_UNDERWAY: 11,
102 UNUN_SMELL_START : 15,
103 UNUN_SMELL_WAIT : 16,
106 COMMUNICATE_START : 19,
107 COMMUNICATE_WAIT: 20,
108 COMMUNICATE_RECV: 21,
109 MOVE_TO_PLACE_START_HOMELESS: 22,
110 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
111 DECLARE_PLACE_HOMELESS: 24,
112 MOVE_TO_HUNT_START: 25,
135 var EWalkAnimation = {
141 var ObjSprite = enchant.Class.create(enchant.Sprite,{
142 initialize: function (w, h){
143 enchant.Sprite.call(this, w, h);
148 // // new BoxLabel(this.ctl,100, e.x, e.y);
149 // var box = new Box(this.ctl, 200, 200);
151 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
154 getStatusForDisplay: function (){
163 removeAll: function(){
170 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
181 //-Event register [onactionstart,onactiontick,onactionend]
182 if(eventFunctions !== undefined){
183 for(var key in eventFunctions){
184 params[key] = eventFunctions[key];
187 return this.tween(params);
192 include("./lang/ja.js");
193 window.onload = function(){
194 var nodeSort = function (a, b){
195 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
198 else if(typeof a.id === "undefined"){
201 else if(typeof b.id === "undefined"){
206 if(a instanceof Box && b instanceof Box){
209 if(a instanceof Box){
212 if(b instanceof Box){
216 if(a instanceof Place){
217 ay += Math.round(a.height * 0.7);
219 if(b instanceof Place){
220 by += Math.round(b.height * 0.7);
223 if(ay < by)return -1;
224 else if(ay > by)return 1;
225 if(a.id < b.id)return -1;
226 else if(a.id > b.id)return 1;
232 var def = new Object();
233 var foodGroup = new Group();
234 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
235 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
236 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
237 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
238 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
242 for(var _v in EResPath){
243 _loadArr[i] = EResPath[_v];
246 game.preload(_loadArr);
247 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
248 var backgroundMap = new MapGroup(16, 16);
249 include("./class.js");
250 include("./ctrl.js");
253 ctl.setBackgroundMap(backgroundMap);
254 var Action = enchant.Class.create({
255 initialize: function (yukkuri){
256 this.status = EAction.THINK;
257 this.yukkuri = yukkuri;
258 this.isMoving = false;
259 this.targetNode = null;
261 getStatus: function(){
264 setStatus: function(eaction){
265 this.status = eaction;
268 if(this.yukkuri.isDead()){
269 this.status = EAction.DEAD;
271 // else if(this.yukkuri.isSleep()){
272 // this.status = EAction.SLEEP;
284 if(this.yukkuri.age%2 === 0){
285 if(this.yukkuri.isPlace()){
286 if(this.yukkuri.isSleep()){
287 this.setStatus(EAction.SLEEP_START);
289 else if(this.yukkuri.getUnun() >= 80){
290 this.setStatus(EAction.UNUN_START);
293 this.yukkuri.changeFace();
294 this.searchHavePlace();
298 if(this.yukkuri.isSleep()){
299 this.setStatus(EAction.SLEEP_START);
301 else if(this.yukkuri.getUnun() >= 80){
302 this.setStatus(EAction.UNUN_START);
305 // this.yukkuri.param.yukkuri -= 1;
306 this.yukkuri.changeFace();
313 case EAction.MOVE_TO_EAT_START:
314 this.move_to_eat_start();
316 case EAction.MOVE_TO_EAT_UNDERWAY:
322 case EAction.SLEEP_START:
325 case EAction.SLEEP_WAIT:
330 case EAction.EAT_START:
333 case EAction.EAT_WAIT:
335 case EAction.UNUN_START:
338 case EAction.UNUN_WAIT:
340 case EAction.MOVE_TO_COMMAND:
341 this.move_to_command();
343 case EAction.UNUN_SMELL_START:
344 this.unun_smell_start();
346 case EAction.COMMUNICATE_START:
347 this.communicate_start();
349 case EAction.COMMUNICATE_WAIT:
351 case EAction.COMMUNICATE_RECV:
353 case EAction.MOVE_TO_PLACE_START_HOMELESS:
354 this.move_to_place_start_homeless();
356 case EAction.DECLARE_PLACE_HOMELESS:
357 this.declare_place_homeless();
361 this.yukkuri.reverse();
364 move_to_eat_start : function(){
367 "targetNode": this.targetNode,
369 "myYukkuri": this.yukkuri
375 walk : function(retryCounter){
376 if(retryCounter > 15){
378 this.status = EAction.NONE;
379 console.log("retryCount over");
382 if(this.yukkuri.imgGroup.tl.queue.length === 0){
385 this.isMoving = false;
386 this.status = EAction.THINK;
390 var xpos = 150 + rand(40) - (retryCounter * 10);
391 var ypos = 150 + rand(40) - (retryCounter * 10);
394 this.yukkuri.vy = -ypos;
396 else if(rand(8) == 1){
397 this.yukkuri.vx = xpos;
398 this.yukkuri.vy = -ypos;
399 this.yukkuri.direction = EDirection.RIGHT;
401 else if(rand(8) == 2){
402 this.yukkuri.vx = xpos;
404 this.yukkuri.direction = EDirection.RIGHT;
406 else if(rand(8) == 3){
407 this.yukkuri.vx = xpos;
408 this.yukkuri.vy = ypos;
409 this.yukkuri.direction = EDirection.RIGHT;
411 else if(rand(8) == 4){
413 this.yukkuri.vy = ypos;
415 else if(rand(8) == 5){
416 this.yukkuri.vx = -xpos;
417 this.yukkuri.vy = ypos;
418 this.yukkuri.direction = EDirection.LEFT;
420 else if(rand(8) == 6){
421 this.yukkuri.vx = -xpos;
423 this.yukkuri.direction = EDirection.LEFT;
425 else if(rand(8) == 7){
426 this.yukkuri.vx = -xpos;
427 this.yukkuri.vy = -ypos;
428 this.yukkuri.direction = EDirection.LEFT;
430 if (this.yukkuri.vx || this.yukkuri.vy) {
431 var map = ctl.backgroundMap;
432 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
433 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
434 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
435 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
436 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
437 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
438 // console.log("X:" + this.yukkuri.moveX);
439 // console.log("Y:" + this.yukkuri.moveY);
440 this.isMoving = true;
441 this.yukkuri.reverse();
442 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
443 mangMsg.output(this.yukkuri,EMsg.WALK);
445 this.targetNode = null;
447 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
448 this.walk(retryCounter+1);
454 sleep_start: function(){
457 "myYukkuri": this.yukkuri
461 mangMsg.output(this.yukkuri, EMsg.DEAD);
462 this.yukkuri.tlPause();
463 this.yukkuri.setBodyImage(EBody.DEAD);
465 eat_start: function(){
468 "targetNode": this.targetNode,
470 "myYukkuri": this.yukkuri
474 unun_start: function(){
477 "myYukkuri": this.yukkuri
480 unun_smell_start: function(){
483 "myYukkuri": this.yukkuri
486 communicate_start:function(){
487 new ComSayHelloSendEvent({
489 "targetNode": this.targetNode,
491 "myYukkuri": this.yukkuri
494 move_to_place_start_homeless:function(){
495 new MoveToPlaceStartHomelessEvent({
496 "targetNode": this.targetNode,
498 "myYukkuri": this.yukkuri
501 declare_place_homeless:function(){
502 new DeclarePlaceHomelessEvent({
503 "targetNode": this.targetNode,
505 "myYukkuri": this.yukkuri
508 move_to_command: function(){
511 searchHavePlace: function(){
512 var nodes = ctl.getObjs();
516 for (var key in nodes) {
517 var node = nodes[key];
518 if(this.yukkuri.id === node.id)continue;
520 && node instanceof Unun
521 && !(this.targetNode instanceof Unun)
522 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
524 this.targetNode = node;
525 this.setStatus(EAction.UNUN_SMELL_START);
528 else if (node instanceof Food) {
529 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
531 //A yukkuri to go to the food area
532 this.targetNode = node;
533 this.setStatus(EAction.MOVE_TO_EAT_START);
537 //not hunbry or not food.
540 else if(node instanceof Yukkuri){
541 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
542 this.targetNode = node;
543 this.setStatus(EAction.COMMUNICATE_START);
547 else if(node instanceof Place){
548 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
549 this.targetNode = node;
550 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
555 this.status = EAction.WALK;
558 var nodes = ctl.getObjs();
562 for (var key in nodes) {
563 var node = nodes[key];
564 if(this.yukkuri.id === node.id)continue;
566 && node instanceof Unun
567 && !(this.targetNode instanceof Unun)
568 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
570 this.targetNode = node;
571 this.setStatus(EAction.UNUN_SMELL_START);
574 else if (node instanceof Food) {
575 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
577 //A yukkuri to go to the food area
578 this.targetNode = node;
579 this.setStatus(EAction.MOVE_TO_EAT_START);
583 //not hunbry or not food.
586 else if(node instanceof Yukkuri){
587 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
588 this.targetNode = node;
589 this.setStatus(EAction.COMMUNICATE_START);
593 else if(node instanceof Place){
594 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
595 this.targetNode = node;
596 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
601 this.status = EAction.WALK;
604 var Event = enchant.Class.create({
605 initialize: function (_data){
607 onactionstart:function(self){
609 if(typeof e === "undefined")return;
612 onactiontick:function(self){
614 if(typeof e === "undefined")return;
617 onactionend:function(self){
619 if(typeof e === "undefined")return;
623 var WalkEvent = enchant.Class.create(Event,{
624 initialize: function (_data){
626 this.yukkuri = _data.myYukkuri;
627 this.action = _data.action;
629 mangMsg.output(this.yukkuri, EMsg.SLEEP);
630 this.action.setStatus(EAction.SLEEP_WAIT);
631 this.yukkuri.setFaceImage(EFace.SLEEP);
632 this.yukkuri.tlPause();
634 this.yukkuri.addEventListener('enterframe', function() {
635 var yukkuri = self.yukkuri;
643 var SleepEvent = enchant.Class.create(Event,{
644 initialize: function (_data){
646 this.yukkuri = _data.myYukkuri;
647 this.action = _data.action;
649 mangMsg.output(this.yukkuri, EMsg.SLEEP);
650 this.action.setStatus(EAction.SLEEP_WAIT);
651 this.yukkuri.setFaceImage(EFace.SLEEP);
652 this.yukkuri.tlPause();
655 this.yukkuri.addEventListener('enterframe', function() {
656 var yukkuri = self.yukkuri;
657 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
658 if(yukkuri.param.sleep <= 0){
659 yukkuri.param.sleep = 0;
660 this.removeEventListener("enterframe",arguments.callee);
661 mangMsg.output(self.yukkuri, EMsg.GET_UP);
662 yukkuri.setFaceImage(EFace.NORMAL);
664 // self.action.setStatus(EAction.WAIT);
665 self.action.setStatus(EAction.THINK);
671 var UnunEvent = enchant.Class.create(Event,{
672 initialize: function (_data){
674 this.yukkuri = _data.myYukkuri;
675 this.action = _data.action;
676 this.action.setStatus(EAction.UNUN_WAIT);
677 mangMsg.output(this.yukkuri, EMsg.UNUN);
678 this.yukkuri.setFaceImage(EFace.HAPPY2);
681 this.yukkuri.wait(sec, {
682 "onactionend": this.onactionend(this)
685 onactionend:function(self){
687 if(typeof e === "undefined")return;
689 self.action.setStatus(EAction.WAIT);
690 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
692 "waitframe": FPS * 1.5,
693 "action": self.action,
694 "myYukkuri": self.yukkuri
699 var WaitEvent = enchant.Class.create(Event,{
700 initialize: function (_data){
702 this.yukkuri = _data.myYukkuri;
703 this.action = _data.action;
704 this.waitframe = _data.waitframe;
705 this.yukkuri.wait(this.waitframe, {
706 "onactionstart": this.onactionstart(this),
707 "onactiontick": this.onactiontick(this),
708 "onactionend": this.onactionend(this)
711 onactionend:function(self){
713 if(typeof e === "undefined")return;
714 self.action.setStatus(EAction.THINK);
718 var UnunSmellEvent = enchant.Class.create(Event,{
719 initialize: function (_data){
721 this.yukkuri = _data.myYukkuri;
722 this.action = _data.action;
723 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
724 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
725 this.yukkuri.setFaceImage(EFace.CRY1);
727 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
728 this.yukkuri.wait(sec, {
729 "onactionend": this.onactionend(this)
732 onactionend:function(self){
734 if(typeof e === "undefined")return;
735 self.action.setStatus(EAction.THINK);
740 var EatEvent = enchant.Class.create(Event,{
741 initialize: function (_data){
743 this.yukkuri = _data.myYukkuri;
744 this.food = _data.targetNode;
745 this.action = _data.action;
746 this.action.setStatus(EAction.EAT_WAIT);
749 var sec = BASE_FPS * 3;
750 if(this.yukkuri.eat(this.food)){
751 mangMsg.output(this.yukkuri, EMsg.EAT);
752 this.yukkuri.setFaceImage(EFace.EAT2);
755 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
756 this.yukkuri.setFaceImage(EFace.CRY2);
758 this.yukkuri.wait(sec, {
759 "onactionend": this.onactionend(this)
762 onactionend:function(self){
764 if(typeof e === "undefined")return;
765 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
766 self.action.setStatus(EAction.THINK);
767 self.yukkuri.setFaceImage(EFace.NORMAL);
769 self.action.setStatus(EAction.EAT_START);
776 * -When yukkuri find Food.
779 * targetNode: enchant.Node
783 var MoveToEatEvent = enchant.Class.create(Event,{
784 initialize: function (_data){
786 this.yukkuri = this.data.myYukkuri;
787 this.action = this.data.action;
789 var yukkuri = this.yukkuri;
790 var node = this.data.targetNode;
792 if(this.data.type == "food"){
793 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
794 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
795 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
796 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
797 var frame = distance + distance/5 + 1;
798 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
801 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
802 "onactionstart": this.onactionstart(this),
803 "onactiontick": this.onactiontick(this),
804 "onactionend": this.onactionend(this)
808 onactionstart:function(self){
810 if(typeof e === "undefined")return;
811 mangMsg.output(EMsg.TARGETING_EAT);
814 onactiontick:function(self){
816 if(typeof e === "undefined")return;
819 onactionend:function(self){
821 if(typeof e === "undefined")return;
822 self.action.setStatus(EAction.EAT_START);
826 var MoveCommandEvent = enchant.Class.create(Event,{
827 initialize: function (_data){
829 this.yukkuri = this.data.myYukkuri;
830 this.action = this.data.action;
831 this.vx = this.data.vx;
832 this.vy = this.data.vy;
834 var yukkuri = this.yukkuri;
835 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
836 yukkuri.vx = node.x - yukkuri.getX();
837 yukkuri.vy = node.y - yukkuri.getY();
838 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
839 var frame = distance + 1;
840 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
841 "onactionstart": this.onactionstart(this),
842 "onactiontick": this.onactiontick(this),
843 "onactionend": this.onactionend(this)
846 onactionstart:function(self){
848 if(typeof e === "undefined")return;
851 onactiontick:function(self){
853 if(typeof e === "undefined")return;
856 onactionend:function(self){
858 if(typeof e === "undefined")return;
859 self.action.setStatus(EAction.THINK);
864 * Say hello contact to send communication .
866 var ComSayHelloSendEvent = enchant.Class.create(Event,{
867 initialize: function (_data){
869 this.yukkuri = _data.myYukkuri;
870 this.targetYukkuri = _data.targetNode;
871 this.action = _data.action;
872 this.action.setStatus(EAction.COMMUNICATE_WAIT);
874 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
876 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
877 this.targetYukkuri.tlPause();
878 this.yukkuri.tlPause();
879 this.yukkuri.syncDirection(this.targetYukkuri);
881 this.yukkuri.addAddress(this.targetYukkuri);
882 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
884 var sec = BASE_FPS * 2;
885 this.yukkuri.wait(sec, {
886 "onactiontick": this.onactiontick(this),
887 "onactionend": this.onactionend(this)
890 onactiontick:function(self){
892 if(typeof e === "undefined")return;
895 onactionend:function(self){
897 if(typeof e === "undefined")return;
898 new ComSayHelloRecvEvent({
900 "targetNode": self.yukkuri,
901 "action": self.targetYukkuri.action,
902 "myYukkuri": self.targetYukkuri
907 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
908 initialize: function (_data){
910 this.yukkuri = _data.myYukkuri;
911 this.targetYukkuri = _data.targetNode;
912 this.action = _data.action;
913 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
914 this.yukkuri.addAddress(this.targetYukkuri);
915 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
917 var sec = BASE_FPS * 2;
918 this.yukkuri.wait(sec, {
919 "onactiontick": this.onactiontick(this),
920 "onactionend": this.onactionend(this)
923 onactiontick:function(self){
925 if(typeof e === "undefined")return;
928 onactionend:function(self){
930 if(typeof e === "undefined")return;
931 self.action.setStatus(EAction.THINK);
933 self.yukkuri.action.setStatus(EAction.THINK);
934 self.yukkuri.animation();
935 self.targetYukkuri.action.setStatus(EAction.THINK);
936 self.targetYukkuri.animation();
940 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
941 initialize: function (_data){
943 this.yukkuri = this.data.myYukkuri;
944 this.action = this.data.action;
946 var yukkuri = this.yukkuri;
947 var node = this.data.targetNode;
949 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
950 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
951 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
952 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
953 var frame = distance + distance/5 + 1;
954 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
957 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
958 "onactionend": this.onactionend(this)
961 onactionend:function(self){
963 if(typeof e === "undefined")return;
964 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
971 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
972 initialize: function (_data){
974 this.yukkuri = _data.myYukkuri;
975 this.place = _data.targetNode;
976 this.action = _data.action;
977 this.action.setStatus(EAction.WAIT);
980 var sec = BASE_FPS * 3;
981 this.yukkuri.declarePlace(this.place);
982 this.place.setOwner(this.yukkuri);
983 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
985 this.yukkuri.setFaceImage(EFace.NORMAL);
986 this.yukkuri.wait(sec, {
987 "onactionend": this.onactionend(this)
990 onactionend:function(self){
992 if(typeof e === "undefined")return;
993 self.action.setStatus(EAction.THINK);
998 var Food = enchant.Class.create(ObjSprite,{
999 initialize: function (type, x, y){
1000 this.classname = "Food";
1001 //一つにつきgiveの値分、hunguryを減少させられる
1002 if(type == "apple"){
1003 ObjSprite.call(this,16,16);
1004 this.image = game.assets[EResPath.OBJECT];
1008 }else if(type == "grass"){
1009 ObjSprite.call(this,64,64);
1010 this.image = game.assets[EResPath.GRASS];
1017 foodGroup.addChild(this);
1018 this.addEventListener('enterframe', function(){
1019 if(this.amount <= 0){
1024 getAmount: function(){
1027 getGive: function(){
1031 var Place = enchant.Class.create(ObjSprite,{
1032 initialize: function (type, x, y){
1033 ObjSprite.call(this,128,128);
1034 this.image = game.assets[EResPath.PLACE_TREE];
1035 this.x = x - this.width / 2;
1036 this.y = y - this.height / 2;
1037 backgroundMap.addChild(this);
1039 this.foodsGraet = 0;
1040 this.foodsNormal = 0;
1042 // this.addEventListener('enterframe', function(){
1043 // if(this.age%10 === 0 && this.age !== 0){
1044 // console.log("x/y " + this.x + "/" + this.y);
1046 // if(game.input.left){
1049 // if(game.input.right){
1052 // if(game.input.up){
1055 // if(game.input.down){
1060 getStatusForDisplay: function(){
1063 if(this.owner == null)ownerId = "なし";
1064 else ownerId = this.owner.id;
1065 ret += "プレイスID " + this.id + "\n";
1066 ret += "オーナーID " + ownerId + "\n";
1067 ret += "食料うめぇ " + this.foodsGraet + "\n";
1068 ret += "食料それなりー " + this.foodsNormal + "\n";
1069 ret += "食料にがにが " + this.foodsBad + "\n";
1072 setOwner: function(yukkuri){
1073 this.owner = yukkuri;
1075 isOwner: function(){
1076 return this.owner !== null;
1079 var Unun = enchant.Class.create(ObjSprite,{
1080 initialize: function (x, y){
1081 this.classname = "Unun";
1082 ObjSprite.call(this,32,32);
1083 this.image = game.assets[EResPath.YUKKURI_UNUN];
1086 backgroundMap.addChild(this);
1087 this.lifetime = 60 * 24 * 3;
1088 this.addEventListener('enterframe', this.runEnterframe(this));
1089 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1092 runEnterframe:function(self){
1094 if(typeof e === "undefined")return;
1095 if(this.age%BASE_FPS === 0 && this.age !== 0){
1097 if(self.lifetime <= 0){
1098 this.parentNode.removeChild(this);
1099 ctl.backgroundMap.removeChild(this);
1100 ctl.removeObj(this);
1107 // runEnterframe: function(){
1108 // console.log("enterframe:" + this.id);
1111 var Okazari = enchant.Class.create(enchant.Sprite,{
1112 initialize: function(){
1113 this.classname = "Okazari";
1114 enchant.Sprite.call(this, 64, 64);
1115 this.image = game.assets[EResPath.OKAZARI];
1116 this.x = -CHARA_WIDTH / 2;
1117 this.y = -12 - CHARA_HEIGHT / 2;
1120 var Address = enchant.Class.create({
1121 initialize: function(yukkuri){
1122 this.friendlyLv = 1;
1123 this.yukkuri = yukkuri;
1124 this.isGreeting = false;
1125 this.greetingWaitFrame = 0;
1127 "beginSayHello" : false,
1132 set:function(key, value){
1133 this.comMatrix[key] = value;
1136 return this.comMatrix[key];
1140 var Yukkuri = enchant.Class.create(ObjSprite,{
1141 initialize: function(x, y){
1142 ObjSprite.call(this, 64, 64);
1143 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1144 this.classname = "Yukkuri";
1145 this.addressBook = {};
1146 this.imgGroup = new SpriteGroup();
1147 this.imgBody = new SpriteGroup();
1148 this.imgGroup.id = guid();
1149 this.imgBody.id = guid();
1150 this.x = -CHARA_WIDTH / 2;
1151 this.y = -CHARA_HEIGHT / 2;
1154 this.image = game.assets[EResPath.YUKKURI_BASE];
1155 this.direction = EDirection.RIGHT;
1156 this.addEventListener('enterframe', this.runEnterframe);
1157 this.bodyStatus ={};
1158 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1159 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1160 this.walkAnimationStatus = EWalkAnimation.END;
1163 runEnterframe:function(){
1164 // this.imgGroup.x = 0;
1168 if(this.isDead())return;
1179 if(this.direction == EDirection.RIGHT){
1180 this.imgBody.scaleX = 1;
1182 else if(this.direction == EDirection.LEFT){
1183 this.imgBody.scaleX = -1;
1186 tweet:function(text){
1187 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1189 moveTo:function(x, y, time){
1190 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1192 moveBy:function(x, y, time, eventFunctions){
1196 return self.imgGroup.x + x;
1199 return self.imgGroup.y + y;
1202 easing: enchant.Easing.SIN_EASEINOUT
1204 //-Event register [onactionstart,onactiontick,onactionend]
1205 if(eventFunctions !== undefined){
1206 for(var key in eventFunctions){
1207 params[key] = eventFunctions[key];
1210 return this.imgGroup.tl.tween(params);
1212 wait:function(frame, eventFunctions){
1213 this.moveBy(0,1,frame,eventFunctions);
1218 animation: function(){
1219 if(this.walkAnimationStatus == EWalkAnimation.END){
1221 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
1222 "onactionstart": function(e){
1223 this.walkAnimationStatus = EWalkAnimation.START;
1226 .moveByEx(0, 5, 10, enchant.Easing.SWING,
1228 "onactionend": function(e){
1229 this.walkAnimationStatus = EWalkAnimation.END;
1234 this.imgBody.tl.loop();
1237 getWidth: function(){
1240 getHeight: function(){
1244 return this.imgGroup.x;
1247 return this.imgGroup.y;
1250 this.imgGroup.x += x;
1252 // this.shadow.x += x;
1253 // this._tweet.x += x;
1256 this.imgGroup.y += y;
1258 // this.shadow.y += y;
1259 // this._tweet.y += y;
1261 // changeFace: function(erespath){
1262 // this.face.image = game.assets[erespath];
1264 loadParamsXML: function(url){
1265 var http = new JKL.ParseXML( url );
1266 return http.parse();
1268 runYukkuri: function(){
1269 if(this.param.hungry > 70){
1270 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1271 this.param.yukkuri -= 1;
1274 else if(this.param.hungry < 10){
1275 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1278 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1279 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1281 runHungry: function(){
1282 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1283 if(this.param.hungry >= 100)this.param.hungry = 100;
1285 runUnun: function(){
1286 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1287 if(this.param.unun >= 100)this.param.unun = 100;
1289 runSleep: function(){
1290 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1291 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1292 if(this.param.sleep >= 100){
1293 this.param.sleep = 100;
1297 runAddress: function(){
1298 for(var key in this.addressBook){
1299 var address = this.addressBook[key];
1301 if(address.isGreeting){
1302 address.greetingWaitFrame++;
1303 if(address.greetingWaitFrame >= DAY){
1304 address.greetingWaitFrame = 0;
1305 address.isGreeting = false;
1310 changeFace: function(){
1311 if(this.param.yukkuri >= 80){
1312 this.setFaceImage(EFace.HAPPY1);
1314 else if(this.param.yukkuri >= 50){
1315 this.setFaceImage(EFace.NORMAL);
1317 else if(this.param.yukkuri >= 30){
1318 this.setFaceImage(EFace.TIRED);
1320 else if(this.param.yukkuri >= 10){
1321 this.setFaceImage(EFace.CRY1);
1323 else if(this.param.yukkuri >= 1){
1324 this.setFaceImage(EFace.CRY2);
1327 getRange: function(){
1328 return this.param.range;
1330 isSleep: function(){
1331 return this.param.sleep >= 100;
1334 return this.param.yukkuri <= 0;
1336 isManpuku: function(){
1337 return this.param.hungry <= 20;
1339 isKuhuku: function(){
1340 return this.param.hungry >= 40;
1342 getYukkuri: function(){
1343 return this.param.yukkuri;
1345 setYukkuri: function(yukkuri){
1346 this.param.yukkuri = yukkuri;
1347 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1349 getHungry: function(){
1350 return this.param.hungry;
1352 setHungry: function(hungry){
1353 this.param.hungry = hungry;
1354 if(this.param.hungry < 0)this.param.hungry = 0;
1356 getUnun: function(){
1357 return this.param.unun;
1359 setUnun: function(unun){
1360 this.param.unun = unun;
1361 if(this.param.unun < 0)this.param.unun = 0;
1365 if(food.amount > 0){
1367 this.setHungry(this.param.hungry - food.getGive());
1368 this.setUnun(this.getUnun() + food.getGive() / 4);
1369 this.setYukkuri(this.getYukkuri() + 5);
1372 this.setYukkuri(this.getYukkuri() - 5);
1376 declarePlace: function(place){
1379 isPlace: function(){
1380 return this.place !== null;
1384 if(this.direction == EDirection.RIGHT){
1385 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1387 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1391 setBodyImage: function(ebody){
1392 var path = this.bodyStatus[ebody];
1393 this.image = game.assets[path];
1396 // this.imgBody.tl.pause();
1397 // this.imgGroup.tl.pause();
1398 this.imgBody.tl.unloop();
1399 this.imgGroup.tl.unloop();
1403 tlResume: function(){
1404 // this.imgBody.tl.resume();
1405 // this.imgGroup.tl.resume();
1408 syncDirection:function(senderYukkuri){
1409 if(this.getX() > senderYukkuri.getX()){
1410 this.direction = EDirection.LEFT;
1411 senderYukkuri.direction = EDirection.RIGHT;
1413 this.direction = EDirection.RIGHT;
1414 senderYukkuri.direction = EDirection.LEFT;
1417 isCommunication: function(yukkuri){
1418 if(this.addressBook[yukkuri.id] === undefined) return true;
1419 if(this.addressBook[yukkuri.id].isGreeting) return false;
1422 addAddress: function(yukkuri){
1423 this.addressBook[yukkuri.id] = new Address(yukkuri);
1425 getAddress: function(yukkuri){
1426 if(this.addressBook[yukkuri.id] === undefined)return null;
1427 return this.addressBook[yukkuri.id];
1429 getStatusForDisplay: function (){
1431 var placeId = (this.place==null)?"無し" : this.place.id;
1432 ret += "ID " + this.id + "\n";
1433 ret += "プレイス " + placeId + "\n";
1434 ret += "うんうん " + this.getUnun() + "\n";
1437 destruct: function(){
1441 var Marisa = enchant.Class.create(Yukkuri,{
1442 initialize: function(x, y){
1443 Yukkuri.call(this,x,y);
1444 this.classname = "Marisa";
1446 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1447 var json = net.load("./data/marisa/params.json");
1448 this.param = json.root.param;
1449 this.shadow = new enchant.Sprite(64, 64);
1450 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1451 this.shadow.x = 0 + this.x;
1452 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1453 this.shadow.image._element.style.zIndex = 2;
1455 this._style.zIndex = 5;
1457 this.face = new enchant.Sprite(64, 64);
1458 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1459 this.face.x = -CHARA_WIDTH / 2;
1460 this.face.y = -CHARA_HEIGHT / 2;
1461 this.face._style.zIndex = 0;
1463 this.faceStatus ={};
1464 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1465 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1466 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1467 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1468 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1469 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1470 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1471 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1472 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1473 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1476 this.hear = new enchant.Sprite(64, 64);
1477 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1478 this.hear.x = -CHARA_WIDTH / 2;
1479 this.hear.y = -CHARA_HEIGHT / 2;
1480 this.hear._style.zIndex = 0;
1482 this.okazari = new Okazari();
1483 this.okazari.image._element.style.zIndex = 1;
1485 // this.imgGroup._style.zIndex = 1;
1487 this.imgGroup.addChild(this.shadow);
1488 this.imgBody.addChild(this);
1489 this.imgBody.addChild(this.face);
1490 this.imgBody.addChild(this.hear);
1491 this.imgBody.addChild(this.okazari);
1492 if(this instanceof Player){
1493 this.budge = new enchant.Sprite(16, 16);
1494 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
1495 this.imgBody.addChild(this.budge);
1496 this.budge.x -= this.width/2;
1497 this.budge.y -= this.height/2;
1499 this.imgGroup.addChild(this.imgBody);
1500 backgroundMap.addChild(this.imgGroup);
1501 this._tweet = new TTweet(148, 64);
1503 this.imgGroup.addChild(this._tweet);
1504 this.imgGroup.x = x;
1505 this.imgGroup.y = y;
1507 this.action = new Action(this);
1510 setFaceImage: function(eface){
1511 var path = this.faceStatus[eface];
1512 this.face.image = game.assets[path];
1515 var Player = enchant.Class.create(Marisa,{
1516 initialize: function(x, y){
1517 // this.runEnterframe = function(){
1519 Marisa.call(this, x, y);
1520 this.classname = "Player";
1521 ctl.setPlayer(this);
1522 // this.removeEventListener('enterframe',this.runEnterframe);
1523 this.addEventListener('enterframe', function(){
1526 if(this.age%10 === 0 && this.age !== 0){
1527 // console.log("palyer:" + this.age);
1530 ///////////////////////////////////////////////
1531 //Action pattern debug
1532 if(game.input.left){
1533 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1535 this.direction = EDirection.LEFT;
1537 if(game.input.right){
1539 this.direction = EDirection.RIGHT;
1544 if(game.input.down){
1547 ///////////////////////////////////////////////
1549 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1550 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1552 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1554 //- Display the circle of search range.
1555 // fieldBg.image.clear();
1556 // fieldBg.image.context.beginPath();
1557 // fieldBg.image.context.fillStyle = '#ff0000';
1558 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1559 // fieldBg.image.context.fill();
1563 game.onload = function(){
1566 def.ObjSprite = ObjSprite;
1567 def.Yukkuri = Yukkuri;
1568 def.nodeSort = nodeSort;
1569 mangTouch = new MangTouch(ctl);
1570 mangMsg = new MangMsg(ctl);
1571 ctl.setDefined(def);
1572 backgroundMap.image = game.assets[EResPath.MAP0];
1573 backgroundMap.loadData(_mapData);
1574 backgroundMap.collisionData = _collisionData;
1576 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1577 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1578 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1579 fieldBg.image = fieldSurface;
1583 windowFront.image = windowSurface;
1586 windowFront.opacity = 0.5;
1588 windowSurface.context.fillStyle = '#000';
1589 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1592 menuSurface.context.fillStyle = '#000';
1593 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1594 menuBg.image = menuSurface;
1595 menuBg.x = EMenuPos.X;
1596 menuBg.y = EMenuPos.Y;
1597 backgroundMap.addChild(fieldBg);
1598 mangIcon = new MangIcon(ctl, menuBg);
1600 game.rootScene.addChild(backgroundMap);
1601 game.rootScene.addChild(windowFront);
1602 game.rootScene.addChild(menuBg);
1604 // var labelGroup = new LabelGroup();
1605 mangLabel = new MangLabel(ctl, menuBg);
1606 // var info = new Label("ゆっくり");
1607 // info.color = "#ffffff";
1608 // info.font = "14px 'Times New Roman'";
1610 // info.y = GAME_HEIGHT / 2;
1611 // labelGroup.addChild(info);
1612 // menuBg.addChild(labelGroup);
1615 // var food = new def.Food("apple", 200, 250);
1616 backgroundMap.addChild(foodGroup);
1617 // backgroundMap.addChild(placeGroup);
1618 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1619 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
1620 new Marisa(PALYER_INIT_X + 800, PALYER_INIT_Y + 800);
1622 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
1625 game.rootScene.addEventListener('touchstart', function (e) {
1626 game.touched = true;
1627 var mang = mangTouch.get(ctl.getCurrentCommand());
1630 game.rootScene.addEventListener('touchmove', function (e) {
1631 var mang = mangTouch.get(ctl.getCurrentCommand());
1634 game.rootScene.addEventListener('touchend', function (e) {
1635 var mang = mangTouch.get(ctl.getCurrentCommand());
1637 game.touched = false;
1641 game.rootScene.addEventListener('enterframe', function(){
1643 mangLabel.draw(player);
1645 this.addEventListener('enterframe', function(){
1646 //The priority processing of display instead of z-index
1647 backgroundMap.childNodes.sort(nodeSort);