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 = {
139 var ObjSprite = enchant.Class.create(enchant.Sprite,{
140 initialize: function (w, h){
141 enchant.Sprite.call(this, w, h);
146 // // new BoxLabel(this.ctl,100, e.x, e.y);
147 // var box = new Box(this.ctl, 200, 200);
149 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
152 getStatusForDisplay: function (){
161 removeAll: function(){
168 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
179 //-Event register [onactionstart,onactiontick,onactionend]
180 if(eventFunctions !== undefined){
181 for(var key in eventFunctions){
182 params[key] = eventFunctions[key];
185 return this.tween(params);
190 include("./lang/ja.js");
191 window.onload = function(){
192 var nodeSort = function (a, b){
193 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
196 else if(typeof a.id === "undefined"){
199 else if(typeof b.id === "undefined"){
204 if(a instanceof Box && b instanceof Box){
207 if(a instanceof Box){
210 if(b instanceof Box){
214 if(a instanceof Place){
215 ay += Math.round(a.height * 0.7);
217 if(b instanceof Place){
218 by += Math.round(b.height * 0.7);
221 if(ay < by)return -1;
222 else if(ay > by)return 1;
223 if(a.id < b.id)return -1;
224 else if(a.id > b.id)return 1;
230 var def = new Object();
231 var foodGroup = new Group();
232 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
233 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
234 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
235 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
236 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
240 for(var _v in EResPath){
241 _loadArr[i] = EResPath[_v];
244 game.preload(_loadArr);
245 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
246 var backgroundMap = new MapGroup(16, 16);
247 include("./class.js");
248 include("./ctrl.js");
251 ctl.setBackgroundMap(backgroundMap);
252 var Action = enchant.Class.create({
253 initialize: function (yukkuri){
254 this.status = EAction.THINK;
255 this.yukkuri = yukkuri;
256 this.isMoving = false;
257 this.targetNode = null;
259 getStatus: function(){
262 setStatus: function(eaction){
263 this.status = eaction;
266 if(this.yukkuri.isDead()){
267 this.status = EAction.DEAD;
269 // else if(this.yukkuri.isSleep()){
270 // this.status = EAction.SLEEP;
282 if(this.yukkuri.age%2 === 0){
283 // if(this.yukkuri.isPlace()){
287 if(this.yukkuri.isSleep()){
288 this.setStatus(EAction.SLEEP_START);
290 else if(this.yukkuri.getUnun() >= 80){
291 this.setStatus(EAction.UNUN_START);
294 // this.yukkuri.param.yukkuri -= 1;
295 this.yukkuri.changeFace();
302 case EAction.MOVE_TO_EAT_START:
303 this.move_to_eat_start();
305 case EAction.MOVE_TO_EAT_UNDERWAY:
311 case EAction.SLEEP_START:
314 case EAction.SLEEP_WAIT:
319 case EAction.EAT_START:
322 case EAction.EAT_WAIT:
324 case EAction.UNUN_START:
327 case EAction.UNUN_WAIT:
329 case EAction.MOVE_TO_COMMAND:
330 this.move_to_command();
332 case EAction.UNUN_SMELL_START:
333 this.unun_smell_start();
335 case EAction.COMMUNICATE_START:
336 this.communicate_start();
338 case EAction.COMMUNICATE_WAIT:
340 case EAction.COMMUNICATE_RECV:
342 case EAction.MOVE_TO_PLACE_START_HOMELESS:
343 this.move_to_place_start_homeless();
345 case EAction.DECLARE_PLACE_HOMELESS:
346 this.declare_place_homeless();
350 this.yukkuri.reverse();
353 move_to_eat_start : function(){
356 "targetNode": this.targetNode,
358 "myYukkuri": this.yukkuri
364 walk : function(retryCounter){
365 if(retryCounter > 15){
367 this.status = EAction.NONE;
368 console.log("retryCount over");
371 if(this.yukkuri.imgGroup.tl.queue.length === 0){
374 this.isMoving = false;
375 this.status = EAction.THINK;
379 var xpos = 150 + rand(40) - (retryCounter * 10);
380 var ypos = 150 + rand(40) - (retryCounter * 10);
383 this.yukkuri.vy = -ypos;
385 else if(rand(8) == 1){
386 this.yukkuri.vx = xpos;
387 this.yukkuri.vy = -ypos;
388 this.yukkuri.direction = EDirection.RIGHT;
390 else if(rand(8) == 2){
391 this.yukkuri.vx = xpos;
393 this.yukkuri.direction = EDirection.RIGHT;
395 else if(rand(8) == 3){
396 this.yukkuri.vx = xpos;
397 this.yukkuri.vy = ypos;
398 this.yukkuri.direction = EDirection.RIGHT;
400 else if(rand(8) == 4){
402 this.yukkuri.vy = ypos;
404 else if(rand(8) == 5){
405 this.yukkuri.vx = -xpos;
406 this.yukkuri.vy = ypos;
407 this.yukkuri.direction = EDirection.LEFT;
409 else if(rand(8) == 6){
410 this.yukkuri.vx = -xpos;
412 this.yukkuri.direction = EDirection.LEFT;
414 else if(rand(8) == 7){
415 this.yukkuri.vx = -xpos;
416 this.yukkuri.vy = -ypos;
417 this.yukkuri.direction = EDirection.LEFT;
419 if (this.yukkuri.vx || this.yukkuri.vy) {
420 var map = ctl.backgroundMap;
421 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
422 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
423 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
424 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
425 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
426 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
427 // console.log("X:" + this.yukkuri.moveX);
428 // console.log("Y:" + this.yukkuri.moveY);
429 this.isMoving = true;
430 this.yukkuri.reverse();
431 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
432 mangMsg.output(this.yukkuri,EMsg.WALK);
434 this.targetNode = null;
436 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
437 this.walk(retryCounter+1);
443 sleep_start: function(){
446 "myYukkuri": this.yukkuri
451 mangMsg.output(this.yukkuri, EMsg.DEAD);
452 this.yukkuri.tlPause();
453 this.yukkuri.setBodyImage(EBody.DEAD);
455 eat_start: function(){
458 "targetNode": this.targetNode,
460 "myYukkuri": this.yukkuri
464 unun_start: function(){
467 "myYukkuri": this.yukkuri
470 unun_smell_start: function(){
473 "myYukkuri": this.yukkuri
476 communicate_start:function(){
477 new ComSayHelloSendEvent({
479 "targetNode": this.targetNode,
481 "myYukkuri": this.yukkuri
484 move_to_place_start_homeless:function(){
485 new MoveToPlaceStartHomelessEvent({
486 "targetNode": this.targetNode,
488 "myYukkuri": this.yukkuri
491 declare_place_homeless:function(){
492 new DeclarePlaceHomelessEvent({
493 "targetNode": this.targetNode,
495 "myYukkuri": this.yukkuri
498 move_to_command: function(){
502 var nodes = ctl.getObjs();
506 for (var key in nodes) {
507 var node = nodes[key];
508 if(this.yukkuri.id === node.id)continue;
510 && node instanceof Unun
511 && !(this.targetNode instanceof Unun)
512 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
514 this.targetNode = node;
515 this.setStatus(EAction.UNUN_SMELL_START);
518 else if (node instanceof Food) {
519 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
521 //A yukkuri to go to the food area
522 this.targetNode = node;
523 this.setStatus(EAction.MOVE_TO_EAT_START);
527 //not hunbry or not food.
530 else if(node instanceof Yukkuri){
531 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
532 this.targetNode = node;
533 this.setStatus(EAction.COMMUNICATE_START);
537 else if(node instanceof Place){
538 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
539 this.targetNode = node;
540 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
545 this.status = EAction.WALK;
548 var Event = enchant.Class.create({
549 initialize: function (_data){
551 onactionstart:function(self){
553 if(typeof e === "undefined")return;
556 onactiontick:function(self){
558 if(typeof e === "undefined")return;
561 onactionend:function(self){
563 if(typeof e === "undefined")return;
567 var WalkEvent = enchant.Class.create(Event,{
568 initialize: function (_data){
570 this.yukkuri = _data.myYukkuri;
571 this.action = _data.action;
573 mangMsg.output(this.yukkuri, EMsg.SLEEP);
574 this.action.setStatus(EAction.SLEEP_WAIT);
575 this.yukkuri.setFaceImage(EFace.SLEEP);
576 this.yukkuri.tlPause();
578 this.yukkuri.addEventListener('enterframe', function() {
579 var yukkuri = self.yukkuri;
587 var SleepEvent = enchant.Class.create(Event,{
588 initialize: function (_data){
590 this.yukkuri = _data.myYukkuri;
591 this.action = _data.action;
593 mangMsg.output(this.yukkuri, EMsg.SLEEP);
594 this.action.setStatus(EAction.SLEEP_WAIT);
595 this.yukkuri.setFaceImage(EFace.SLEEP);
596 this.yukkuri.tlPause();
599 this.yukkuri.addEventListener('enterframe', function() {
600 var yukkuri = self.yukkuri;
601 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
602 if(yukkuri.param.sleep <= 0){
603 yukkuri.param.sleep = 0;
604 this.removeEventListener("enterframe",arguments.callee);
605 mangMsg.output(self.yukkuri, EMsg.GET_UP);
606 yukkuri.setFaceImage(EFace.NORMAL);
608 // self.action.setStatus(EAction.WAIT);
609 self.action.setStatus(EAction.THINK);
615 var UnunEvent = enchant.Class.create(Event,{
616 initialize: function (_data){
618 this.yukkuri = _data.myYukkuri;
619 this.action = _data.action;
620 this.action.setStatus(EAction.UNUN_WAIT);
621 mangMsg.output(this.yukkuri, EMsg.UNUN);
622 this.yukkuri.setFaceImage(EFace.HAPPY2);
625 this.yukkuri.wait(sec, {
626 "onactionend": this.onactionend(this)
629 onactionend:function(self){
631 if(typeof e === "undefined")return;
633 self.action.setStatus(EAction.WAIT);
634 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
636 "waitframe": FPS * 1.5,
637 "action": self.action,
638 "myYukkuri": self.yukkuri
643 var WaitEvent = enchant.Class.create(Event,{
644 initialize: function (_data){
646 this.yukkuri = _data.myYukkuri;
647 this.action = _data.action;
648 this.waitframe = _data.waitframe;
649 this.yukkuri.wait(this.waitframe, {
650 "onactionstart": this.onactionstart(this),
651 "onactiontick": this.onactiontick(this),
652 "onactionend": this.onactionend(this)
655 onactionend:function(self){
657 if(typeof e === "undefined")return;
658 self.action.setStatus(EAction.THINK);
662 var UnunSmellEvent = enchant.Class.create(Event,{
663 initialize: function (_data){
665 this.yukkuri = _data.myYukkuri;
666 this.action = _data.action;
667 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
668 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
669 this.yukkuri.setFaceImage(EFace.CRY1);
671 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
672 this.yukkuri.wait(sec, {
673 "onactionstart": this.onactionstart(this),
674 "onactiontick": this.onactiontick(this),
675 "onactionend": this.onactionend(this)
678 onactionend:function(self){
680 if(typeof e === "undefined")return;
681 self.action.setStatus(EAction.THINK);
686 var EatEvent = enchant.Class.create(Event,{
687 initialize: function (_data){
689 this.yukkuri = _data.myYukkuri;
690 this.food = _data.targetNode;
691 this.action = _data.action;
692 this.action.setStatus(EAction.EAT_WAIT);
695 var sec = BASE_FPS * 3;
696 if(this.yukkuri.eat(this.food)){
697 mangMsg.output(this.yukkuri, EMsg.EAT);
698 this.yukkuri.setFaceImage(EFace.EAT2);
701 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
702 this.yukkuri.setFaceImage(EFace.CRY2);
704 this.yukkuri.wait(sec, {
705 "onactionend": this.onactionend(this)
708 onactionend:function(self){
710 if(typeof e === "undefined")return;
711 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
712 self.action.setStatus(EAction.THINK);
713 self.yukkuri.setFaceImage(EFace.NORMAL);
715 self.action.setStatus(EAction.EAT_START);
722 * -When yukkuri find Food.
725 * targetNode: enchant.Node
729 var MoveToEatEvent = enchant.Class.create(Event,{
730 initialize: function (_data){
732 this.yukkuri = this.data.myYukkuri;
733 this.action = this.data.action;
735 var yukkuri = this.yukkuri;
736 var node = this.data.targetNode;
738 if(this.data.type == "food"){
739 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
740 yukkuri.vx = node.x - yukkuri.getX();
741 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
742 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
743 var frame = distance + distance/5 + 1;
744 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
747 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
748 "onactionstart": this.onactionstart(this),
749 "onactiontick": this.onactiontick(this),
750 "onactionend": this.onactionend(this)
754 onactionstart:function(self){
756 if(typeof e === "undefined")return;
757 mangMsg.output(EMsg.TARGETING_EAT);
758 // self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
761 onactiontick:function(self){
763 if(typeof e === "undefined")return;
766 onactionend:function(self){
768 if(typeof e === "undefined")return;
769 self.action.setStatus(EAction.EAT_START);
773 var MoveCommandEvent = enchant.Class.create(Event,{
774 initialize: function (_data){
776 this.yukkuri = this.data.myYukkuri;
777 this.action = this.data.action;
778 this.vx = this.data.vx;
779 this.vy = this.data.vy;
781 var yukkuri = this.yukkuri;
782 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
783 yukkuri.vx = node.x - yukkuri.getX();
784 yukkuri.vy = node.y - yukkuri.getY();
785 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
786 var frame = distance + 1;
787 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
788 "onactionstart": this.onactionstart(this),
789 "onactiontick": this.onactiontick(this),
790 "onactionend": this.onactionend(this)
793 onactionstart:function(self){
795 if(typeof e === "undefined")return;
798 onactiontick:function(self){
800 if(typeof e === "undefined")return;
803 onactionend:function(self){
805 if(typeof e === "undefined")return;
806 self.action.setStatus(EAction.THINK);
811 * Say hello contact to send communication .
813 var ComSayHelloSendEvent = enchant.Class.create(Event,{
814 initialize: function (_data){
816 this.yukkuri = _data.myYukkuri;
817 this.targetYukkuri = _data.targetNode;
818 this.action = _data.action;
819 this.action.setStatus(EAction.COMMUNICATE_WAIT);
821 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
823 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
824 this.targetYukkuri.tlPause();
825 this.yukkuri.tlPause();
826 this.yukkuri.syncDirection(this.targetYukkuri);
828 this.yukkuri.addAddress(this.targetYukkuri);
829 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
831 var sec = BASE_FPS * 2;
832 this.yukkuri.wait(sec, {
833 "onactiontick": this.onactiontick(this),
834 "onactionend": this.onactionend(this)
837 onactiontick:function(self){
839 if(typeof e === "undefined")return;
842 onactionend:function(self){
844 if(typeof e === "undefined")return;
845 new ComSayHelloRecvEvent({
847 "targetNode": self.yukkuri,
848 "action": self.targetYukkuri.action,
849 "myYukkuri": self.targetYukkuri
854 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
855 initialize: function (_data){
857 this.yukkuri = _data.myYukkuri;
858 this.targetYukkuri = _data.targetNode;
859 this.action = _data.action;
860 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
861 this.yukkuri.addAddress(this.targetYukkuri);
862 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
864 var sec = BASE_FPS * 2;
865 this.yukkuri.wait(sec, {
866 "onactiontick": this.onactiontick(this),
867 "onactionend": this.onactionend(this)
870 onactiontick:function(self){
872 if(typeof e === "undefined")return;
875 onactionend:function(self){
877 if(typeof e === "undefined")return;
878 self.action.setStatus(EAction.THINK);
880 self.yukkuri.action.setStatus(EAction.THINK);
881 self.yukkuri.animation();
882 self.targetYukkuri.action.setStatus(EAction.THINK);
883 self.targetYukkuri.animation();
887 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
888 initialize: function (_data){
890 this.yukkuri = this.data.myYukkuri;
891 this.action = this.data.action;
893 var yukkuri = this.yukkuri;
894 var node = this.data.targetNode;
896 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
897 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
898 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
899 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
900 var frame = distance + distance/5 + 1;
901 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
904 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
905 "onactionend": this.onactionend(this)
908 onactionend:function(self){
910 if(typeof e === "undefined")return;
911 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
918 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
919 initialize: function (_data){
921 this.yukkuri = _data.myYukkuri;
922 this.place = _data.targetNode;
923 this.action = _data.action;
924 this.action.setStatus(EAction.WAIT);
927 var sec = BASE_FPS * 3;
928 this.yukkuri.declarePlace(this.place);
929 this.place.setOwner(this.yukkuri);
930 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
932 this.yukkuri.setFaceImage(EFace.NORMAL);
933 this.yukkuri.wait(sec, {
934 "onactionend": this.onactionend(this)
937 onactionend:function(self){
939 if(typeof e === "undefined")return;
940 self.action.setStatus(EAction.THINK);
945 var Food = enchant.Class.create(ObjSprite,{
946 initialize: function (type, x, y){
947 this.classname = "Food";
948 ObjSprite.call(this,16,16);
949 this.image = game.assets[EResPath.OBJECT];
953 //一つにつきgiveの値分、hunguryを減少させられる
956 foodGroup.addChild(this);
957 this.addEventListener('enterframe', function(){
958 if(this.amount <= 0){
963 getAmount: function(){
970 var Place = enchant.Class.create(ObjSprite,{
971 initialize: function (type, x, y){
972 ObjSprite.call(this,128,128);
973 this.image = game.assets[EResPath.PLACE_TREE];
974 this.x = x - this.width / 2;
975 this.y = y - this.height / 2;
976 backgroundMap.addChild(this);
979 this.foodsNormal = 0;
981 // this.addEventListener('enterframe', function(){
982 // if(this.age%10 === 0 && this.age !== 0){
983 // console.log("x/y " + this.x + "/" + this.y);
985 // if(game.input.left){
988 // if(game.input.right){
991 // if(game.input.up){
994 // if(game.input.down){
999 getStatusForDisplay: function(){
1002 if(this.owner == null)ownerId = "なし";
1003 else ownerId = this.owner.id;
1004 ret += "プレイスID " + this.id + "\n";
1005 ret += "オーナーID " + ownerId + "\n";
1006 ret += "食料うめぇ " + this.foodsGraet + "\n";
1007 ret += "食料それなりー " + this.foodsNormal + "\n";
1008 ret += "食料にがにが " + this.foodsBad + "\n";
1011 setOwner: function(yukkuri){
1012 this.owner = yukkuri;
1014 isOwner: function(){
1015 return this.owner !== null;
1018 var Unun = enchant.Class.create(ObjSprite,{
1019 initialize: function (x, y){
1020 this.classname = "Unun";
1021 ObjSprite.call(this,32,32);
1022 this.image = game.assets[EResPath.YUKKURI_UNUN];
1025 backgroundMap.addChild(this);
1028 var Okazari = enchant.Class.create(enchant.Sprite,{
1029 initialize: function(){
1030 this.classname = "Okazari";
1031 enchant.Sprite.call(this, 64, 64);
1032 this.image = game.assets[EResPath.OKAZARI];
1033 this.x = -CHARA_WIDTH / 2;
1034 this.y = -12 - CHARA_HEIGHT / 2;
1037 var Address = enchant.Class.create({
1038 initialize: function(yukkuri){
1039 this.friendlyLv = 1;
1040 this.yukkuri = yukkuri;
1041 this.isGreeting = false;
1042 this.greetingWaitFrame = 0;
1044 "beginSayHello" : false,
1049 set:function(key, value){
1050 this.comMatrix[key] = value;
1053 return this.comMatrix[key];
1057 var Yukkuri = enchant.Class.create(ObjSprite,{
1058 initialize: function(x, y){
1059 ObjSprite.call(this, 64, 64);
1060 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1061 this.classname = "Yukkuri";
1062 this.addressBook = {};
1063 this.imgGroup = new SpriteGroup();
1064 this.imgBody = new SpriteGroup();
1065 this.imgGroup.id = guid();
1066 this.imgBody.id = guid();
1067 this.x = -CHARA_WIDTH / 2;
1068 this.y = -CHARA_HEIGHT / 2;
1071 this.image = game.assets[EResPath.YUKKURI_BASE];
1072 this.direction = EDirection.RIGHT;
1073 this.addEventListener('enterframe', this.runEnterframe);
1074 this.bodyStatus ={};
1075 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1076 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1077 this.walkAnimationStatus = EWalkAnimation.END;
1080 runEnterframe:function(){
1081 // this.imgGroup.x = 0;
1084 if(this.isDead())return;
1092 if(this.direction == EDirection.RIGHT){
1093 this.imgBody.scaleX = 1;
1095 else if(this.direction == EDirection.LEFT){
1096 this.imgBody.scaleX = -1;
1099 tweet:function(text){
1100 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1102 moveTo:function(x, y, time){
1103 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1105 moveBy:function(x, y, time, eventFunctions){
1109 return self.imgGroup.x + x;
1112 return self.imgGroup.y + y;
1115 easing: enchant.Easing.SIN_EASEINOUT
1117 //-Event register [onactionstart,onactiontick,onactionend]
1118 if(eventFunctions !== undefined){
1119 for(var key in eventFunctions){
1120 params[key] = eventFunctions[key];
1123 return this.imgGroup.tl.tween(params);
1125 wait:function(frame, eventFunctions){
1126 this.moveBy(0,1,frame,eventFunctions);
1131 animation: function(){
1132 if(this.walkAnimationStatus == EWalkAnimation.END){
1134 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
1135 "onactionstart": function(e){
1136 this.walkAnimationStatus = EWalkAnimation.START;
1139 .moveByEx(0, 5, 10, enchant.Easing.SWING,
1141 "onactionend": function(e){
1142 this.walkAnimationStatus = EWalkAnimation.END;
1147 this.imgBody.tl.loop();
1150 getWidth: function(){
1153 getHeight: function(){
1157 return this.imgGroup.x;
1160 return this.imgGroup.y;
1163 this.imgGroup.x += x;
1165 // this.shadow.x += x;
1166 // this._tweet.x += x;
1169 this.imgGroup.y += y;
1171 // this.shadow.y += y;
1172 // this._tweet.y += y;
1174 // changeFace: function(erespath){
1175 // this.face.image = game.assets[erespath];
1177 loadParamsXML: function(url){
1178 var http = new JKL.ParseXML( url );
1179 return http.parse();
1181 runYukkuri: function(){
1182 if(this.param.hungry > 70){
1183 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1184 this.param.yukkuri -= 1;
1187 else if(this.param.hungry < 10){
1188 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1191 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1192 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1194 runHungry: function(){
1195 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1196 if(this.param.hungry >= 100)this.param.hungry = 100;
1198 runUnun: function(){
1199 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1200 if(this.param.unun >= 100)this.param.unun = 100;
1202 runSleep: function(){
1203 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1204 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1205 if(this.param.sleep >= 100){
1206 this.param.sleep = 100;
1210 runAddress: function(){
1211 for(var key in this.addressBook){
1212 var address = this.addressBook[key];
1214 if(address.isGreeting){
1215 address.greetingWaitFrame++;
1216 if(address.greetingWaitFrame >= DAY){
1217 address.greetingWaitFrame = 0;
1218 address.isGreeting = false;
1223 changeFace: function(){
1224 if(this.param.yukkuri >= 80){
1225 this.setFaceImage(EFace.HAPPY1);
1227 else if(this.param.yukkuri >= 50){
1228 this.setFaceImage(EFace.NORMAL);
1230 else if(this.param.yukkuri >= 30){
1231 this.setFaceImage(EFace.TIRED);
1233 else if(this.param.yukkuri >= 10){
1234 this.setFaceImage(EFace.CRY1);
1236 else if(this.param.yukkuri >= 1){
1237 this.setFaceImage(EFace.CRY2);
1240 getRange: function(){
1241 return this.param.range;
1243 isSleep: function(){
1244 return this.param.sleep >= 100;
1247 return this.param.yukkuri <= 0;
1249 isManpuku: function(){
1250 return this.param.hungry <= 20;
1252 isKuhuku: function(){
1253 return this.param.hungry >= 40;
1255 getYukkuri: function(){
1256 return this.param.yukkuri;
1258 setYukkuri: function(yukkuri){
1259 this.param.yukkuri = yukkuri;
1260 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1262 getHungry: function(){
1263 return this.param.hungry;
1265 setHungry: function(hungry){
1266 this.param.hungry = hungry;
1267 if(this.param.hungry < 0)this.param.hungry = 0;
1269 getUnun: function(){
1270 return this.param.unun;
1272 setUnun: function(unun){
1273 this.param.unun = unun;
1274 if(this.param.unun < 0)this.param.unun = 0;
1278 if(food.amount > 0){
1280 this.setHungry(this.param.hungry - food.getGive());
1281 this.setUnun(this.getUnun() + food.getGive() / 4);
1282 this.setYukkuri(this.getYukkuri() + 5);
1285 this.setYukkuri(this.getYukkuri() - 5);
1289 declarePlace: function(place){
1292 isPlace: function(){
1293 return this.place !== null;
1297 if(this.direction == EDirection.RIGHT){
1298 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1300 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1304 setBodyImage: function(ebody){
1305 var path = this.bodyStatus[ebody];
1306 this.image = game.assets[path];
1309 // this.imgBody.tl.pause();
1310 // this.imgGroup.tl.pause();
1311 this.imgBody.tl.unloop();
1312 this.imgGroup.tl.unloop();
1314 tlResume: function(){
1315 // this.imgBody.tl.resume();
1316 // this.imgGroup.tl.resume();
1319 syncDirection:function(senderYukkuri){
1320 if(this.getX() > senderYukkuri.getX()){
1321 this.direction = EDirection.LEFT;
1322 senderYukkuri.direction = EDirection.RIGHT;
1324 this.direction = EDirection.RIGHT;
1325 senderYukkuri.direction = EDirection.LEFT;
1328 isCommunication: function(yukkuri){
1329 if(this.addressBook[yukkuri.id] === undefined) return true;
1330 if(this.addressBook[yukkuri.id].isGreeting) return false;
1333 addAddress: function(yukkuri){
1334 this.addressBook[yukkuri.id] = new Address(yukkuri);
1336 getAddress: function(yukkuri){
1337 if(this.addressBook[yukkuri.id] === undefined)return null;
1338 return this.addressBook[yukkuri.id];
1340 getStatusForDisplay: function (){
1342 var placeId = (this.place==null)?"無し" : this.place.id;
1343 ret += "ID " + this.id + "\n";
1344 ret += "プレイス " + placeId + "\n";
1347 destruct: function(){
1351 var Marisa = enchant.Class.create(Yukkuri,{
1352 initialize: function(x, y){
1353 Yukkuri.call(this,x,y);
1354 this.classname = "Marisa";
1356 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1357 var json = net.load("./data/marisa/params.json");
1358 this.param = json.root.param;
1359 this.shadow = new enchant.Sprite(64, 64);
1360 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1361 this.shadow.x = 0 + this.x;
1362 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1363 this.shadow.image._element.style.zIndex = 2;
1365 this._style.zIndex = 5;
1367 this.face = new enchant.Sprite(64, 64);
1368 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1369 this.face.x = -CHARA_WIDTH / 2;
1370 this.face.y = -CHARA_HEIGHT / 2;
1371 this.face._style.zIndex = 0;
1373 this.faceStatus ={};
1374 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1375 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1376 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1377 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1378 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1379 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1380 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1381 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1382 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1383 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1386 this.hear = new enchant.Sprite(64, 64);
1387 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1388 this.hear.x = -CHARA_WIDTH / 2;
1389 this.hear.y = -CHARA_HEIGHT / 2;
1390 this.hear._style.zIndex = 0;
1392 this.okazari = new Okazari();
1393 this.okazari.image._element.style.zIndex = 1;
1395 // this.imgGroup._style.zIndex = 1;
1397 this.imgGroup.addChild(this.shadow);
1398 this.imgBody.addChild(this);
1399 this.imgBody.addChild(this.face);
1400 this.imgBody.addChild(this.hear);
1401 this.imgBody.addChild(this.okazari);
1402 this.imgGroup.addChild(this.imgBody);
1403 backgroundMap.addChild(this.imgGroup);
1404 this._tweet = new TTweet(148, 64);
1406 this.imgGroup.addChild(this._tweet);
1407 this.imgGroup.x = x;
1408 this.imgGroup.y = y;
1410 this.action = new Action(this);
1413 setFaceImage: function(eface){
1414 var path = this.faceStatus[eface];
1415 this.face.image = game.assets[path];
1418 var Player = enchant.Class.create(Marisa,{
1419 initialize: function(x, y){
1420 // this.runEnterframe = function(){
1422 Marisa.call(this, x, y);
1423 this.classname = "Player";
1424 ctl.setPlayer(this);
1425 // this.removeEventListener('enterframe',this.runEnterframe);
1426 this.addEventListener('enterframe', function(){
1429 if(this.age%10 === 0 && this.age !== 0){
1430 // console.log("palyer:" + this.age);
1433 ///////////////////////////////////////////////
1434 //Action pattern debug
1435 if(game.input.left){
1436 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1438 this.direction = EDirection.LEFT;
1440 if(game.input.right){
1442 this.direction = EDirection.RIGHT;
1447 if(game.input.down){
1450 ///////////////////////////////////////////////
1452 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1453 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1455 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1457 //- Display the circle of search range.
1458 // fieldBg.image.clear();
1459 // fieldBg.image.context.beginPath();
1460 // fieldBg.image.context.fillStyle = '#ff0000';
1461 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1462 // fieldBg.image.context.fill();
1466 game.onload = function(){
1469 def.ObjSprite = ObjSprite;
1470 def.Yukkuri = Yukkuri;
1471 def.nodeSort = nodeSort;
1472 mangTouch = new MangTouch(ctl);
1473 mangMsg = new MangMsg(ctl);
1474 ctl.setDefined(def);
1475 backgroundMap.image = game.assets[EResPath.MAP0];
1476 backgroundMap.loadData(_mapData);
1477 backgroundMap.collisionData = _collisionData;
1479 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1480 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1481 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1482 fieldBg.image = fieldSurface;
1486 windowFront.image = windowSurface;
1489 windowFront.opacity = 0.5;
1491 windowSurface.context.fillStyle = '#000';
1492 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1495 menuSurface.context.fillStyle = '#000';
1496 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1497 menuBg.image = menuSurface;
1498 menuBg.x = EMenuPos.X;
1499 menuBg.y = EMenuPos.Y;
1500 backgroundMap.addChild(fieldBg);
1501 mangIcon = new MangIcon(ctl, menuBg);
1503 game.rootScene.addChild(backgroundMap);
1504 game.rootScene.addChild(windowFront);
1505 game.rootScene.addChild(menuBg);
1507 // var labelGroup = new LabelGroup();
1508 mangLabel = new MangLabel(ctl, menuBg);
1509 // var info = new Label("ゆっくり");
1510 // info.color = "#ffffff";
1511 // info.font = "14px 'Times New Roman'";
1513 // info.y = GAME_HEIGHT / 2;
1514 // labelGroup.addChild(info);
1515 // menuBg.addChild(labelGroup);
1518 // var food = new def.Food("apple", 200, 250);
1519 backgroundMap.addChild(foodGroup);
1520 // backgroundMap.addChild(placeGroup);
1521 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1522 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
1523 new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
1526 game.rootScene.addEventListener('touchstart', function (e) {
1527 game.touched = true;
1528 var mang = mangTouch.get(ctl.getCurrentCommand());
1531 game.rootScene.addEventListener('touchmove', function (e) {
1532 var mang = mangTouch.get(ctl.getCurrentCommand());
1535 game.rootScene.addEventListener('touchend', function (e) {
1536 var mang = mangTouch.get(ctl.getCurrentCommand());
1538 game.touched = false;
1542 game.rootScene.addEventListener('enterframe', function(){
1544 mangLabel.draw(player);
1546 this.addEventListener('enterframe', function(){
1547 //The priority processing of display instead of z-index
1548 backgroundMap.childNodes.sort(nodeSort
1550 // if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1553 // else if(typeof a.id === "undefined"){
1556 // else if(typeof b.id === "undefined"){
1561 // if(a instanceof Box && b instanceof Box){
1564 // if(a instanceof Box){
1567 // if(b instanceof Box){
1571 // if(a instanceof Place){
1572 // ay += Math.round(a.height * 0.7);
1574 // if(b instanceof Place){
1575 // by += Math.round(b.height * 0.7);
1578 // if(ay < by)return -1;
1579 // else if(ay > by)return 1;
1580 // if(a.id < b.id)return -1;
1581 // else if(a.id > b.id)return 1;