2 //////////////////////////////////////
4 CanvasLayer初期化後にcanvasのコンテキストを操作する
6 // var initCanvas = CanvasLayer.prototype.initialize;
8 // CanvasLayer.prototype.initialize = function() {
9 // initCanvas.call(this);
10 // console.log("canvas");
12 // // 拡大時の処理をNearest Neighbor方式に切り替え
13 // // ただしChromeとFireFoxでのみ動作
14 // this.context.imageSmoothingEnabled = false;
15 // this.context.webkitImageSmoothingEnabled = false;
16 // this.context.mozImageSmoothingEnabled = false;
24 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
26 //////////////////////////////////////
28 //////////////////////////////////////
29 var PALYER_INIT_X = 100;
30 var PALYER_INIT_Y = 100;
32 var CHARA_HEIGHT = 64;
34 var GAME_HEIGHT = 600;
40 // var DAY = HOUR * 24;
42 var GAME_START_TIME = HOUR * 6;
45 YUKKURI_BASE : './data/yukkuri_base.png',
46 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
47 YUKKURI_UNUN : './data/unun.png',
48 YUKKURI_SHADOW : './data/shadow.png',
49 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
50 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
51 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
52 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
53 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
54 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
55 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
56 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
57 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
58 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
59 MARISA_HEAR : './data/marisa/hear1.png',
60 OBJECT : './data/object.png',
61 MAP0 : './data/map0.png',
62 COMMAND : './data/command.png',
63 OKAZARI : './data/okazari.png',
64 PLACE_TREE : './data/system/place_tree.png',
65 GRASS : './data/system/grass.png',
66 PLAYER_BADGE : './data/system/player_badge.png',
67 // PLACE_TREE : './data/system/rapture.png',
73 FACE_NORMAL : './data/reimu/face_normal1.png',
74 FACE_TIRED : './data/reimu/face_tired1.png',
75 FACE_ANGRY : './data/reimu/face_angry1.png',
76 FACE_CRY1 : './data/reimu/face_cry1.png',
77 FACE_CRY2 : './data/reimu/face_cry2.png',
78 FACE_EAT1 : './data/reimu/face_eat1.png',
79 FACE_EAT2 : './data/reimu/face_eat2.png',
80 FACE_HAPPY1 : './data/reimu/face_happy1.png',
81 FACE_HAPPY2 : './data/reimu/face_happy2.png',
82 FACE_SLEEP : './data/reimu/face_sleep1.png',
83 HEAR : './data/reimu/hear1.png',
84 OKAZARI : './data/reimu/okazari.png',
85 SUB1 : './data/reimu/sub1.png',
117 HEIGHT : GAME_HEIGHT,
122 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
133 MOVE_TO_EAT_START: 10,
134 MOVE_TO_EAT_UNDERWAY: 11,
138 UNUN_SMELL_START : 15,
139 UNUN_SMELL_WAIT : 16,
142 COMMUNICATE_START : 19,
143 COMMUNICATE_WAIT: 20,
144 COMMUNICATE_RECV: 21,
145 MOVE_TO_PLACE_START_HOMELESS: 22,
146 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
147 DECLARE_PLACE_HOMELESS: 24,
148 MOVE_TO_HUNT_START: 25,
182 var EWalkAnimation = {
211 var ObjSprite = enchant.Class.create(enchant.Sprite,{
212 initialize: function (w, h){
213 enchant.Sprite.call(this, w, h);
218 // // new BoxLabel(this.ctl,100, e.x, e.y);
219 // var box = new Box(this.ctl, 200, 200);
221 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
224 getStatusForDisplay: function (){
233 getWidth: function(){
236 getHeight: function(){
239 removeAll: function(){
246 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
257 //-Event register [onactionstart,onactiontick,onactionend]
258 if(eventFunctions !== undefined){
259 for(var key in eventFunctions){
260 params[key] = eventFunctions[key];
263 return this.tween(params);
265 function plusFrameScale(frame, scale){
266 return (frame/2) * (1 - scale)
271 include("./lang/ja.js");
272 window.onload = function(){
273 var nodeSort = function (a, b){
274 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
277 else if(typeof a.id === "undefined"){
280 else if(typeof b.id === "undefined"){
285 if(a instanceof Box && b instanceof Box){
288 if(a instanceof Box){
291 if(b instanceof Box){
294 if(a instanceof SpriteGroup){
298 if(b instanceof SpriteGroup){
303 if(a instanceof Place){
304 ay += Math.round(a.height * 0.7);
306 if(b instanceof Place){
307 by += Math.round(b.height * 0.7);
310 if(ay < by)return -1;
311 else if(ay > by)return 1;
312 if(a.id < b.id)return -1;
313 else if(a.id > b.id)return 1;
319 var def = new Object();
320 var foodGroup = new Group();
321 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
322 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
323 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
324 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
325 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
329 var tmpName = EResPathReimu.getName();
331 for(var _v in EResPathReimu){
332 if(typeof EResPathReimu[_v] === "function")continue;
333 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
339 for(var _v in EResPath){
340 _loadArr[i] = EResPath[_v];
343 game.preload(_loadArr);
344 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
345 var backgroundMap = new MapGroup(16, 16);
346 include("./class.js");
347 include("./ctrl.js");
350 ctl.setBackgroundMap(backgroundMap);
351 var Action = enchant.Class.create({
352 initialize: function (yukkuri){
353 this.status = EAction.THINK;
354 this.yukkuri = yukkuri;
355 this.isMoving = false;
356 this.targetNode = null;
358 getStatus: function(){
361 setStatus: function(eaction){
362 this.status = eaction;
365 if(this.yukkuri.isDead()){
366 this.status = EAction.DEAD;
368 // else if(this.yukkuri.isSleep()){
369 // this.status = EAction.SLEEP;
379 if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
381 this.setStatus(EAction.THINK);
382 console.log("wait cnt end");
385 case EAction.THINK_IN_HOME:
388 this.think_in_home();
390 case EAction.EAT_IN_HOME:
395 if(this.yukkuri.age%2 === 0){
396 this.yukkuri.changeFace();
398 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
401 case EAction.MOVE_TO_EAT_START:
402 this.move_to_eat_start();
404 case EAction.MOVE_TO_EAT_UNDERWAY:
410 case EAction.SLEEP_START:
413 case EAction.SLEEP_WAIT:
418 case EAction.EAT_START:
421 case EAction.EAT_WAIT:
423 case EAction.UNUN_START:
426 case EAction.UNUN_WAIT:
428 case EAction.MOVE_TO_COMMAND:
429 this.move_to_command();
431 case EAction.UNUN_SMELL_START:
432 this.unun_smell_start();
434 case EAction.COMMUNICATE_START:
435 this.communicate_start();
437 case EAction.COMMUNICATE_WAIT:
439 case EAction.COMMUNICATE_RECV:
441 case EAction.MOVE_TO_PLACE_START_HOMELESS:
442 this.move_to_place_start_homeless();
444 case EAction.DECLARE_PLACE_HOMELESS:
445 this.declare_place_homeless();
447 case EAction.MOVE_TO_HUNT_START:
448 this.move_to_hunt_start();
450 case EAction.HUNT_START:
453 case EAction.MOVE_GOTO_HOME:
454 this.move_goto_home();
456 case EAction.IN_HOME:
461 this.yukkuri.reverse();
463 thinkHavePlace: function(){
464 var date = ctl.getDate();
465 if(this.yukkuri.isPlaceRange()){
468 if(date === EDate.EVENING
469 || date === EDate.NIGHT
470 || date === EDate.MIDNIGHT
472 this.setStatus(EAction.MOVE_GOTO_HOME);
475 else if(date === EDate.EVENING){
476 // if(this.yukkuri.isItemsMax()){
477 // this.setStatus(EAction.IN_HOME);
480 // this.setStatus(EAction.MOVE_TO_HUNT_START);
484 if(this.yukkuri.isVeryKuhuku()){
487 this.setStatus(EAction.MOVE_GOTO_HOME);
489 else if(this.yukkuri.isSleep()){
490 this.setStatus(EAction.SLEEP_START);
492 else if(this.yukkuri.getUnun() >= 80){
493 this.setStatus(EAction.UNUN_START);
496 this.yukkuri.changeFace();
500 think_in_home: function(){
501 var date = ctl.getDate();
502 if((date === EDate.MIDNIGHT)
503 && !this.yukkuri.isSleep()
504 && !this.yukkuri.isVeryKuhuku()
508 "nextStatus":EAction.THINK_IN_HOME,
509 "myYukkuri": this.yukkuri
513 else if(date === EDate.EVENING){
516 else if(this.yukkuri.isVeryKuhuku() && this.yukkuri.getPlace().isFood()){
517 this.setStatus(EAction.EAT_IN_HOME);
520 //marisa is hunting move
521 if(this.yukkuri.beforeHuntingFood !== null){
522 new MoveToHuntEvent({
524 "targetNode": this.yukkuri.beforeHuntingFood,
526 "myYukkuri": this.yukkuri
530 this.setStatus(EAction.WALK);
534 eat_in_home: function(){
536 "targetNode": this.yukkuri.getPlace(),
538 "myYukkuri": this.yukkuri
541 move_to_eat_start : function(){
544 "targetNode": this.targetNode,
546 "myYukkuri": this.yukkuri
552 walk : function(retryCounter){
553 if(retryCounter > 15){
555 this.status = EAction.NONE;
556 console.log("retryCount over");
559 if(this.yukkuri.imgGroup.tl.queue.length === 0){
561 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
563 this.isMoving = false;
564 this.status = EAction.THINK;
568 var xpos = 150 + rand(40) - (retryCounter * 10);
569 var ypos = 150 + rand(40) - (retryCounter * 10);
572 this.yukkuri.vy = -ypos;
574 else if(rand(8) == 1){
575 this.yukkuri.vx = xpos;
576 this.yukkuri.vy = -ypos;
577 this.yukkuri.direction = EDirection.RIGHT;
579 else if(rand(8) == 2){
580 this.yukkuri.vx = xpos;
582 this.yukkuri.direction = EDirection.RIGHT;
584 else if(rand(8) == 3){
585 this.yukkuri.vx = xpos;
586 this.yukkuri.vy = ypos;
587 this.yukkuri.direction = EDirection.RIGHT;
589 else if(rand(8) == 4){
591 this.yukkuri.vy = ypos;
593 else if(rand(8) == 5){
594 this.yukkuri.vx = -xpos;
595 this.yukkuri.vy = ypos;
596 this.yukkuri.direction = EDirection.LEFT;
598 else if(rand(8) == 6){
599 this.yukkuri.vx = -xpos;
601 this.yukkuri.direction = EDirection.LEFT;
603 else if(rand(8) == 7){
604 this.yukkuri.vx = -xpos;
605 this.yukkuri.vy = -ypos;
606 this.yukkuri.direction = EDirection.LEFT;
608 if (this.yukkuri.vx || this.yukkuri.vy) {
609 var map = ctl.backgroundMap;
610 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
611 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
612 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
613 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
614 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
615 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
616 // console.log("X:" + this.yukkuri.moveX);
617 // console.log("Y:" + this.yukkuri.moveY);
618 this.isMoving = true;
619 this.yukkuri.reverse();
620 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
621 mangMsg.output(this.yukkuri,EMsg.WALK);
623 this.targetNode = null;
625 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
626 this.walk(retryCounter+1);
632 sleep_start: function(){
635 "myYukkuri": this.yukkuri
639 mangMsg.output(this.yukkuri, EMsg.DEAD);
640 this.yukkuri.tlPause();
641 this.yukkuri.setBodyImage(EBody.DEAD);
643 eat_start: function(){
646 "targetNode": this.targetNode,
648 "myYukkuri": this.yukkuri
652 unun_start: function(){
655 "myYukkuri": this.yukkuri
658 unun_smell_start: function(){
661 "myYukkuri": this.yukkuri
664 communicate_start:function(){
665 new ComSayHelloSendEvent({
667 "targetNode": this.targetNode,
669 "myYukkuri": this.yukkuri
672 move_to_place_start_homeless:function(){
673 new MoveToPlaceStartHomelessEvent({
674 "targetNode": this.targetNode,
676 "myYukkuri": this.yukkuri
679 declare_place_homeless:function(){
680 new DeclarePlaceHomelessEvent({
681 "targetNode": this.targetNode,
683 "myYukkuri": this.yukkuri
686 move_to_hunt_start:function(){
687 new MoveToHuntEvent({
689 "targetNode": this.targetNode,
691 "myYukkuri": this.yukkuri
694 hunt_start:function(){
697 "targetNode": this.targetNode,
699 "myYukkuri": this.yukkuri
702 move_goto_home:function(){
703 var place = this.yukkuri.getPlace();
704 new MoveGotoHomeEvent({
708 "myYukkuri": this.yukkuri
712 var place = this.yukkuri.getPlace();
717 "myYukkuri": this.yukkuri
720 move_to_command: function(){
724 this.yukkuri.clearSearchObject();
725 var nodes = ctl.getObjs();
729 for (var key in nodes) {
730 var node = nodes[key];
731 if(this.yukkuri.id === node.id)continue;
735 && !(this.targetNode instanceof Unun)
736 && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
738 this.yukkuri.addSearchObject(ESearch.UNUN, node);
741 else if (node instanceof Food && node.amount > 0) {
742 if(this.yukkuri.within(node, this.yukkuri.getRange())){
743 this.yukkuri.addSearchObject(ESearch.FOOD, node);
747 else if(node instanceof Yukkuri){
748 if(this.yukkuri.within(node, this.yukkuri.getRange())){
749 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
753 else if(node instanceof Place){
754 if(this.yukkuri.within(node, this.yukkuri.getRange())){
755 this.yukkuri.addSearchObject(ESearch.PLACE, node);
759 this.status = EAction.WALK;
763 * Range範囲内のObjSprを管理する
764 * 注意!:ゆっくりプレイスを持って入るもののみ使用される
768 var SearchObjectMang = enchant.Class.create({
769 initialize: function (){
774 for(var key in ESearch){
775 var esearch = ESearch[key];
776 this.datas[esearch] = [];
779 add :function(esearch, node){
780 this.datas[esearch].push(node);
783 for(var key in ESearch){
784 var esearch = ESearch[key];
785 this.datas[esearch].length = 0;
787 // this.datas.length = 0;
790 get:function (esearch){
791 return this.datas[esearch];
793 getNear:function (esearch, yukkuri){
794 var objects = this.datas[esearch];
795 var nearDistance = null;
797 for(var i=0;i<objects.length;i++){
798 var object = objects[i];
799 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
800 if(nearDistance === null || nearDistance > nowDistance){
801 nearDistance = nowDistance;
807 callEvent: function(yukkuri){
808 if(yukkuri.isItemsMax() && yukkuri.isPlace()){
809 yukkuri.action.targetNode = yukkuri.getPlace();
810 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
813 if(yukkuri.isVeryKuhuku()){
815 var foods = this.get(ESearch.FOOD);
816 if(foods.length === 0 && yukkuri.isPlace()){
818 yukkuri.action.targetNode = yukkuri.getPlace();
819 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
822 var foods = this.get(ESearch.FOOD);
823 food = this.getNear(ESearch.FOOD, yukkuri);
825 yukkuri.action.targetNode = food;
826 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
832 if(yukkuri.isSleep()){
833 yukkuri.action.setStatus(EAction.SLEEP_START);
837 else if(yukkuri.getUnun() >= 80){
838 yukkuri.action.setStatus(EAction.UNUN_START);
843 if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
844 food = this.getNear(ESearch.FOOD, yukkuri);
846 yukkuri.action.targetNode = food;
847 yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
851 ununs = this.get(ESearch.UNUN);
852 if(ununs.length !== 0){
853 yukkuri.action.targetNode = yukkuri.getPlace();
854 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
857 var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
858 if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
859 yukkuri.action.targetNode = searchYukkuri;
860 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
863 if(!yukkuri.isPlace()){
864 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
865 if(searchYukkuri != null && !searchYukkuri.isOwner()){
866 yukkuri.action.targetNode = searchYukkuri;
867 yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
871 yukkuri.action.setStatus(EAction.WALK);
876 var Event = enchant.Class.create({
877 initialize: function (_data){
880 onactionstart:function(self){
881 return this._onactionstart;
883 _onactionstart:function(e){
884 if(typeof e === "undefined")return;
886 onactiontick:function(self){
888 if(typeof e === "undefined")return;
891 onactionend:function(self){
893 if(typeof e === "undefined")return;
897 var WalkEvent = enchant.Class.create(Event,{
898 initialize: function (_data){
900 this.yukkuri = _data.myYukkuri;
901 this.action = _data.action;
903 mangMsg.output(this.yukkuri, EMsg.SLEEP);
904 this.action.setStatus(EAction.SLEEP_WAIT);
905 this.yukkuri.setFaceImage(EFace.SLEEP);
906 this.yukkuri.tlPause();
908 this.yukkuri.addEventListener('enterframe', function() {
909 var yukkuri = self.yukkuri;
917 var SleepEvent = enchant.Class.create(Event,{
918 initialize: function (_data){
920 this.yukkuri = _data.myYukkuri;
921 this.action = _data.action;
923 mangMsg.output(this.yukkuri, EMsg.SLEEP);
924 this.action.setStatus(EAction.SLEEP_WAIT);
925 this.yukkuri.setFaceImage(EFace.SLEEP);
926 this.yukkuri.tlPause();
929 this.yukkuri.addEventListener('enterframe', function() {
930 var yukkuri = self.yukkuri;
931 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
932 if(yukkuri.param.sleep <= 0){
933 yukkuri.param.sleep = 0;
934 this.removeEventListener("enterframe",arguments.callee);
935 mangMsg.output(self.yukkuri, EMsg.GET_UP);
936 yukkuri.setFaceImage(EFace.NORMAL);
938 // self.action.setStatus(EAction.WAIT);
939 if(self.data.nextStatus !== undefined){
940 self.action.setStatus(self.data.nextStatus);
942 self.action.setStatus(EAction.THINK);
949 var UnunEvent = enchant.Class.create(Event,{
950 initialize: function (_data){
952 this.yukkuri = _data.myYukkuri;
953 this.action = _data.action;
954 this.action.setStatus(EAction.UNUN_WAIT);
955 mangMsg.output(this.yukkuri, EMsg.UNUN);
956 this.yukkuri.setFaceImage(EFace.HAPPY2);
959 this.yukkuri.wait(sec, {
960 "onactionend": this.onactionend(this)
963 onactionend:function(self){
965 if(typeof e === "undefined")return;
967 self.action.setStatus(EAction.WAIT);
968 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
970 "waitframe": FPS * 1.5,
971 "action": self.action,
972 "myYukkuri": self.yukkuri
977 var WaitEvent = enchant.Class.create(Event,{
978 initialize: function (_data){
980 this.yukkuri = _data.myYukkuri;
981 this.action = _data.action;
982 this.waitframe = _data.waitframe;
983 this.yukkuri.wait(this.waitframe, {
984 "onactionstart": this.onactionstart(this),
985 "onactiontick": this.onactiontick(this),
986 "onactionend": this.onactionend(this)
989 onactionend:function(self){
991 if(typeof e === "undefined")return;
992 self.action.setStatus(EAction.THINK);
996 var UnunSmellEvent = enchant.Class.create(Event,{
997 initialize: function (_data){
999 this.yukkuri = _data.myYukkuri;
1000 this.action = _data.action;
1001 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1002 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1003 this.yukkuri.setFaceImage(EFace.CRY1);
1005 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1006 this.yukkuri.wait(sec, {
1007 "onactionend": this.onactionend(this)
1010 onactionend:function(self){
1012 if(typeof e === "undefined")return;
1013 self.action.setStatus(EAction.WALK);
1018 var EatEvent = enchant.Class.create(Event,{
1019 initialize: function (_data){
1021 this.yukkuri = _data.myYukkuri;
1022 this.food = _data.targetNode;
1023 this.action = _data.action;
1024 this.action.setStatus(EAction.EAT_WAIT);
1027 var sec = BASE_FPS * 3;
1028 if(this.yukkuri.eat(this.food)){
1029 mangMsg.output(this.yukkuri, EMsg.EAT);
1030 this.yukkuri.setFaceImage(EFace.EAT2);
1033 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1034 this.yukkuri.setFaceImage(EFace.CRY2);
1036 this.yukkuri.wait(sec, {
1037 "onactionend": this.onactionend(this)
1040 onactionend:function(self){
1042 if(typeof e === "undefined")return;
1043 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1044 self.action.setStatus(EAction.THINK);
1045 self.yukkuri.setFaceImage(EFace.NORMAL);
1047 self.action.setStatus(EAction.EAT_START);
1054 * -When yukkuri find Food.
1057 * targetNode: enchant.Node
1061 var MoveToEatEvent = enchant.Class.create(Event,{
1062 initialize: function (_data){
1064 this.yukkuri = this.data.myYukkuri;
1065 this.action = this.data.action;
1067 var yukkuri = this.yukkuri;
1068 var node = this.data.targetNode;
1070 if(this.data.type == "food"){
1071 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1072 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1073 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1074 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1075 var frame = distance + distance/5 + 1;
1076 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1077 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1080 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1081 "onactionstart": this.onactionstart(this),
1082 "onactiontick": this.onactiontick(this),
1083 "onactionend": this.onactionend(this)
1087 onactionstart:function(self){
1089 if(typeof e === "undefined")return;
1090 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1093 onactiontick:function(self){
1095 if(typeof e === "undefined")return;
1098 onactionend:function(self){
1100 if(typeof e === "undefined")return;
1101 self.action.setStatus(EAction.EAT_START);
1105 var MoveToHuntEvent = enchant.Class.create(Event,{
1106 initialize: function (_data){
1108 this.yukkuri = this.data.myYukkuri;
1109 this.action = this.data.action;
1111 var yukkuri = this.yukkuri;
1112 var node = this.data.targetNode;
1115 var nodeWidth = node.width;
1116 var nodeHeight = node.height;
1120 if(this.data.type == "food"){
1121 this.action.setStatus(EAction.WAIT);
1122 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1123 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1124 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1125 var frame = distance + distance/5 + 1;
1126 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1127 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1129 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1131 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1132 "onactionend": this.onactionend(this)
1136 onactionend:function(self){
1138 if(typeof e === "undefined")return;
1139 self.action.setStatus(EAction.HUNT_START);
1143 var HuntStartEvent = enchant.Class.create(Event,{
1144 initialize: function (_data){
1145 Event.call(this, _data);
1148 this.yukkuri = _data.myYukkuri;
1149 this.food = _data.targetNode;
1150 this.action = _data.action;
1151 this.action.setStatus(EAction.WAIT);
1152 this.huntingStatus = "hunting";
1154 this.yukkuri.beforeHuntingFood = this.food;
1155 var sec = BASE_FPS * 8;
1156 if(this.yukkuri.hunt(this.food)){
1157 this.huntingStatus = "hunting";
1158 mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1159 this.yukkuri.setFaceImage(EFace.HAPPY1);
1161 if(this.yukkuri.isItemsMax()){
1163 this.huntingStatus = "return";
1164 // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1165 this.yukkuri.setFaceImage(EFace.NORMAL);
1168 this.huntingStatus = "cry";
1169 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1170 this.yukkuri.setFaceImage(EFace.CRY2);
1174 this.yukkuri.wait(sec, {
1175 "onactiontick": this.onactiontick(this),
1176 "onactionend": this.onactionend(this)
1179 onactiontick:function(self){
1181 if(typeof e === "undefined")return;
1183 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1184 if(this.age%(BASE_FPS * 3) == 0){
1185 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1186 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1191 onactionend:function(self){
1193 if(typeof e === "undefined")return;
1194 if(self.huntingStatus == "hunting"){
1195 if(self.yukkuri.isItemsMax()){
1196 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1197 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1199 self.action.setStatus(EAction.HUNT_START);
1202 else if(self.huntingStatus == "return"){
1203 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1205 else if(self.huntingStatus === "cry"){
1206 // self.action.setStatus(EAction.THINK);
1207 self.action.setStatus(EAction.WALK);
1214 this.yukkuri = null;
1219 var MoveGotoHomeEvent = enchant.Class.create(Event,{
1220 initialize: function (_data){
1222 this.yukkuri = this.data.myYukkuri;
1223 this.action = this.data.action;
1225 var yukkuri = this.yukkuri;
1226 var place = this.data.targetNode;
1228 if(this.data.type == "hunt_end"){
1229 this.action.setStatus(EAction.WAIT);
1230 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1231 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1232 // console.log("place.x:" + place.x);
1233 // console.log("place.y:" + place.y);
1234 // console.log("yukkuri.getX():" + yukkuri.getX());
1235 // console.log("yukkuri.getY():" + yukkuri.getY());
1236 // console.log("yukkuri.vx:" + yukkuri.vx);
1237 // console.log("yukkuri.vy:" + yukkuri.vy);
1238 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1239 var frame = distance + distance/2 + 1 ;
1240 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1241 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1243 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1245 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1246 "onactiontick": this.onactiontick(this),
1247 "onactionend": this.onactionend(this)
1251 onactiontick:function(self){
1253 if(typeof e === "undefined")return;
1254 if(this.age%(BASE_FPS * 5) == 0){
1255 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1259 onactionend:function(self){
1261 if(typeof e === "undefined")return;
1262 self.action.setStatus(EAction.IN_HOME);
1268 this.yukkuri = null;
1272 var InHomeEvent = enchant.Class.create(Event,{
1273 initialize: function (_data){
1275 this.yukkuri = this.data.myYukkuri;
1276 this.action = this.data.action;
1278 var yukkuri = this.yukkuri;
1279 var place = this.data.targetNode;
1280 if(yukkuri.isVeryKuhuku()){
1282 this.action.setStatus(EAction.EAT_IN_HOME);
1285 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1288 this.action.setStatus(EAction.WAIT);
1289 var items = this.yukkuri.getItems();
1290 if(items.length > 0){
1291 place.setItems(items);
1295 var sec = BASE_FPS * 10;
1296 this.yukkuri.wait(sec, {
1297 "onactiontick": this.onactiontick(this),
1298 "onactionend": this.onactionend(this)
1301 onactiontick:function(self){
1303 if(typeof e === "undefined")return;
1304 if(this.age%(BASE_FPS * 5) == 0){
1305 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1309 onactionend:function(self){
1311 if(typeof e === "undefined")return;
1312 self.action.setStatus(EAction.THINK);
1316 var EatInHomeEvent = enchant.Class.create(Event,{
1317 initialize: function (_data){
1319 this.yukkuri = _data.myYukkuri;
1320 this.place = _data.targetNode;
1321 this.action = _data.action;
1322 this.action.setStatus(EAction.EAT_WAIT);
1324 var sec = BASE_FPS * 3;
1325 var foodHash = this.place.getFoodHash();
1326 if(foodHash !== false && this.yukkuri.eat(foodHash)){
1327 mangMsg.output(this.yukkuri, EMsg.EAT);
1328 this.yukkuri.setFaceImage(EFace.EAT2);
1331 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1332 this.yukkuri.setFaceImage(EFace.CRY2);
1335 this.yukkuri.wait(sec, {
1336 "onactionend": this.onactionend(this)
1339 onactionend:function(self){
1341 if(typeof e === "undefined")return;
1342 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1343 self.action.setStatus(EAction.EAT_IN_HOME);
1345 // new EatInHomeEvent({
1346 // "targetNode": self.place,
1347 // "action": self.action,
1348 // "myYukkuri": self.yukkuri
1351 self.action.setStatus(EAction.THINK_IN_HOME);
1352 self.yukkuri.setFaceImage(EFace.NORMAL);
1359 var MoveCommandEvent = enchant.Class.create(Event,{
1360 initialize: function (_data){
1362 this.yukkuri = this.data.myYukkuri;
1363 this.action = this.data.action;
1364 this.vx = this.data.vx;
1365 this.vy = this.data.vy;
1367 var yukkuri = this.yukkuri;
1368 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1369 yukkuri.vx = node.x - yukkuri.getX();
1370 yukkuri.vy = node.y - yukkuri.getY();
1371 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1372 var frame = distance + 1;
1373 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1375 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1376 "onactionstart": this.onactionstart(this),
1377 "onactiontick": this.onactiontick(this),
1378 "onactionend": this.onactionend(this)
1381 onactionstart:function(self){
1383 if(typeof e === "undefined")return;
1386 onactiontick:function(self){
1388 if(typeof e === "undefined")return;
1391 onactionend:function(self){
1393 if(typeof e === "undefined")return;
1394 self.action.setStatus(EAction.THINK);
1399 * Say hello contact to send communication .
1401 var ComSayHelloSendEvent = enchant.Class.create(Event,{
1402 initialize: function (_data){
1404 this.yukkuri = _data.myYukkuri;
1405 this.targetYukkuri = _data.targetNode;
1406 this.action = _data.action;
1407 this.action.setStatus(EAction.COMMUNICATE_WAIT);
1408 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1410 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1411 this.targetYukkuri.tlPause();
1412 this.yukkuri.tlPause();
1413 this.yukkuri.syncDirection(this.targetYukkuri);
1415 this.yukkuri.addAddress(this.targetYukkuri);
1416 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1418 var sec = BASE_FPS * 2;
1419 this.yukkuri.wait(sec, {
1420 "onactiontick": this.onactiontick(this),
1421 "onactionend": this.onactionend(this)
1424 onactiontick:function(self){
1426 if(typeof e === "undefined")return;
1429 onactionend:function(self){
1431 if(typeof e === "undefined")return;
1432 new ComSayHelloRecvEvent({
1434 "targetNode": self.yukkuri,
1435 "action": self.targetYukkuri.action,
1436 "myYukkuri": self.targetYukkuri
1441 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1442 initialize: function (_data){
1444 this.yukkuri = _data.myYukkuri;
1445 this.targetYukkuri = _data.targetNode;
1446 this.action = _data.action;
1447 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1448 this.yukkuri.addAddress(this.targetYukkuri);
1449 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1451 var sec = BASE_FPS * 2;
1452 this.yukkuri.wait(sec, {
1453 "onactiontick": this.onactiontick(this),
1454 "onactionend": this.onactionend(this)
1457 onactiontick:function(self){
1459 if(typeof e === "undefined")return;
1462 onactionend:function(self){
1464 if(typeof e === "undefined")return;
1465 self.action.setStatus(EAction.THINK);
1467 self.yukkuri.action.setStatus(EAction.THINK);
1468 self.yukkuri.animation();
1469 self.targetYukkuri.action.setStatus(EAction.THINK);
1470 self.targetYukkuri.animation();
1474 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1475 initialize: function (_data){
1477 this.yukkuri = this.data.myYukkuri;
1478 this.action = this.data.action;
1480 var yukkuri = this.yukkuri;
1481 var node = this.data.targetNode;
1483 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1484 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
1485 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1486 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1487 var frame = distance + distance/5 + 1;
1488 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1490 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1493 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1494 "onactionend": this.onactionend(this)
1497 onactionend:function(self){
1499 if(typeof e === "undefined")return;
1500 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1502 self.yukkuri = null;
1507 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1508 initialize: function (_data){
1510 this.yukkuri = _data.myYukkuri;
1511 this.place = _data.targetNode;
1512 this.action = _data.action;
1513 this.action.setStatus(EAction.WAIT);
1516 var sec = BASE_FPS * 3;
1517 this.yukkuri.declarePlace(this.place);
1518 this.place.setOwner(this.yukkuri);
1519 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1521 this.yukkuri.setFaceImage(EFace.NORMAL);
1522 this.yukkuri.wait(sec, {
1523 "onactionend": this.onactionend(this)
1526 onactionend:function(self){
1528 if(typeof e === "undefined")return;
1529 self.action.setStatus(EAction.THINK);
1534 var Food = enchant.Class.create(ObjSprite,{
1535 initialize: function (type, x, y){
1536 this.classname = "Food";
1537 //一つにつきgiveの値分、hunguryを減少させられる
1538 if(type == "apple"){
1539 ObjSprite.call(this,16,16);
1540 this.image = game.assets[EResPath.OBJECT];
1544 }else if(type == "grass"){
1545 ObjSprite.call(this,64,64);
1546 this.image = game.assets[EResPath.GRASS];
1553 foodGroup.addChild(this);
1554 this.addEventListener('enterframe', function(){
1555 if(this.amount <= 0){
1560 getAmount: function(){
1563 getGive: function(){
1567 var Place = enchant.Class.create(ObjSprite,{
1568 initialize: function (type, x, y){
1569 ObjSprite.call(this,128,128);
1570 this.image = game.assets[EResPath.PLACE_TREE];
1571 this.x = x - this.width / 2;
1572 this.y = y - this.height / 2;
1573 backgroundMap.addChild(this);
1576 for(var key in EFood){
1577 var efood = EFood[key];
1578 this.foods[efood] = 0;
1580 // this.addEventListener('enterframe', function(){
1581 // if(this.age%10 === 0 && this.age !== 0){
1582 // console.log("x/y " + this.x + "/" + this.y);
1584 // if(game.input.left){
1587 // if(game.input.right){
1590 // if(game.input.up){
1593 // if(game.input.down){
1598 getStatusForDisplay: function(){
1601 if(this.owner == null)ownerId = "なし";
1602 else ownerId = this.owner.id;
1603 ret += "プレイスID " + this.id + "\n";
1604 ret += "オーナーID " + ownerId + "\n";
1605 ret += "食料うめぇ " + this.foods[EFood.GREAT] + "\n";
1606 ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1607 ret += "食料にがにが " + this.foods[EFood.BAD] + "\n";
1610 setItems:function(items){
1611 var len = items.length;
1612 for(var i=0; i<len; i++){
1613 var item = items[i];
1614 if(item instanceof Food){
1615 this.foods[EFood.NORMAL]++;
1622 for(var key in EFood){
1623 var efood = EFood[key];
1624 ret += this.foods[efood];
1628 getFoodHash:function(){
1629 if(this.foods[EFood.GREAT] !== 0){
1630 this.foods[EFood.GREAT]--;
1631 return {give:20,yukkuri:15,unun:20};
1633 else if(this.foods[EFood.NORMAL] !== 0){
1634 this.foods[EFood.NORMAL]--;
1635 return {give:10,yukkuri:5,unun:10};
1637 else if(this.foods[EFood.BAD] !== 0){
1638 this.foods[EFood.BAD]--;
1639 return {give:10,yukkuri:-2,unun:10};
1643 setOwner: function(yukkuri){
1644 this.owner = yukkuri;
1646 isOwner: function(){
1647 return this.owner !== null;
1650 var Unun = enchant.Class.create(ObjSprite,{
1651 initialize: function (x, y){
1652 this.classname = "Unun";
1653 ObjSprite.call(this,32,32);
1654 this.image = game.assets[EResPath.YUKKURI_UNUN];
1657 backgroundMap.addChild(this);
1658 this.lifetime = 30 * 24 * 3;
1659 this.addEventListener('enterframe', this.runEnterframe(this));
1660 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1663 runEnterframe:function(self){
1665 if(typeof e === "undefined")return;
1666 if(this.age%BASE_FPS === 0 && this.age !== 0){
1668 if(self.lifetime <= 0){
1669 this.parentNode.removeChild(this);
1670 ctl.backgroundMap.removeChild(this);
1671 ctl.removeObj(this);
1678 // runEnterframe: function(){
1679 // console.log("enterframe:" + this.id);
1682 var Okazari = enchant.Class.create(enchant.Sprite,{
1683 initialize: function(yukkuri){
1684 this.classname = "Okazari";
1685 if(yukkuri.myCode === "REIMU"){
1686 enchant.Sprite.call(this, 80, 32);
1687 this.image = game.assets[EResPathReimu.OKAZARI];
1688 this.x = -CHARA_WIDTH / 2;
1691 enchant.Sprite.call(this, 64, 64);
1692 this.image = game.assets[EResPath.OKAZARI];
1693 this.x = -CHARA_WIDTH / 2;
1694 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1696 this.yukkuri = yukkuri;
1698 getWidth: function(){
1700 // return this.width * this.yukkuri.myScaleX;
1702 getHeight: function(){
1704 // return this.height * this.yukkuri.myScaleY;
1707 var Address = enchant.Class.create({
1708 initialize: function(yukkuri){
1709 this.friendlyLv = 1;
1710 this.yukkuri = yukkuri;
1711 this.isGreeting = false;
1712 this.greetingWaitFrame = 0;
1714 "beginSayHello" : false,
1719 set:function(key, value){
1720 this.comMatrix[key] = value;
1723 return this.comMatrix[key];
1727 var Yukkuri = enchant.Class.create(ObjSprite,{
1728 initialize: function(x, y, grow){
1729 ObjSprite.call(this, 64, 64);
1730 this.searchObjectMang = new SearchObjectMang();
1732 this.myCode = "YUKKURI";
1733 this.myName = "ゆっくり";
1734 this.beforeHuntingFood = null;
1735 if(grow == EGrow.ADULT){
1740 else if(grow == EGrow.SUBADULT){
1741 this.myScaleX = 0.8;
1742 this.myScaleY = 0.8;
1745 else if(grow == EGrow.CHILD){
1746 this.myScaleX = 0.6;
1747 this.myScaleY = 0.6;
1750 else if(grow == EGrow.BABY){
1751 this.myScaleX = 0.3;
1752 this.myScaleY = 0.3;
1756 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1757 this.classname = "Yukkuri";
1758 this.addressBook = {};
1759 this.imgGroup = new SpriteGroup();
1760 this.imgBody = new SpriteGroup();
1761 this.imgGroup.id = guid();
1762 this.imgBody.id = guid();
1763 this.x = -CHARA_WIDTH / 2;
1764 this.y = -CHARA_HEIGHT / 2;
1767 this.image = game.assets[EResPath.YUKKURI_BASE];
1768 this.direction = EDirection.RIGHT;
1769 this.addEventListener('enterframe', this.runEnterframe);
1770 this.bodyStatus ={};
1771 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1772 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1773 this.walkAnimationStatus = EWalkAnimation.END;
1776 this.actionQueue = [];
1778 runEnterframe:function(){
1781 if(this.isDead())return;
1792 if(this.direction == EDirection.RIGHT){
1793 this.imgBody.scaleX = 1;
1795 else if(this.direction == EDirection.LEFT){
1796 this.imgBody.scaleX = -1;
1799 tweet:function(text){
1800 text = text.replace(/%name%/g, this.myName);
1801 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1803 moveTo:function(x, y, time){
1804 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1806 moveBy:function(x, y, time, eventFunctions){
1810 return self.imgGroup.x + x;
1813 return self.imgGroup.y + y;
1816 easing: enchant.Easing.SIN_EASEINOUT
1818 //-Event register [onactionstart,onactiontick,onactionend]
1819 if(eventFunctions !== undefined){
1820 for(var key in eventFunctions){
1821 params[key] = eventFunctions[key];
1824 return this.imgGroup.tl.tween(params);
1826 wait:function(frame, eventFunctions){
1827 this.moveBy(0,1,frame,eventFunctions);
1832 animation: function(){
1835 frame += plusFrameScale(frame, this.getMyScale());
1837 move -= plusFrameScale(move, this.getMyScale());
1838 if(this.walkAnimationStatus == EWalkAnimation.END){
1840 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1841 "onactionstart": function(e){
1842 this.walkAnimationStatus = EWalkAnimation.START;
1845 .moveByEx(0, move, frame, enchant.Easing.SWING,
1847 "onactionend": function(e){
1848 this.walkAnimationStatus = EWalkAnimation.END;
1853 this.imgBody.tl.loop();
1856 getMyScale: function(){
1857 return (this.myScaleX + this.myScaleY) / 2;
1859 getWidth: function(){
1860 return this.width * this.myScaleX;
1862 getHeight: function(){
1863 return this.height * this.myScaleY;
1866 return this.imgGroup.x;
1869 return this.imgGroup.y;
1872 this.imgGroup.x += x;
1874 // this.shadow.x += x;
1875 // this._tweet.x += x;
1878 this.imgGroup.y += y;
1880 // this.shadow.y += y;
1881 // this._tweet.y += y;
1883 // changeFace: function(erespath){
1884 // this.face.image = game.assets[erespath];
1886 loadParamsXML: function(url){
1887 var http = new JKL.ParseXML( url );
1888 return http.parse();
1890 runYukkuri: function(){
1891 if(this.param.hungry > 70){
1892 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1893 this.param.yukkuri -= 1;
1896 else if(this.param.hungry < 10){
1897 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1900 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1901 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1903 runHungry: function(){
1904 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1905 if(this.param.hungry >= 100)this.param.hungry = 100;
1907 runUnun: function(){
1908 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1909 if(this.param.unun >= 100)this.param.unun = 100;
1911 runSleep: function(){
1912 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1913 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1914 if(this.param.sleep >= 100){
1915 this.param.sleep = 100;
1919 runAddress: function(){
1920 for(var key in this.addressBook){
1921 var address = this.addressBook[key];
1923 if(address.isGreeting){
1924 address.greetingWaitFrame++;
1925 if(address.greetingWaitFrame >= DAY){
1926 address.greetingWaitFrame = 0;
1927 address.isGreeting = false;
1932 changeFace: function(){
1933 if(this.param.yukkuri >= 80){
1934 this.setFaceImage(EFace.HAPPY1);
1936 else if(this.param.yukkuri >= 50){
1937 this.setFaceImage(EFace.NORMAL);
1939 else if(this.param.yukkuri >= 30){
1940 this.setFaceImage(EFace.TIRED);
1942 else if(this.param.yukkuri >= 10){
1943 this.setFaceImage(EFace.CRY1);
1945 else if(this.param.yukkuri >= 1){
1946 this.setFaceImage(EFace.CRY2);
1949 getRange: function(){
1950 return this.param.range;
1952 isSleep: function(){
1953 return this.param.sleep >= 100;
1956 return this.param.yukkuri <= 0;
1958 isManpuku: function(){
1959 return this.param.hungry <= 20;
1961 isKuhuku: function(){
1962 return this.param.hungry >= 40;
1964 isVeryKuhuku: function(){
1965 return this.param.hungry >= 80;
1967 getYukkuri: function(){
1968 return this.param.yukkuri;
1970 setYukkuri: function(yukkuri){
1971 this.param.yukkuri = yukkuri;
1972 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1974 getHungry: function(){
1975 return this.param.hungry;
1977 setHungry: function(hungry){
1978 this.param.hungry = hungry;
1979 if(this.param.hungry < 0)this.param.hungry = 0;
1981 getUnun: function(){
1982 return this.param.unun;
1984 setUnun: function(unun){
1985 this.param.unun = unun;
1986 if(this.param.unun < 0)this.param.unun = 0;
1990 if(food instanceof Food){
1992 if(food.amount > 0){
1994 this.setHungry(this.param.hungry - food.getGive());
1995 this.setUnun(this.getUnun() + food.getGive() / 4);
1996 this.setYukkuri(this.getYukkuri() + 5);
1999 this.setYukkuri(this.getYukkuri() - 5);
2005 this.setHungry(this.param.hungry - food.give);
2006 this.setUnun(this.getUnun() + food.unun);
2007 this.setYukkuri(this.getYukkuri() + food.yukkuri);
2014 hunt:function(food){
2015 if(food.amount > 0){
2016 if(!this.isItemsMax()){
2018 this.items.push(food);
2019 this.setYukkuri(this.getYukkuri() + 1);
2025 declarePlace: function(place){
2028 getPlace:function(){
2031 isPlace: function(){
2032 return this.place !== null;
2036 if(this.direction == EDirection.RIGHT){
2037 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2039 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
2043 setBodyImage: function(ebody){
2044 var path = this.bodyStatus[ebody];
2045 this.image = game.assets[path];
2048 // this.imgBody.tl.pause();
2049 // this.imgGroup.tl.pause();
2050 this.imgBody.tl.clear();
2051 this.imgGroup.tl.clear();
2052 this.imgBody.tl.unloop();
2053 this.imgGroup.tl.unloop();
2057 tlResume: function(){
2058 // this.imgBody.tl.resume();
2059 // this.imgGroup.tl.resume();
2062 syncDirection:function(senderYukkuri){
2063 if(this.getX() > senderYukkuri.getX()){
2064 this.direction = EDirection.LEFT;
2065 senderYukkuri.direction = EDirection.RIGHT;
2067 this.direction = EDirection.RIGHT;
2068 senderYukkuri.direction = EDirection.LEFT;
2071 isCommunication: function(yukkuri){
2072 if(this.addressBook[yukkuri.id] === undefined) return true;
2073 if(this.addressBook[yukkuri.id].isGreeting) return false;
2076 addAddress: function(yukkuri){
2077 this.addressBook[yukkuri.id] = new Address(yukkuri);
2079 getAddress: function(yukkuri){
2080 if(this.addressBook[yukkuri.id] === undefined)return null;
2081 return this.addressBook[yukkuri.id];
2083 getStatusForDisplay: function (){
2085 var placeId = (this.place==null)?"無し" : this.place.id;
2086 ret += "ID " + this.id + "\n";
2087 ret += "プレイス " + placeId + "\n";
2088 ret += "ゆっくり " + this.getYukkuri() + "\n";
2089 ret += "空腹 " + this.getHungry() + "\n";
2090 ret += "うんうん " + this.getUnun() + "\n";
2091 ret += "もちもの " + this.items.length + "\n";
2092 ret += "アクション " + this.action.status + "\n";
2095 isItemsMax:function(){
2096 return this.items.length >= this.param.items_max;
2098 getItems:function(){
2101 addSearchObject:function(esearch, node){
2102 this.searchObjectMang.add(esearch, node)
2104 clearSearchObject:function(){
2105 this.searchObjectMang.clear()
2107 setFaceImage: function(eface){
2108 var path = this.faceStatus[eface];
2109 this.face.image = game.assets[path];
2111 myScale: function(_scaleX, _scaleY){
2112 this.face.scale(_scaleX,_scaleY);
2113 if(this.myCode === "REIMU"){
2114 this.okazari.x = -CHARA_WIDTH / 2;
2115 this.okazari.x = -CHARA_WIDTH / 2 - CHARA_WIDTH / 8;
2116 this.okazari.y = -CHARA_HEIGHT / 3 - CHARA_HEIGHT/7;
2118 this.okazari.x = -CHARA_WIDTH /2;
2119 this.okazari.y = -CHARA_HEIGHT / 2 - CHARA_HEIGHT/6;
2122 this.okazari.scale(_scaleX,_scaleY);
2123 this.hear.scale(_scaleX,_scaleY);
2124 this.scale(_scaleX,_scaleY);
2125 this.shadow.scale(_scaleX, _scaleY);
2127 send: function(targetYukkuri){
2128 targetYukkuri.recv();
2130 recv: function(object, callback){
2131 this.actionQueue.push({
2133 actionStatus : EAction.COMMUNICATE_RECV,
2137 destruct: function(){
2141 var Marisa = enchant.Class.create(Yukkuri,{
2142 initialize: function(x, y, grow){
2143 Yukkuri.call(this,x,y, grow);
2144 this.classname = "Marisa";
2145 this.myCode = "MARISA";
2146 this.myName = "まりさ";
2148 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2149 // var json = net.load("./data/marisa/params.json");
2150 // this.param = json.root.param;
2151 this.param = MarisaParam;
2152 if(this.grow == EGrow.BABY){
2153 this.myName = "まりちゃ";
2154 this.param.range /= 4;
2156 else if(this.grow == EGrow.CHILD){
2157 this.param.range /= 3;
2159 else if(this.grow == EGrow.SUBADULT){
2160 this.param.range *= 0.8;
2162 this.shadow = new enchant.Sprite(64, 64);
2163 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2164 this.shadow.x = 0 + this.x;
2165 this.shadow.y = this.getWidth() / 16 + this.x;
2166 this.shadow.image._element.style.zIndex = 2;
2168 this._style.zIndex = 5;
2170 this.face = new enchant.Sprite(64, 64);
2171 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2172 this.face.x = -CHARA_WIDTH / 2;
2173 this.face.y = -CHARA_HEIGHT / 2;
2174 this.face._style.zIndex = 0;
2176 this.faceStatus ={};
2177 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2178 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2179 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2180 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2181 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2182 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2183 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2184 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2185 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2186 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2189 this.hear = new enchant.Sprite(64, 64);
2190 this.hear.image = game.assets[EResPath.MARISA_HEAR];
2191 this.hear.x = -CHARA_WIDTH / 2;
2192 this.hear.y = -CHARA_HEIGHT / 2;
2193 this.hear._style.zIndex = 0;
2195 this.okazari = new Okazari(this);
2197 // this.imgGroup._style.zIndex = 1;
2200 this.imgGroup.addChild(this.shadow);
2201 this.imgBody.addChild(this);
2202 this.imgBody.addChild(this.face);
2203 this.imgBody.addChild(this.hear);
2204 this.imgBody.addChild(this.okazari);
2205 this.myScale(this.myScaleX, this.myScaleY)
2206 if(this instanceof Player){
2207 // this.myScaleX = 0.5;
2208 // this.myScaleY = 0.5;
2210 this.budge = new enchant.Sprite(16, 16);
2211 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2212 this.imgBody.addChild(this.budge);
2213 this.budge.x -= this.getWidth()/2;
2214 this.budge.y -= this.getHeight()/2;
2215 this.budge.scale(this.myScaleX, this.myScaleX);
2217 this.imgGroup.width = this.getWidth();
2218 this.imgGroup.height = this.getHeight();
2219 this.imgGroup.addChild(this.imgBody);
2220 backgroundMap.addChild(this.imgGroup);
2221 this._tweet = new TTweet(148, 64);
2223 this.imgGroup.addChild(this._tweet);
2224 this.imgGroup.x = x;
2225 this.imgGroup.y = y;
2228 this.action = new Action(this);
2232 var Player = enchant.Class.create(Marisa,{
2233 initialize: function(x, y){
2234 // this.runEnterframe = function(){
2236 Marisa.call(this, x, y, EGrow.ADULT);
2237 this.classname = "Player";
2239 ctl.setPlayer(this);
2240 // this.removeEventListener('enterframe',this.runEnterframe);
2241 this.addEventListener('enterframe', function(){
2244 if(this.age%10 === 0 && this.age !== 0){
2245 // console.log("palyer:" + this.age);
2248 ///////////////////////////////////////////////
2249 //Action pattern debug
2250 if(game.input.left){
2251 // this.changeFace(EResPath.MARISA_FACE_TIRED);
2253 this.direction = EDirection.LEFT;
2255 if(game.input.right){
2257 this.direction = EDirection.RIGHT;
2262 if(game.input.down){
2266 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2267 ///////////////////////////////////////////////
2269 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2270 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
2272 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
2274 //- Display the circle of search range.
2275 // fieldBg.image.clear();
2276 // fieldBg.image.context.beginPath();
2277 // fieldBg.image.context.fillStyle = '#ff0000';
2278 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2279 // fieldBg.image.context.fill();
2283 var Reimu = enchant.Class.create(Yukkuri,{
2284 initialize: function(x, y, grow){
2285 Yukkuri.call(this,x,y, grow);
2286 this.classname = "Reimu";
2287 this.myCode = "REIMU";
2288 this.myName = "れいむ";
2290 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2291 // var json = net.load("./data/reimu/params.json");
2292 // this.param = json.root.param;
2293 this.param = ReimuParam;
2294 if(this.grow == EGrow.BABY){
2295 this.myName = "れいみゅ";
2296 this.param.range /= 4;
2298 else if(this.grow == EGrow.CHILD){
2299 this.param.range /= 3;
2301 else if(this.grow == EGrow.SUBADULT){
2302 this.param.range *= 0.8;
2304 this.shadow = new enchant.Sprite(64, 64);
2305 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2306 this.shadow.x = 0 + this.x;
2307 this.shadow.y = this.getWidth() / 16 + this.x;
2308 this.shadow.image._element.style.zIndex = 2;
2310 this._style.zIndex = 5;
2312 this.face = new enchant.Sprite(64, 64);
2313 this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2314 this.face.x = -CHARA_WIDTH / 2;
2315 this.face.y = -CHARA_HEIGHT / 2;
2316 this.face._style.zIndex = 0;
2318 this.faceStatus ={};
2319 this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2320 this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2321 this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2322 this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2323 this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2324 this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2325 this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2326 this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2327 this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2328 this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2331 this.hear = new enchant.Sprite(64, 64);
2332 this.hear.image = game.assets[EResPathReimu.HEAR];
2333 this.hear.x = -CHARA_WIDTH / 2;
2334 this.hear.y = -CHARA_HEIGHT / 2;
2336 this.sub1 = new enchant.Sprite(64, 64);
2337 this.sub1.image = game.assets[EResPathReimu.SUB1];
2338 this.sub1.x = -CHARA_WIDTH / 2;
2339 this.sub1.y = -CHARA_HEIGHT / 2;
2341 this.okazari = new Okazari(this);
2343 // this.imgGroup._style.zIndex = 1;
2346 this.imgGroup.addChild(this.shadow);
2347 this.imgBody.addChild(this.okazari);
2348 this.imgBody.addChild(this);
2349 this.imgBody.addChild(this.face);
2350 this.imgBody.addChild(this.hear);
2351 this.imgBody.addChild(this.sub1);
2352 this.myScale(this.myScaleX, this.myScaleY)
2353 if(this instanceof Player){
2354 // this.myScaleX = 0.5;
2355 // this.myScaleY = 0.5;
2357 this.budge = new enchant.Sprite(16, 16);
2358 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2359 this.imgBody.addChild(this.budge);
2360 this.budge.x -= this.getWidth()/2;
2361 this.budge.y -= this.getHeight()/2;
2362 this.budge.scale(this.myScaleX, this.myScaleX);
2364 this.imgGroup.width = this.getWidth();
2365 this.imgGroup.height = this.getHeight();
2366 this.imgGroup.addChild(this.imgBody);
2367 backgroundMap.addChild(this.imgGroup);
2368 this._tweet = new TTweet(148, 64);
2370 this.imgGroup.addChild(this._tweet);
2371 this.imgGroup.x = x;
2372 this.imgGroup.y = y;
2375 this.action = new Action(this);
2380 game.onload = function(){
2384 def.ObjSprite = ObjSprite;
2385 def.Yukkuri = Yukkuri;
2386 def.nodeSort = nodeSort;
2387 mangTouch = new MangTouch(ctl);
2388 mangMsg = new MangMsg(ctl);
2389 ctl.setDefined(def);
2390 backgroundMap.image = game.assets[EResPath.MAP0];
2391 backgroundMap.loadData(_mapData);
2392 backgroundMap.collisionData = _collisionData;
2394 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2395 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2396 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2397 fieldBg.image = fieldSurface;
2401 windowFront.image = windowSurface;
2404 windowFront.opacity = 0.5;
2406 windowSurface.context.fillStyle = '#000';
2407 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2410 menuSurface.context.fillStyle = '#000';
2411 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2412 menuBg.image = menuSurface;
2413 menuBg.x = EMenuPos.X;
2414 menuBg.y = EMenuPos.Y;
2415 backgroundMap.addChild(fieldBg);
2416 mangIcon = new MangIcon(ctl, menuBg);
2418 game.rootScene.addChild(backgroundMap);
2419 game.rootScene.addChild(windowFront);
2420 game.rootScene.addChild(menuBg);
2422 // var labelGroup = new LabelGroup();
2423 mangLabel = new MangLabel(ctl, menuBg);
2424 // var info = new Label("ゆっくり");
2425 // info.color = "#ffffff";
2426 // info.font = "14px 'Times New Roman'";
2428 // info.y = GAME_HEIGHT / 2;
2429 // labelGroup.addChild(info);
2430 // menuBg.addChild(labelGroup);
2433 // var food = new def.Food("apple", 200, 250);
2434 backgroundMap.addChild(foodGroup);
2435 // backgroundMap.addChild(placeGroup);
2436 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2437 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2438 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2439 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2440 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2441 // new Unun(100, 100);
2442 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2446 game.rootScene.addEventListener('touchstart', function (e) {
2447 game.touched = true;
2448 var mang = mangTouch.get(ctl.getCurrentCommand());
2451 game.rootScene.addEventListener('touchmove', function (e) {
2452 var mang = mangTouch.get(ctl.getCurrentCommand());
2455 game.rootScene.addEventListener('touchend', function (e) {
2456 var mang = mangTouch.get(ctl.getCurrentCommand());
2458 game.touched = false;
2462 game.rootScene.addEventListener('enterframe', function(){
2464 mangLabel.draw(player);
2465 if(this.age%BASE_FPS == 0 ){
2470 this.addEventListener('enterframe', function(){
2471 //The priority processing of display instead of z-index
2473 backgroundMap.childNodes.sort(nodeSort);