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 // PLACE_TREE : './data/system/rapture.png',
85 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
96 MOVE_TO_EAT_START: 10,
97 MOVE_TO_EAT_UNDERWAY: 11,
101 UNUN_SMELL_START : 15,
102 UNUN_SMELL_WAIT : 16,
105 COMMUNICATE_START : 19,
106 COMMUNICATE_WAIT: 20,
107 COMMUNICATE_RECV: 21,
108 MOVE_TO_PLACE_START_HOMELESS: 22,
109 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
110 DECLARE_PLACE_HOMELESS: 24,
111 MOVE_TO_HUNT_START: 25,
134 var EWalkAnimation = {
140 var ObjSprite = enchant.Class.create(enchant.Sprite,{
141 initialize: function (w, h){
142 enchant.Sprite.call(this, w, h);
147 // // new BoxLabel(this.ctl,100, e.x, e.y);
148 // var box = new Box(this.ctl, 200, 200);
150 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
153 getStatusForDisplay: function (){
162 removeAll: function(){
169 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
180 //-Event register [onactionstart,onactiontick,onactionend]
181 if(eventFunctions !== undefined){
182 for(var key in eventFunctions){
183 params[key] = eventFunctions[key];
186 return this.tween(params);
191 include("./lang/ja.js");
192 window.onload = function(){
193 var nodeSort = function (a, b){
194 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
197 else if(typeof a.id === "undefined"){
200 else if(typeof b.id === "undefined"){
205 if(a instanceof Box && b instanceof Box){
208 if(a instanceof Box){
211 if(b instanceof Box){
215 if(a instanceof Place){
216 ay += Math.round(a.height * 0.7);
218 if(b instanceof Place){
219 by += Math.round(b.height * 0.7);
222 if(ay < by)return -1;
223 else if(ay > by)return 1;
224 if(a.id < b.id)return -1;
225 else if(a.id > b.id)return 1;
231 var def = new Object();
232 var foodGroup = new Group();
233 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
234 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
235 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
236 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
237 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
241 for(var _v in EResPath){
242 _loadArr[i] = EResPath[_v];
245 game.preload(_loadArr);
246 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
247 var backgroundMap = new MapGroup(16, 16);
248 include("./class.js");
249 include("./ctrl.js");
252 ctl.setBackgroundMap(backgroundMap);
253 var Action = enchant.Class.create({
254 initialize: function (yukkuri){
255 this.status = EAction.THINK;
256 this.yukkuri = yukkuri;
257 this.isMoving = false;
258 this.targetNode = null;
260 getStatus: function(){
263 setStatus: function(eaction){
264 this.status = eaction;
267 if(this.yukkuri.isDead()){
268 this.status = EAction.DEAD;
270 // else if(this.yukkuri.isSleep()){
271 // this.status = EAction.SLEEP;
283 if(this.yukkuri.age%2 === 0){
284 if(this.yukkuri.isPlace()){
285 this.searchHavePlace();
288 if(this.yukkuri.isSleep()){
289 this.setStatus(EAction.SLEEP_START);
291 else if(this.yukkuri.getUnun() >= 80){
292 this.setStatus(EAction.UNUN_START);
295 // this.yukkuri.param.yukkuri -= 1;
296 this.yukkuri.changeFace();
303 case EAction.MOVE_TO_EAT_START:
304 this.move_to_eat_start();
306 case EAction.MOVE_TO_EAT_UNDERWAY:
312 case EAction.SLEEP_START:
315 case EAction.SLEEP_WAIT:
320 case EAction.EAT_START:
323 case EAction.EAT_WAIT:
325 case EAction.UNUN_START:
328 case EAction.UNUN_WAIT:
330 case EAction.MOVE_TO_COMMAND:
331 this.move_to_command();
333 case EAction.UNUN_SMELL_START:
334 this.unun_smell_start();
336 case EAction.COMMUNICATE_START:
337 this.communicate_start();
339 case EAction.COMMUNICATE_WAIT:
341 case EAction.COMMUNICATE_RECV:
343 case EAction.MOVE_TO_PLACE_START_HOMELESS:
344 this.move_to_place_start_homeless();
346 case EAction.DECLARE_PLACE_HOMELESS:
347 this.declare_place_homeless();
351 this.yukkuri.reverse();
354 move_to_eat_start : function(){
357 "targetNode": this.targetNode,
359 "myYukkuri": this.yukkuri
365 walk : function(retryCounter){
366 if(retryCounter > 15){
368 this.status = EAction.NONE;
369 console.log("retryCount over");
372 if(this.yukkuri.imgGroup.tl.queue.length === 0){
375 this.isMoving = false;
376 this.status = EAction.THINK;
380 var xpos = 150 + rand(40) - (retryCounter * 10);
381 var ypos = 150 + rand(40) - (retryCounter * 10);
384 this.yukkuri.vy = -ypos;
386 else if(rand(8) == 1){
387 this.yukkuri.vx = xpos;
388 this.yukkuri.vy = -ypos;
389 this.yukkuri.direction = EDirection.RIGHT;
391 else if(rand(8) == 2){
392 this.yukkuri.vx = xpos;
394 this.yukkuri.direction = EDirection.RIGHT;
396 else if(rand(8) == 3){
397 this.yukkuri.vx = xpos;
398 this.yukkuri.vy = ypos;
399 this.yukkuri.direction = EDirection.RIGHT;
401 else if(rand(8) == 4){
403 this.yukkuri.vy = ypos;
405 else if(rand(8) == 5){
406 this.yukkuri.vx = -xpos;
407 this.yukkuri.vy = ypos;
408 this.yukkuri.direction = EDirection.LEFT;
410 else if(rand(8) == 6){
411 this.yukkuri.vx = -xpos;
413 this.yukkuri.direction = EDirection.LEFT;
415 else if(rand(8) == 7){
416 this.yukkuri.vx = -xpos;
417 this.yukkuri.vy = -ypos;
418 this.yukkuri.direction = EDirection.LEFT;
420 if (this.yukkuri.vx || this.yukkuri.vy) {
421 var map = ctl.backgroundMap;
422 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
423 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
424 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
425 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
426 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
427 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
428 // console.log("X:" + this.yukkuri.moveX);
429 // console.log("Y:" + this.yukkuri.moveY);
430 this.isMoving = true;
431 this.yukkuri.reverse();
432 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
433 mangMsg.output(this.yukkuri,EMsg.WALK);
435 this.targetNode = null;
437 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
438 this.walk(retryCounter+1);
444 sleep_start: function(){
447 "myYukkuri": this.yukkuri
452 mangMsg.output(this.yukkuri, EMsg.DEAD);
453 this.yukkuri.tlPause();
454 this.yukkuri.setBodyImage(EBody.DEAD);
456 eat_start: function(){
459 "targetNode": this.targetNode,
461 "myYukkuri": this.yukkuri
465 unun_start: function(){
468 "myYukkuri": this.yukkuri
471 unun_smell_start: function(){
474 "myYukkuri": this.yukkuri
477 communicate_start:function(){
478 new ComSayHelloSendEvent({
480 "targetNode": this.targetNode,
482 "myYukkuri": this.yukkuri
485 move_to_place_start_homeless:function(){
486 new MoveToPlaceStartHomelessEvent({
487 "targetNode": this.targetNode,
489 "myYukkuri": this.yukkuri
492 declare_place_homeless:function(){
493 new DeclarePlaceHomelessEvent({
494 "targetNode": this.targetNode,
496 "myYukkuri": this.yukkuri
499 move_to_command: function(){
502 searchHavePlace: function(){
503 var nodes = ctl.getObjs();
507 for (var key in nodes) {
508 var node = nodes[key];
509 if(this.yukkuri.id === node.id)continue;
511 && node instanceof Unun
512 && !(this.targetNode instanceof Unun)
513 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
515 this.targetNode = node;
516 this.setStatus(EAction.UNUN_SMELL_START);
519 else if (node instanceof Food) {
520 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
522 //A yukkuri to go to the food area
523 this.targetNode = node;
524 this.setStatus(EAction.MOVE_TO_EAT_START);
528 //not hunbry or not food.
531 else if(node instanceof Yukkuri){
532 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
533 this.targetNode = node;
534 this.setStatus(EAction.COMMUNICATE_START);
538 else if(node instanceof Place){
539 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
540 this.targetNode = node;
541 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
546 this.status = EAction.WALK;
549 var nodes = ctl.getObjs();
553 for (var key in nodes) {
554 var node = nodes[key];
555 if(this.yukkuri.id === node.id)continue;
557 && node instanceof Unun
558 && !(this.targetNode instanceof Unun)
559 && this.yukkuri.within(node, this.yukkuri.getRange() / 2)) {
561 this.targetNode = node;
562 this.setStatus(EAction.UNUN_SMELL_START);
565 else if (node instanceof Food) {
566 if(this.yukkuri.isKuhuku() && this.yukkuri.within(node, this.yukkuri.getRange())){
568 //A yukkuri to go to the food area
569 this.targetNode = node;
570 this.setStatus(EAction.MOVE_TO_EAT_START);
574 //not hunbry or not food.
577 else if(node instanceof Yukkuri){
578 if(this.yukkuri.isCommunication(node) && this.yukkuri.within(node, this.yukkuri.getRange())){
579 this.targetNode = node;
580 this.setStatus(EAction.COMMUNICATE_START);
584 else if(node instanceof Place){
585 if(!node.isOwner() && !this.yukkuri.isPlace() && this.yukkuri.within(node, this.yukkuri.getRange())){
586 this.targetNode = node;
587 this.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
592 this.status = EAction.WALK;
595 var Event = enchant.Class.create({
596 initialize: function (_data){
598 onactionstart:function(self){
600 if(typeof e === "undefined")return;
603 onactiontick:function(self){
605 if(typeof e === "undefined")return;
608 onactionend:function(self){
610 if(typeof e === "undefined")return;
614 var WalkEvent = enchant.Class.create(Event,{
615 initialize: function (_data){
617 this.yukkuri = _data.myYukkuri;
618 this.action = _data.action;
620 mangMsg.output(this.yukkuri, EMsg.SLEEP);
621 this.action.setStatus(EAction.SLEEP_WAIT);
622 this.yukkuri.setFaceImage(EFace.SLEEP);
623 this.yukkuri.tlPause();
625 this.yukkuri.addEventListener('enterframe', function() {
626 var yukkuri = self.yukkuri;
634 var SleepEvent = enchant.Class.create(Event,{
635 initialize: function (_data){
637 this.yukkuri = _data.myYukkuri;
638 this.action = _data.action;
640 mangMsg.output(this.yukkuri, EMsg.SLEEP);
641 this.action.setStatus(EAction.SLEEP_WAIT);
642 this.yukkuri.setFaceImage(EFace.SLEEP);
643 this.yukkuri.tlPause();
646 this.yukkuri.addEventListener('enterframe', function() {
647 var yukkuri = self.yukkuri;
648 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
649 if(yukkuri.param.sleep <= 0){
650 yukkuri.param.sleep = 0;
651 this.removeEventListener("enterframe",arguments.callee);
652 mangMsg.output(self.yukkuri, EMsg.GET_UP);
653 yukkuri.setFaceImage(EFace.NORMAL);
655 // self.action.setStatus(EAction.WAIT);
656 self.action.setStatus(EAction.THINK);
662 var UnunEvent = enchant.Class.create(Event,{
663 initialize: function (_data){
665 this.yukkuri = _data.myYukkuri;
666 this.action = _data.action;
667 this.action.setStatus(EAction.UNUN_WAIT);
668 mangMsg.output(this.yukkuri, EMsg.UNUN);
669 this.yukkuri.setFaceImage(EFace.HAPPY2);
672 this.yukkuri.wait(sec, {
673 "onactionend": this.onactionend(this)
676 onactionend:function(self){
678 if(typeof e === "undefined")return;
680 self.action.setStatus(EAction.WAIT);
681 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
683 "waitframe": FPS * 1.5,
684 "action": self.action,
685 "myYukkuri": self.yukkuri
690 var WaitEvent = enchant.Class.create(Event,{
691 initialize: function (_data){
693 this.yukkuri = _data.myYukkuri;
694 this.action = _data.action;
695 this.waitframe = _data.waitframe;
696 this.yukkuri.wait(this.waitframe, {
697 "onactionstart": this.onactionstart(this),
698 "onactiontick": this.onactiontick(this),
699 "onactionend": this.onactionend(this)
702 onactionend:function(self){
704 if(typeof e === "undefined")return;
705 self.action.setStatus(EAction.THINK);
709 var UnunSmellEvent = enchant.Class.create(Event,{
710 initialize: function (_data){
712 this.yukkuri = _data.myYukkuri;
713 this.action = _data.action;
714 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
715 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
716 this.yukkuri.setFaceImage(EFace.CRY1);
718 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
719 this.yukkuri.wait(sec, {
720 "onactionend": this.onactionend(this)
723 onactionend:function(self){
725 if(typeof e === "undefined")return;
726 self.action.setStatus(EAction.THINK);
731 var EatEvent = enchant.Class.create(Event,{
732 initialize: function (_data){
734 this.yukkuri = _data.myYukkuri;
735 this.food = _data.targetNode;
736 this.action = _data.action;
737 this.action.setStatus(EAction.EAT_WAIT);
740 var sec = BASE_FPS * 3;
741 if(this.yukkuri.eat(this.food)){
742 mangMsg.output(this.yukkuri, EMsg.EAT);
743 this.yukkuri.setFaceImage(EFace.EAT2);
746 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
747 this.yukkuri.setFaceImage(EFace.CRY2);
749 this.yukkuri.wait(sec, {
750 "onactionend": this.onactionend(this)
753 onactionend:function(self){
755 if(typeof e === "undefined")return;
756 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
757 self.action.setStatus(EAction.THINK);
758 self.yukkuri.setFaceImage(EFace.NORMAL);
760 self.action.setStatus(EAction.EAT_START);
767 * -When yukkuri find Food.
770 * targetNode: enchant.Node
774 var MoveToEatEvent = enchant.Class.create(Event,{
775 initialize: function (_data){
777 this.yukkuri = this.data.myYukkuri;
778 this.action = this.data.action;
780 var yukkuri = this.yukkuri;
781 var node = this.data.targetNode;
783 if(this.data.type == "food"){
784 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
785 yukkuri.vx = node.x - yukkuri.getX();
786 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2;
787 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
788 var frame = distance + distance/5 + 1;
789 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
792 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
793 "onactionstart": this.onactionstart(this),
794 "onactiontick": this.onactiontick(this),
795 "onactionend": this.onactionend(this)
799 onactionstart:function(self){
801 if(typeof e === "undefined")return;
802 mangMsg.output(EMsg.TARGETING_EAT);
803 // self.yukkuri.tweet("ゆゆ??\nたべものさん\nはっけんなのぜ!");
806 onactiontick:function(self){
808 if(typeof e === "undefined")return;
811 onactionend:function(self){
813 if(typeof e === "undefined")return;
814 self.action.setStatus(EAction.EAT_START);
818 var MoveCommandEvent = enchant.Class.create(Event,{
819 initialize: function (_data){
821 this.yukkuri = this.data.myYukkuri;
822 this.action = this.data.action;
823 this.vx = this.data.vx;
824 this.vy = this.data.vy;
826 var yukkuri = this.yukkuri;
827 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
828 yukkuri.vx = node.x - yukkuri.getX();
829 yukkuri.vy = node.y - yukkuri.getY();
830 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
831 var frame = distance + 1;
832 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
833 "onactionstart": this.onactionstart(this),
834 "onactiontick": this.onactiontick(this),
835 "onactionend": this.onactionend(this)
838 onactionstart:function(self){
840 if(typeof e === "undefined")return;
843 onactiontick:function(self){
845 if(typeof e === "undefined")return;
848 onactionend:function(self){
850 if(typeof e === "undefined")return;
851 self.action.setStatus(EAction.THINK);
856 * Say hello contact to send communication .
858 var ComSayHelloSendEvent = enchant.Class.create(Event,{
859 initialize: function (_data){
861 this.yukkuri = _data.myYukkuri;
862 this.targetYukkuri = _data.targetNode;
863 this.action = _data.action;
864 this.action.setStatus(EAction.COMMUNICATE_WAIT);
866 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
868 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
869 this.targetYukkuri.tlPause();
870 this.yukkuri.tlPause();
871 this.yukkuri.syncDirection(this.targetYukkuri);
873 this.yukkuri.addAddress(this.targetYukkuri);
874 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
876 var sec = BASE_FPS * 2;
877 this.yukkuri.wait(sec, {
878 "onactiontick": this.onactiontick(this),
879 "onactionend": this.onactionend(this)
882 onactiontick:function(self){
884 if(typeof e === "undefined")return;
887 onactionend:function(self){
889 if(typeof e === "undefined")return;
890 new ComSayHelloRecvEvent({
892 "targetNode": self.yukkuri,
893 "action": self.targetYukkuri.action,
894 "myYukkuri": self.targetYukkuri
899 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
900 initialize: function (_data){
902 this.yukkuri = _data.myYukkuri;
903 this.targetYukkuri = _data.targetNode;
904 this.action = _data.action;
905 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
906 this.yukkuri.addAddress(this.targetYukkuri);
907 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
909 var sec = BASE_FPS * 2;
910 this.yukkuri.wait(sec, {
911 "onactiontick": this.onactiontick(this),
912 "onactionend": this.onactionend(this)
915 onactiontick:function(self){
917 if(typeof e === "undefined")return;
920 onactionend:function(self){
922 if(typeof e === "undefined")return;
923 self.action.setStatus(EAction.THINK);
925 self.yukkuri.action.setStatus(EAction.THINK);
926 self.yukkuri.animation();
927 self.targetYukkuri.action.setStatus(EAction.THINK);
928 self.targetYukkuri.animation();
932 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
933 initialize: function (_data){
935 this.yukkuri = this.data.myYukkuri;
936 this.action = this.data.action;
938 var yukkuri = this.yukkuri;
939 var node = this.data.targetNode;
941 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
942 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
943 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
944 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
945 var frame = distance + distance/5 + 1;
946 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
949 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
950 "onactionend": this.onactionend(this)
953 onactionend:function(self){
955 if(typeof e === "undefined")return;
956 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
963 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
964 initialize: function (_data){
966 this.yukkuri = _data.myYukkuri;
967 this.place = _data.targetNode;
968 this.action = _data.action;
969 this.action.setStatus(EAction.WAIT);
972 var sec = BASE_FPS * 3;
973 this.yukkuri.declarePlace(this.place);
974 this.place.setOwner(this.yukkuri);
975 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
977 this.yukkuri.setFaceImage(EFace.NORMAL);
978 this.yukkuri.wait(sec, {
979 "onactionend": this.onactionend(this)
982 onactionend:function(self){
984 if(typeof e === "undefined")return;
985 self.action.setStatus(EAction.THINK);
990 var Food = enchant.Class.create(ObjSprite,{
991 initialize: function (type, x, y){
992 this.classname = "Food";
993 //一つにつきgiveの値分、hunguryを減少させられる
995 ObjSprite.call(this,16,16);
996 this.image = game.assets[EResPath.OBJECT];
1000 }else if(type == "grass"){
1001 ObjSprite.call(this,64,64);
1002 this.image = game.assets[EResPath.GRASS];
1009 foodGroup.addChild(this);
1010 this.addEventListener('enterframe', function(){
1011 if(this.amount <= 0){
1016 getAmount: function(){
1019 getGive: function(){
1023 var Place = enchant.Class.create(ObjSprite,{
1024 initialize: function (type, x, y){
1025 ObjSprite.call(this,128,128);
1026 this.image = game.assets[EResPath.PLACE_TREE];
1027 this.x = x - this.width / 2;
1028 this.y = y - this.height / 2;
1029 backgroundMap.addChild(this);
1031 this.foodsGraet = 0;
1032 this.foodsNormal = 0;
1034 // this.addEventListener('enterframe', function(){
1035 // if(this.age%10 === 0 && this.age !== 0){
1036 // console.log("x/y " + this.x + "/" + this.y);
1038 // if(game.input.left){
1041 // if(game.input.right){
1044 // if(game.input.up){
1047 // if(game.input.down){
1052 getStatusForDisplay: function(){
1055 if(this.owner == null)ownerId = "なし";
1056 else ownerId = this.owner.id;
1057 ret += "プレイスID " + this.id + "\n";
1058 ret += "オーナーID " + ownerId + "\n";
1059 ret += "食料うめぇ " + this.foodsGraet + "\n";
1060 ret += "食料それなりー " + this.foodsNormal + "\n";
1061 ret += "食料にがにが " + this.foodsBad + "\n";
1064 setOwner: function(yukkuri){
1065 this.owner = yukkuri;
1067 isOwner: function(){
1068 return this.owner !== null;
1071 var Unun = enchant.Class.create(ObjSprite,{
1072 initialize: function (x, y){
1073 this.classname = "Unun";
1074 ObjSprite.call(this,32,32);
1075 this.image = game.assets[EResPath.YUKKURI_UNUN];
1078 backgroundMap.addChild(this);
1081 var Okazari = enchant.Class.create(enchant.Sprite,{
1082 initialize: function(){
1083 this.classname = "Okazari";
1084 enchant.Sprite.call(this, 64, 64);
1085 this.image = game.assets[EResPath.OKAZARI];
1086 this.x = -CHARA_WIDTH / 2;
1087 this.y = -12 - CHARA_HEIGHT / 2;
1090 var Address = enchant.Class.create({
1091 initialize: function(yukkuri){
1092 this.friendlyLv = 1;
1093 this.yukkuri = yukkuri;
1094 this.isGreeting = false;
1095 this.greetingWaitFrame = 0;
1097 "beginSayHello" : false,
1102 set:function(key, value){
1103 this.comMatrix[key] = value;
1106 return this.comMatrix[key];
1110 var Yukkuri = enchant.Class.create(ObjSprite,{
1111 initialize: function(x, y){
1112 ObjSprite.call(this, 64, 64);
1113 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1114 this.classname = "Yukkuri";
1115 this.addressBook = {};
1116 this.imgGroup = new SpriteGroup();
1117 this.imgBody = new SpriteGroup();
1118 this.imgGroup.id = guid();
1119 this.imgBody.id = guid();
1120 this.x = -CHARA_WIDTH / 2;
1121 this.y = -CHARA_HEIGHT / 2;
1124 this.image = game.assets[EResPath.YUKKURI_BASE];
1125 this.direction = EDirection.RIGHT;
1126 this.addEventListener('enterframe', this.runEnterframe);
1127 this.bodyStatus ={};
1128 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1129 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1130 this.walkAnimationStatus = EWalkAnimation.END;
1133 runEnterframe:function(){
1134 // this.imgGroup.x = 0;
1137 if(this.isDead())return;
1145 if(this.direction == EDirection.RIGHT){
1146 this.imgBody.scaleX = 1;
1148 else if(this.direction == EDirection.LEFT){
1149 this.imgBody.scaleX = -1;
1152 tweet:function(text){
1153 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1155 moveTo:function(x, y, time){
1156 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1158 moveBy:function(x, y, time, eventFunctions){
1162 return self.imgGroup.x + x;
1165 return self.imgGroup.y + y;
1168 easing: enchant.Easing.SIN_EASEINOUT
1170 //-Event register [onactionstart,onactiontick,onactionend]
1171 if(eventFunctions !== undefined){
1172 for(var key in eventFunctions){
1173 params[key] = eventFunctions[key];
1176 return this.imgGroup.tl.tween(params);
1178 wait:function(frame, eventFunctions){
1179 this.moveBy(0,1,frame,eventFunctions);
1184 animation: function(){
1185 if(this.walkAnimationStatus == EWalkAnimation.END){
1187 this.imgBody.tl.moveByEx(0, -5, 10, enchant.Easing.SWING, {
1188 "onactionstart": function(e){
1189 this.walkAnimationStatus = EWalkAnimation.START;
1192 .moveByEx(0, 5, 10, enchant.Easing.SWING,
1194 "onactionend": function(e){
1195 this.walkAnimationStatus = EWalkAnimation.END;
1200 this.imgBody.tl.loop();
1203 getWidth: function(){
1206 getHeight: function(){
1210 return this.imgGroup.x;
1213 return this.imgGroup.y;
1216 this.imgGroup.x += x;
1218 // this.shadow.x += x;
1219 // this._tweet.x += x;
1222 this.imgGroup.y += y;
1224 // this.shadow.y += y;
1225 // this._tweet.y += y;
1227 // changeFace: function(erespath){
1228 // this.face.image = game.assets[erespath];
1230 loadParamsXML: function(url){
1231 var http = new JKL.ParseXML( url );
1232 return http.parse();
1234 runYukkuri: function(){
1235 if(this.param.hungry > 70){
1236 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1237 this.param.yukkuri -= 1;
1240 else if(this.param.hungry < 10){
1241 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1244 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1245 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1247 runHungry: function(){
1248 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1249 if(this.param.hungry >= 100)this.param.hungry = 100;
1251 runUnun: function(){
1252 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1253 if(this.param.unun >= 100)this.param.unun = 100;
1255 runSleep: function(){
1256 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1257 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1258 if(this.param.sleep >= 100){
1259 this.param.sleep = 100;
1263 runAddress: function(){
1264 for(var key in this.addressBook){
1265 var address = this.addressBook[key];
1267 if(address.isGreeting){
1268 address.greetingWaitFrame++;
1269 if(address.greetingWaitFrame >= DAY){
1270 address.greetingWaitFrame = 0;
1271 address.isGreeting = false;
1276 changeFace: function(){
1277 if(this.param.yukkuri >= 80){
1278 this.setFaceImage(EFace.HAPPY1);
1280 else if(this.param.yukkuri >= 50){
1281 this.setFaceImage(EFace.NORMAL);
1283 else if(this.param.yukkuri >= 30){
1284 this.setFaceImage(EFace.TIRED);
1286 else if(this.param.yukkuri >= 10){
1287 this.setFaceImage(EFace.CRY1);
1289 else if(this.param.yukkuri >= 1){
1290 this.setFaceImage(EFace.CRY2);
1293 getRange: function(){
1294 return this.param.range;
1296 isSleep: function(){
1297 return this.param.sleep >= 100;
1300 return this.param.yukkuri <= 0;
1302 isManpuku: function(){
1303 return this.param.hungry <= 20;
1305 isKuhuku: function(){
1306 return this.param.hungry >= 40;
1308 getYukkuri: function(){
1309 return this.param.yukkuri;
1311 setYukkuri: function(yukkuri){
1312 this.param.yukkuri = yukkuri;
1313 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1315 getHungry: function(){
1316 return this.param.hungry;
1318 setHungry: function(hungry){
1319 this.param.hungry = hungry;
1320 if(this.param.hungry < 0)this.param.hungry = 0;
1322 getUnun: function(){
1323 return this.param.unun;
1325 setUnun: function(unun){
1326 this.param.unun = unun;
1327 if(this.param.unun < 0)this.param.unun = 0;
1331 if(food.amount > 0){
1333 this.setHungry(this.param.hungry - food.getGive());
1334 this.setUnun(this.getUnun() + food.getGive() / 4);
1335 this.setYukkuri(this.getYukkuri() + 5);
1338 this.setYukkuri(this.getYukkuri() - 5);
1342 declarePlace: function(place){
1345 isPlace: function(){
1346 return this.place !== null;
1350 if(this.direction == EDirection.RIGHT){
1351 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1353 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1357 setBodyImage: function(ebody){
1358 var path = this.bodyStatus[ebody];
1359 this.image = game.assets[path];
1362 // this.imgBody.tl.pause();
1363 // this.imgGroup.tl.pause();
1364 this.imgBody.tl.unloop();
1365 this.imgGroup.tl.unloop();
1367 tlResume: function(){
1368 // this.imgBody.tl.resume();
1369 // this.imgGroup.tl.resume();
1372 syncDirection:function(senderYukkuri){
1373 if(this.getX() > senderYukkuri.getX()){
1374 this.direction = EDirection.LEFT;
1375 senderYukkuri.direction = EDirection.RIGHT;
1377 this.direction = EDirection.RIGHT;
1378 senderYukkuri.direction = EDirection.LEFT;
1381 isCommunication: function(yukkuri){
1382 if(this.addressBook[yukkuri.id] === undefined) return true;
1383 if(this.addressBook[yukkuri.id].isGreeting) return false;
1386 addAddress: function(yukkuri){
1387 this.addressBook[yukkuri.id] = new Address(yukkuri);
1389 getAddress: function(yukkuri){
1390 if(this.addressBook[yukkuri.id] === undefined)return null;
1391 return this.addressBook[yukkuri.id];
1393 getStatusForDisplay: function (){
1395 var placeId = (this.place==null)?"無し" : this.place.id;
1396 ret += "ID " + this.id + "\n";
1397 ret += "プレイス " + placeId + "\n";
1400 destruct: function(){
1404 var Marisa = enchant.Class.create(Yukkuri,{
1405 initialize: function(x, y){
1406 Yukkuri.call(this,x,y);
1407 this.classname = "Marisa";
1409 // var xml = this.loadParamsXML("./data/marisa/params.xml");
1410 var json = net.load("./data/marisa/params.json");
1411 this.param = json.root.param;
1412 this.shadow = new enchant.Sprite(64, 64);
1413 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
1414 this.shadow.x = 0 + this.x;
1415 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
1416 this.shadow.image._element.style.zIndex = 2;
1418 this._style.zIndex = 5;
1420 this.face = new enchant.Sprite(64, 64);
1421 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
1422 this.face.x = -CHARA_WIDTH / 2;
1423 this.face.y = -CHARA_HEIGHT / 2;
1424 this.face._style.zIndex = 0;
1426 this.faceStatus ={};
1427 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
1428 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
1429 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
1430 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
1431 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
1432 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
1433 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
1434 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
1435 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
1436 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
1439 this.hear = new enchant.Sprite(64, 64);
1440 this.hear.image = game.assets[EResPath.MARISA_HEAR];
1441 this.hear.x = -CHARA_WIDTH / 2;
1442 this.hear.y = -CHARA_HEIGHT / 2;
1443 this.hear._style.zIndex = 0;
1445 this.okazari = new Okazari();
1446 this.okazari.image._element.style.zIndex = 1;
1448 // this.imgGroup._style.zIndex = 1;
1450 this.imgGroup.addChild(this.shadow);
1451 this.imgBody.addChild(this);
1452 this.imgBody.addChild(this.face);
1453 this.imgBody.addChild(this.hear);
1454 this.imgBody.addChild(this.okazari);
1455 this.imgGroup.addChild(this.imgBody);
1456 backgroundMap.addChild(this.imgGroup);
1457 this._tweet = new TTweet(148, 64);
1459 this.imgGroup.addChild(this._tweet);
1460 this.imgGroup.x = x;
1461 this.imgGroup.y = y;
1463 this.action = new Action(this);
1466 setFaceImage: function(eface){
1467 var path = this.faceStatus[eface];
1468 this.face.image = game.assets[path];
1471 var Player = enchant.Class.create(Marisa,{
1472 initialize: function(x, y){
1473 // this.runEnterframe = function(){
1475 Marisa.call(this, x, y);
1476 this.classname = "Player";
1477 ctl.setPlayer(this);
1478 // this.removeEventListener('enterframe',this.runEnterframe);
1479 this.addEventListener('enterframe', function(){
1482 if(this.age%10 === 0 && this.age !== 0){
1483 // console.log("palyer:" + this.age);
1486 ///////////////////////////////////////////////
1487 //Action pattern debug
1488 if(game.input.left){
1489 // this.changeFace(EResPath.MARISA_FACE_TIRED);
1491 this.direction = EDirection.LEFT;
1493 if(game.input.right){
1495 this.direction = EDirection.RIGHT;
1500 if(game.input.down){
1503 ///////////////////////////////////////////////
1505 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
1506 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
1508 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
1510 //- Display the circle of search range.
1511 // fieldBg.image.clear();
1512 // fieldBg.image.context.beginPath();
1513 // fieldBg.image.context.fillStyle = '#ff0000';
1514 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
1515 // fieldBg.image.context.fill();
1519 game.onload = function(){
1522 def.ObjSprite = ObjSprite;
1523 def.Yukkuri = Yukkuri;
1524 def.nodeSort = nodeSort;
1525 mangTouch = new MangTouch(ctl);
1526 mangMsg = new MangMsg(ctl);
1527 ctl.setDefined(def);
1528 backgroundMap.image = game.assets[EResPath.MAP0];
1529 backgroundMap.loadData(_mapData);
1530 backgroundMap.collisionData = _collisionData;
1532 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
1533 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1534 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
1535 fieldBg.image = fieldSurface;
1539 windowFront.image = windowSurface;
1542 windowFront.opacity = 0.5;
1544 windowSurface.context.fillStyle = '#000';
1545 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
1548 menuSurface.context.fillStyle = '#000';
1549 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
1550 menuBg.image = menuSurface;
1551 menuBg.x = EMenuPos.X;
1552 menuBg.y = EMenuPos.Y;
1553 backgroundMap.addChild(fieldBg);
1554 mangIcon = new MangIcon(ctl, menuBg);
1556 game.rootScene.addChild(backgroundMap);
1557 game.rootScene.addChild(windowFront);
1558 game.rootScene.addChild(menuBg);
1560 // var labelGroup = new LabelGroup();
1561 mangLabel = new MangLabel(ctl, menuBg);
1562 // var info = new Label("ゆっくり");
1563 // info.color = "#ffffff";
1564 // info.font = "14px 'Times New Roman'";
1566 // info.y = GAME_HEIGHT / 2;
1567 // labelGroup.addChild(info);
1568 // menuBg.addChild(labelGroup);
1571 // var food = new def.Food("apple", 200, 250);
1572 backgroundMap.addChild(foodGroup);
1573 // backgroundMap.addChild(placeGroup);
1574 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
1575 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200);
1576 new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
1579 game.rootScene.addEventListener('touchstart', function (e) {
1580 game.touched = true;
1581 var mang = mangTouch.get(ctl.getCurrentCommand());
1584 game.rootScene.addEventListener('touchmove', function (e) {
1585 var mang = mangTouch.get(ctl.getCurrentCommand());
1588 game.rootScene.addEventListener('touchend', function (e) {
1589 var mang = mangTouch.get(ctl.getCurrentCommand());
1591 game.touched = false;
1595 game.rootScene.addEventListener('enterframe', function(){
1597 mangLabel.draw(player);
1599 this.addEventListener('enterframe', function(){
1600 //The priority processing of display instead of z-index
1601 backgroundMap.childNodes.sort(nodeSort
1603 // if(typeof a.id === "undefined" && typeof b.id === "undefined"){
1606 // else if(typeof a.id === "undefined"){
1609 // else if(typeof b.id === "undefined"){
1614 // if(a instanceof Box && b instanceof Box){
1617 // if(a instanceof Box){
1620 // if(b instanceof Box){
1624 // if(a instanceof Place){
1625 // ay += Math.round(a.height * 0.7);
1627 // if(b instanceof Place){
1628 // by += Math.round(b.height * 0.7);
1631 // if(ay < by)return -1;
1632 // else if(ay > by)return 1;
1633 // if(a.id < b.id)return -1;
1634 // else if(a.id > b.id)return 1;