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;
41 // var DAY = HOUR * 24;
43 var GAME_START_TIME = HOUR * 6;
46 YUKKURI_BASE : './data/yukkuri_base.png',
47 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
48 YUKKURI_UNUN : './data/unun.png',
49 YUKKURI_SHADOW : './data/shadow.png',
50 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
51 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
52 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
53 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
54 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
55 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
56 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
57 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
58 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
59 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
60 MARISA_HEAR : './data/marisa/hear1.png',
61 OBJECT : './data/object.png',
62 MAP0 : './data/map0.png',
63 COMMAND : './data/command.png',
64 OKAZARI : './data/okazari.png',
65 PLACE_TREE : './data/system/place_tree.png',
66 GRASS : './data/system/grass.png',
67 PLAYER_BADGE : './data/system/player_badge.png',
68 // PLACE_TREE : './data/system/rapture.png',
74 FACE_NORMAL : './data/reimu/face_normal1.png',
75 FACE_TIRED : './data/reimu/face_tired1.png',
76 FACE_ANGRY : './data/reimu/face_angry1.png',
77 FACE_CRY1 : './data/reimu/face_cry1.png',
78 FACE_CRY2 : './data/reimu/face_cry2.png',
79 FACE_EAT1 : './data/reimu/face_eat1.png',
80 FACE_EAT2 : './data/reimu/face_eat2.png',
81 FACE_HAPPY1 : './data/reimu/face_happy1.png',
82 FACE_HAPPY2 : './data/reimu/face_happy2.png',
83 FACE_SLEEP : './data/reimu/face_sleep1.png',
84 HEAR : './data/reimu/hear1.png',
85 OKAZARI : './data/reimu/okazari.png',
86 SUB1 : './data/reimu/sub1.png',
118 HEIGHT : GAME_HEIGHT,
123 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
134 MOVE_TO_EAT_START: 10,
135 MOVE_TO_EAT_UNDERWAY: 11,
139 UNUN_SMELL_START : 15,
140 UNUN_SMELL_WAIT : 16,
143 COMMUNICATE_START : 19,
144 COMMUNICATE_WAIT: 20,
145 COMMUNICATE_RECV: 21,
146 MOVE_TO_PLACE_START_HOMELESS: 22,
147 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
148 DECLARE_PLACE_HOMELESS: 24,
149 MOVE_TO_HUNT_START: 25,
182 LEARN_NO_FOOD_IN_PLACE:19,
184 var EWalkAnimation = {
214 NO_FOOD_IN_PLACE : 1,
220 var ObjSprite = enchant.Class.create(enchant.Sprite,{
221 initialize: function (w, h){
222 enchant.Sprite.call(this, w, h);
225 // // new BoxLabel(this.ctl,100, e.x, e.y);
226 // var box = new Box(this.ctl, 200, 200);
227 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
229 getStatusForDisplay: function (){
238 getWidth: function(){
241 getHeight: function(){
244 removeAll: function(){
251 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
262 //-Event register [onactionstart,onactiontick,onactionend]
263 if(eventFunctions !== undefined){
264 for(var key in eventFunctions){
265 params[key] = eventFunctions[key];
268 return this.tween(params);
270 function plusFrameScale(frame, scale){
271 return (frame/2) * (1 - scale)
276 include("./lang/ja.js");
277 window.onload = function(){
278 var nodeSort = function (a, b){
279 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
282 else if(typeof a.id === "undefined"){
285 else if(typeof b.id === "undefined"){
290 if(a instanceof Box && b instanceof Box){
293 if(a instanceof Box){
296 if(b instanceof Box){
299 if(a instanceof SpriteGroup){
303 if(b instanceof SpriteGroup){
308 if(a instanceof Place){
309 ay += Math.round(a.height * 0.7);
311 if(b instanceof Place){
312 by += Math.round(b.height * 0.7);
315 if(ay < by)return -1;
316 else if(ay > by)return 1;
317 if(a.id < b.id)return -1;
318 else if(a.id > b.id)return 1;
324 var def = new Object();
325 var foodGroup = new Group();
326 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
327 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
328 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
329 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
330 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
334 var tmpName = EResPathReimu.getName();
336 for(var _v in EResPathReimu){
337 if(typeof EResPathReimu[_v] === "function")continue;
338 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
344 for(var _v in EResPath){
345 _loadArr[i] = EResPath[_v];
348 game.preload(_loadArr);
349 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
350 var backgroundMap = new MapGroup(16, 16);
351 include("./class.js");
352 include("./ctrl.js");
355 ctl.setBackgroundMap(backgroundMap);
356 var Action = enchant.Class.create({
357 initialize: function (yukkuri){
358 this.status = EAction.THINK;
359 this.yukkuri = yukkuri;
360 this.isMoving = false;
361 this.targetNode = null;
363 getStatus: function(){
366 setStatus: function(eaction){
367 this.status = eaction;
370 if(this.yukkuri.isDead()){
371 this.status = EAction.DEAD;
373 // else if(this.yukkuri.isSleep()){
374 // this.status = EAction.SLEEP;
384 if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
386 this.setStatus(EAction.THINK);
387 console.log("wait cnt end");
390 case EAction.THINK_IN_HOME:
393 this.think_in_home();
395 case EAction.EAT_IN_HOME:
400 if(this.yukkuri.age%2 === 0){
401 this.yukkuri.changeFace();
403 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
406 case EAction.MOVE_TO_EAT_START:
407 this.move_to_eat_start();
409 case EAction.MOVE_TO_EAT_UNDERWAY:
415 case EAction.SLEEP_START:
418 case EAction.SLEEP_WAIT:
423 case EAction.EAT_START:
426 case EAction.EAT_WAIT:
428 case EAction.UNUN_START:
431 case EAction.UNUN_WAIT:
433 case EAction.MOVE_TO_COMMAND:
434 this.move_to_command();
436 case EAction.UNUN_SMELL_START:
437 this.unun_smell_start();
439 case EAction.COMMUNICATE_START:
440 this.communicate_start();
442 case EAction.COMMUNICATE_WAIT:
444 case EAction.COMMUNICATE_RECV:
446 case EAction.MOVE_TO_PLACE_START_HOMELESS:
447 this.move_to_place_start_homeless();
449 case EAction.DECLARE_PLACE_HOMELESS:
450 this.declare_place_homeless();
452 case EAction.MOVE_TO_HUNT_START:
453 this.move_to_hunt_start();
455 case EAction.HUNT_START:
458 case EAction.MOVE_GOTO_HOME:
459 this.move_goto_home();
461 case EAction.IN_HOME:
466 this.yukkuri.reverse();
468 // thinkHavePlace: function(){
469 // var date = ctl.getDate();
470 // if(this.yukkuri.isPlaceRange()){
473 // if(date === EDate.EVENING
474 // || date === EDate.NIGHT
475 // || date === EDate.MIDNIGHT
477 // this.setStatus(EAction.MOVE_GOTO_HOME);
480 // else if(date === EDate.EVENING){
481 // // if(this.yukkuri.isItemsMax()){
482 // // this.setStatus(EAction.IN_HOME);
485 // // this.setStatus(EAction.MOVE_TO_HUNT_START);
489 // if(this.yukkuri.isVeryKuhuku()){
493 // this.setStatus(EAction.MOVE_GOTO_HOME);
495 // else if(this.yukkuri.isSleep()){
496 // this.setStatus(EAction.SLEEP_START);
498 // else if(this.yukkuri.getUnun() >= 80){
499 // this.setStatus(EAction.UNUN_START);
502 // this.yukkuri.changeFace();
506 think_in_home: function(){
507 var date = ctl.getDate();
508 if((date === EDate.MIDNIGHT)
509 && !this.yukkuri.isSleep()
510 && !this.yukkuri.isVeryKuhuku()
514 "nextStatus":EAction.THINK_IN_HOME,
515 "myYukkuri": this.yukkuri
519 else if(date === EDate.EVENING){
522 else if(this.yukkuri.isVeryKuhuku() && this.yukkuri.getPlace().isFood()){
523 this.setStatus(EAction.EAT_IN_HOME);
526 //marisa is hunting move
527 if(this.yukkuri.beforeHuntingFood !== null){
528 new MoveToHuntEvent({
530 "targetNode": this.yukkuri.beforeHuntingFood,
532 "myYukkuri": this.yukkuri
536 this.setStatus(EAction.WALK);
540 eat_in_home: function(){
542 "targetNode": this.yukkuri.getPlace(),
544 "myYukkuri": this.yukkuri
547 move_to_eat_start : function(){
550 "targetNode": this.targetNode,
552 "myYukkuri": this.yukkuri
558 walk : function(retryCounter){
559 if(retryCounter > 15){
561 this.status = EAction.NONE;
562 console.log("retryCount over");
565 if(this.yukkuri.imgGroup.tl.queue.length === 0){
567 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
569 this.isMoving = false;
570 this.status = EAction.THINK;
574 var xpos = 150 + rand(40) - (retryCounter * 10);
575 var ypos = 150 + rand(40) - (retryCounter * 10);
578 this.yukkuri.vy = -ypos;
580 else if(rand(8) == 1){
581 this.yukkuri.vx = xpos;
582 this.yukkuri.vy = -ypos;
583 this.yukkuri.direction = EDirection.RIGHT;
585 else if(rand(8) == 2){
586 this.yukkuri.vx = xpos;
588 this.yukkuri.direction = EDirection.RIGHT;
590 else if(rand(8) == 3){
591 this.yukkuri.vx = xpos;
592 this.yukkuri.vy = ypos;
593 this.yukkuri.direction = EDirection.RIGHT;
595 else if(rand(8) == 4){
597 this.yukkuri.vy = ypos;
599 else if(rand(8) == 5){
600 this.yukkuri.vx = -xpos;
601 this.yukkuri.vy = ypos;
602 this.yukkuri.direction = EDirection.LEFT;
604 else if(rand(8) == 6){
605 this.yukkuri.vx = -xpos;
607 this.yukkuri.direction = EDirection.LEFT;
609 else if(rand(8) == 7){
610 this.yukkuri.vx = -xpos;
611 this.yukkuri.vy = -ypos;
612 this.yukkuri.direction = EDirection.LEFT;
614 if (this.yukkuri.vx || this.yukkuri.vy) {
615 var map = ctl.backgroundMap;
616 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
617 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
618 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
619 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
620 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
621 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
622 // console.log("X:" + this.yukkuri.moveX);
623 // console.log("Y:" + this.yukkuri.moveY);
624 this.isMoving = true;
625 this.yukkuri.reverse();
626 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
627 mangMsg.output(this.yukkuri,EMsg.WALK);
629 this.targetNode = null;
631 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
632 this.walk(retryCounter+1);
638 sleep_start: function(){
641 "myYukkuri": this.yukkuri
645 mangMsg.output(this.yukkuri, EMsg.DEAD);
646 this.yukkuri.tlPause();
647 this.yukkuri.setBodyImage(EBody.DEAD);
649 eat_start: function(){
652 "targetNode": this.targetNode,
654 "myYukkuri": this.yukkuri
658 unun_start: function(){
661 "myYukkuri": this.yukkuri
664 unun_smell_start: function(){
667 "myYukkuri": this.yukkuri
670 communicate_start:function(){
671 new ComSayHelloSendEvent({
673 "targetNode": this.targetNode,
675 "myYukkuri": this.yukkuri
678 move_to_place_start_homeless:function(){
679 new MoveToPlaceStartHomelessEvent({
680 "targetNode": this.targetNode,
682 "myYukkuri": this.yukkuri
685 declare_place_homeless:function(){
686 new DeclarePlaceHomelessEvent({
687 "targetNode": this.targetNode,
689 "myYukkuri": this.yukkuri
692 move_to_hunt_start:function(){
693 new MoveToHuntEvent({
695 "targetNode": this.targetNode,
697 "myYukkuri": this.yukkuri
700 hunt_start:function(){
703 "targetNode": this.targetNode,
705 "myYukkuri": this.yukkuri
708 move_goto_home:function(){
709 var place = this.yukkuri.getPlace();
710 new MoveGotoHomeEvent({
714 "myYukkuri": this.yukkuri
718 var place = this.yukkuri.getPlace();
723 "myYukkuri": this.yukkuri
726 move_to_command: function(){
730 this.yukkuri.clearSearchObject();
731 var nodes = ctl.getObjs();
735 for (var key in nodes) {
736 var node = nodes[key];
737 if(this.yukkuri.id === node.id)continue;
741 && !(this.targetNode instanceof Unun)
742 && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
744 this.yukkuri.addSearchObject(ESearch.UNUN, node);
747 else if (node instanceof Food && node.amount > 0) {
748 if(this.yukkuri.within(node, this.yukkuri.getRange())){
749 this.yukkuri.addSearchObject(ESearch.FOOD, node);
753 else if(node instanceof Yukkuri){
754 if(this.yukkuri.within(node, this.yukkuri.getRange())){
755 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
759 else if(node instanceof Place){
760 if(this.yukkuri.within(node, this.yukkuri.getRange())){
761 this.yukkuri.addSearchObject(ESearch.PLACE, node);
765 this.status = EAction.WALK;
769 * Range範囲内のObjSprを管理する
770 * 注意!:ゆっくりプレイスを持って入るもののみ使用される
774 var SearchObjectMang = enchant.Class.create({
775 initialize: function (){
780 for(var key in ESearch){
781 var esearch = ESearch[key];
782 this.datas[esearch] = [];
785 add :function(esearch, node){
786 this.datas[esearch].push(node);
789 for(var key in ESearch){
790 var esearch = ESearch[key];
791 this.datas[esearch].length = 0;
793 // this.datas.length = 0;
796 get:function (esearch){
797 return this.datas[esearch];
799 getNear:function (esearch, yukkuri){
800 var objects = this.datas[esearch];
801 var nearDistance = null;
803 for(var i=0;i<objects.length;i++){
804 var object = objects[i];
805 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
806 if(nearDistance === null || nearDistance > nowDistance){
807 nearDistance = nowDistance;
813 callEvent: function(yukkuri){
814 if(yukkuri.isItemsMax() && yukkuri.isPlace()){
815 yukkuri.action.targetNode = yukkuri.getPlace();
816 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
819 if(yukkuri.isVeryKuhuku()){
821 var foods = this.get(ESearch.FOOD);
822 if(foods.length > 0){
823 var foods = this.get(ESearch.FOOD);
824 food = this.getNear(ESearch.FOOD, yukkuri);
826 yukkuri.action.targetNode = food;
827 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
831 if(yukkuri.getMemory(EMemory.FOOD_IN_PLACE) === 0 && yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
832 yukkuri.action.setStatus(EAction.WALK);
836 if(foods.length === 0 && yukkuri.isPlace()){
838 yukkuri.action.targetNode = yukkuri.getPlace();
839 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
845 if(yukkuri.isSleep()){
846 yukkuri.action.setStatus(EAction.SLEEP_START);
850 else if(yukkuri.getUnun() >= 80){
851 yukkuri.action.setStatus(EAction.UNUN_START);
856 if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
857 food = this.getNear(ESearch.FOOD, yukkuri);
859 yukkuri.action.targetNode = food;
860 yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
864 ununs = this.get(ESearch.UNUN);
865 if(ununs.length !== 0){
866 yukkuri.action.targetNode = yukkuri.getPlace();
867 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
870 var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
871 if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
872 yukkuri.action.targetNode = searchYukkuri;
873 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
876 if(!yukkuri.isPlace()){
877 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
878 if(searchYukkuri != null && !searchYukkuri.isOwner()){
879 yukkuri.action.targetNode = searchYukkuri;
880 yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
884 yukkuri.action.setStatus(EAction.WALK);
889 var Event = enchant.Class.create({
890 initialize: function (_data){
893 onactionstart:function(self){
894 return this._onactionstart;
896 _onactionstart:function(e){
897 if(typeof e === "undefined")return;
899 onactiontick:function(self){
901 if(typeof e === "undefined")return;
904 onactionend:function(self){
906 if(typeof e === "undefined")return;
910 var WalkEvent = enchant.Class.create(Event,{
911 initialize: function (_data){
913 this.yukkuri = _data.myYukkuri;
914 this.action = _data.action;
916 mangMsg.output(this.yukkuri, EMsg.SLEEP);
917 this.action.setStatus(EAction.SLEEP_WAIT);
918 this.yukkuri.setFaceImage(EFace.SLEEP);
919 this.yukkuri.tlPause();
921 this.yukkuri.addEventListener('enterframe', function() {
922 var yukkuri = self.yukkuri;
930 var SleepEvent = enchant.Class.create(Event,{
931 initialize: function (_data){
933 this.yukkuri = _data.myYukkuri;
934 this.action = _data.action;
936 mangMsg.output(this.yukkuri, EMsg.SLEEP);
937 this.action.setStatus(EAction.SLEEP_WAIT);
938 this.yukkuri.setFaceImage(EFace.SLEEP);
939 this.yukkuri.tlPause();
942 this.yukkuri.addEventListener('enterframe', function() {
943 var yukkuri = self.yukkuri;
944 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
945 if(yukkuri.param.sleep <= 0){
946 yukkuri.param.sleep = 0;
947 this.removeEventListener("enterframe",arguments.callee);
948 mangMsg.output(self.yukkuri, EMsg.GET_UP);
949 yukkuri.setFaceImage(EFace.NORMAL);
951 // self.action.setStatus(EAction.WAIT);
952 if(self.data.nextStatus !== undefined){
953 self.action.setStatus(self.data.nextStatus);
955 self.action.setStatus(EAction.THINK);
962 var UnunEvent = enchant.Class.create(Event,{
963 initialize: function (_data){
965 this.yukkuri = _data.myYukkuri;
966 this.action = _data.action;
967 this.action.setStatus(EAction.UNUN_WAIT);
968 mangMsg.output(this.yukkuri, EMsg.UNUN);
969 this.yukkuri.setFaceImage(EFace.HAPPY2);
972 this.yukkuri.wait(sec, {
973 "onactionend": this.onactionend(this)
976 onactionend:function(self){
978 if(typeof e === "undefined")return;
980 self.action.setStatus(EAction.WAIT);
981 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
983 "waitframe": FPS * 1.5,
984 "action": self.action,
985 "myYukkuri": self.yukkuri
990 var WaitEvent = enchant.Class.create(Event,{
991 initialize: function (_data){
993 this.yukkuri = _data.myYukkuri;
994 this.action = _data.action;
995 this.waitframe = _data.waitframe;
996 this.yukkuri.wait(this.waitframe, {
997 "onactionstart": this.onactionstart(this),
998 "onactiontick": this.onactiontick(this),
999 "onactionend": this.onactionend(this)
1002 onactionend:function(self){
1004 if(typeof e === "undefined")return;
1005 self.action.setStatus(EAction.THINK);
1009 var UnunSmellEvent = enchant.Class.create(Event,{
1010 initialize: function (_data){
1012 this.yukkuri = _data.myYukkuri;
1013 this.action = _data.action;
1014 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1015 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1016 this.yukkuri.setFaceImage(EFace.CRY1);
1018 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1019 this.yukkuri.wait(sec, {
1020 "onactionend": this.onactionend(this)
1023 onactionend:function(self){
1025 if(typeof e === "undefined")return;
1026 self.action.setStatus(EAction.WALK);
1031 var EatEvent = enchant.Class.create(Event,{
1032 initialize: function (_data){
1034 this.yukkuri = _data.myYukkuri;
1035 this.food = _data.targetNode;
1036 this.action = _data.action;
1037 this.action.setStatus(EAction.EAT_WAIT);
1040 var sec = BASE_FPS * 3;
1041 if(this.yukkuri.eat(this.food)){
1042 mangMsg.output(this.yukkuri, EMsg.EAT);
1043 this.yukkuri.setFaceImage(EFace.EAT2);
1046 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1047 this.yukkuri.setFaceImage(EFace.CRY2);
1049 this.yukkuri.wait(sec, {
1050 "onactionend": this.onactionend(this)
1053 onactionend:function(self){
1055 if(typeof e === "undefined")return;
1056 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1057 self.action.setStatus(EAction.THINK);
1058 self.yukkuri.setFaceImage(EFace.NORMAL);
1060 self.action.setStatus(EAction.EAT_START);
1067 * -When yukkuri find Food.
1070 * targetNode: enchant.Node
1074 var MoveToEatEvent = enchant.Class.create(Event,{
1075 initialize: function (_data){
1077 this.yukkuri = this.data.myYukkuri;
1078 this.action = this.data.action;
1080 var yukkuri = this.yukkuri;
1081 var node = this.data.targetNode;
1083 if(this.data.type == "food"){
1084 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1085 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1086 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1087 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1088 var frame = distance + distance/5 + 1;
1089 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1090 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1093 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1094 "onactionstart": this.onactionstart(this),
1095 "onactiontick": this.onactiontick(this),
1096 "onactionend": this.onactionend(this)
1100 onactionstart:function(self){
1102 if(typeof e === "undefined")return;
1103 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1106 onactiontick:function(self){
1108 if(typeof e === "undefined")return;
1111 onactionend:function(self){
1113 if(typeof e === "undefined")return;
1114 self.action.setStatus(EAction.EAT_START);
1118 var MoveToHuntEvent = enchant.Class.create(Event,{
1119 initialize: function (_data){
1121 this.yukkuri = this.data.myYukkuri;
1122 this.action = this.data.action;
1124 var yukkuri = this.yukkuri;
1125 var node = this.data.targetNode;
1128 var nodeWidth = node.width;
1129 var nodeHeight = node.height;
1133 if(this.data.type == "food"){
1134 this.action.setStatus(EAction.WAIT);
1135 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1136 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1137 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1138 var frame = distance + distance/5 + 1;
1139 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1140 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1142 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1144 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1145 "onactionend": this.onactionend(this)
1149 onactionend:function(self){
1151 if(typeof e === "undefined")return;
1152 self.action.setStatus(EAction.HUNT_START);
1156 var HuntStartEvent = enchant.Class.create(Event,{
1157 initialize: function (_data){
1158 Event.call(this, _data);
1161 this.yukkuri = _data.myYukkuri;
1162 this.food = _data.targetNode;
1163 this.action = _data.action;
1164 this.action.setStatus(EAction.WAIT);
1165 this.huntingStatus = "hunting";
1167 this.yukkuri.beforeHuntingFood = this.food;
1168 var sec = BASE_FPS * 8;
1169 if(this.yukkuri.hunt(this.food)){
1170 this.huntingStatus = "hunting";
1171 mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1172 this.yukkuri.setFaceImage(EFace.HAPPY1);
1174 if(this.yukkuri.isItemsMax()){
1176 this.huntingStatus = "return";
1177 // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1178 this.yukkuri.setFaceImage(EFace.NORMAL);
1181 this.huntingStatus = "cry";
1182 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1183 this.yukkuri.setFaceImage(EFace.CRY2);
1187 this.yukkuri.wait(sec, {
1188 "onactiontick": this.onactiontick(this),
1189 "onactionend": this.onactionend(this)
1192 onactiontick:function(self){
1194 if(typeof e === "undefined")return;
1196 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1197 if(this.age%(BASE_FPS * 3) == 0){
1198 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1199 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1204 onactionend:function(self){
1206 if(typeof e === "undefined")return;
1207 if(self.huntingStatus == "hunting"){
1208 if(self.yukkuri.isItemsMax()){
1209 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1210 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1212 self.action.setStatus(EAction.HUNT_START);
1215 else if(self.huntingStatus == "return"){
1216 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1218 else if(self.huntingStatus === "cry"){
1219 // self.action.setStatus(EAction.THINK);
1220 self.action.setStatus(EAction.WALK);
1227 this.yukkuri = null;
1232 var MoveGotoHomeEvent = enchant.Class.create(Event,{
1233 initialize: function (_data){
1235 this.yukkuri = this.data.myYukkuri;
1236 this.action = this.data.action;
1238 var yukkuri = this.yukkuri;
1239 var place = this.data.targetNode;
1241 if(this.data.type == "hunt_end"){
1242 this.action.setStatus(EAction.WAIT);
1243 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1244 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1245 // console.log("place.x:" + place.x);
1246 // console.log("place.y:" + place.y);
1247 // console.log("yukkuri.getX():" + yukkuri.getX());
1248 // console.log("yukkuri.getY():" + yukkuri.getY());
1249 // console.log("yukkuri.vx:" + yukkuri.vx);
1250 // console.log("yukkuri.vy:" + yukkuri.vy);
1251 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1252 var frame = distance + distance/2 + 1 ;
1253 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1254 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1256 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1258 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1259 "onactiontick": this.onactiontick(this),
1260 "onactionend": this.onactionend(this)
1264 onactiontick:function(self){
1266 if(typeof e === "undefined")return;
1267 if(this.age%(BASE_FPS * 5) == 0){
1268 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1272 onactionend:function(self){
1274 if(typeof e === "undefined")return;
1275 self.action.setStatus(EAction.IN_HOME);
1281 this.yukkuri = null;
1285 var InHomeEvent = enchant.Class.create(Event,{
1286 initialize: function (_data){
1288 this.yukkuri = this.data.myYukkuri;
1289 this.action = this.data.action;
1291 var yukkuri = this.yukkuri;
1292 var place = this.data.targetNode;
1294 if(yukkuri.isVeryKuhuku()){
1296 yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1297 this.action.setStatus(EAction.EAT_IN_HOME);
1300 yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1302 if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1303 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1304 this.action.setStatus(EAction.THINK);
1307 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1308 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1313 this.action.setStatus(EAction.WAIT);
1314 var items = this.yukkuri.getItems();
1315 if(items.length > 0){
1316 place.setItems(items);
1320 var sec = BASE_FPS * 10;
1321 if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1322 this.yukkuri.wait(sec, {
1323 "onactiontick": this.onactiontick(this),
1324 "onactionend": this.onactionend(this)
1327 onactiontick:function(self){
1329 if(typeof e === "undefined")return;
1330 if(this.age%(BASE_FPS * 5) == 0){
1331 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1335 onactionend:function(self){
1337 if(typeof e === "undefined")return;
1338 self.action.setStatus(EAction.THINK_IN_HOME);
1342 var EatInHomeEvent = enchant.Class.create(Event,{
1343 initialize: function (_data){
1345 this.yukkuri = _data.myYukkuri;
1346 this.place = _data.targetNode;
1347 this.action = _data.action;
1348 this.action.setStatus(EAction.EAT_WAIT);
1350 var sec = BASE_FPS * 3;
1351 var foodHash = this.place.getFoodHash();
1352 if(foodHash !== false && this.yukkuri.eat(foodHash)){
1353 mangMsg.output(this.yukkuri, EMsg.EAT);
1354 this.yukkuri.setFaceImage(EFace.EAT2);
1357 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1358 this.yukkuri.setFaceImage(EFace.CRY2);
1361 this.yukkuri.wait(sec, {
1362 "onactionend": this.onactionend(this)
1365 onactionend:function(self){
1367 if(typeof e === "undefined")return;
1368 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1369 self.action.setStatus(EAction.EAT_IN_HOME);
1371 // new EatInHomeEvent({
1372 // "targetNode": self.place,
1373 // "action": self.action,
1374 // "myYukkuri": self.yukkuri
1377 self.action.setStatus(EAction.THINK_IN_HOME);
1378 self.yukkuri.setFaceImage(EFace.NORMAL);
1385 var MoveCommandEvent = enchant.Class.create(Event,{
1386 initialize: function (_data){
1388 this.yukkuri = this.data.myYukkuri;
1389 this.action = this.data.action;
1390 this.vx = this.data.vx;
1391 this.vy = this.data.vy;
1393 var yukkuri = this.yukkuri;
1394 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1395 yukkuri.vx = node.x - yukkuri.getX();
1396 yukkuri.vy = node.y - yukkuri.getY();
1397 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1398 var frame = distance + 1;
1399 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1401 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1402 "onactionstart": this.onactionstart(this),
1403 "onactiontick": this.onactiontick(this),
1404 "onactionend": this.onactionend(this)
1407 onactionstart:function(self){
1409 if(typeof e === "undefined")return;
1412 onactiontick:function(self){
1414 if(typeof e === "undefined")return;
1417 onactionend:function(self){
1419 if(typeof e === "undefined")return;
1420 self.action.setStatus(EAction.THINK);
1425 * Say hello contact to send communication .
1427 var ComSayHelloSendEvent = enchant.Class.create(Event,{
1428 initialize: function (_data){
1430 this.yukkuri = _data.myYukkuri;
1431 this.targetYukkuri = _data.targetNode;
1432 this.action = _data.action;
1433 this.action.setStatus(EAction.COMMUNICATE_WAIT);
1434 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1437 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1438 this.targetYukkuri.tlPause();
1439 this.yukkuri.tlPause();
1440 this.yukkuri.syncDirection(this.targetYukkuri);
1442 this.yukkuri.addAddress(this.targetYukkuri);
1443 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1445 var sec = BASE_FPS * 2;
1446 this.yukkuri.wait(sec, {
1447 "onactiontick": this.onactiontick(this),
1448 "onactionend": this.onactionend(this)
1451 onactiontick:function(self){
1453 if(typeof e === "undefined")return;
1456 onactionend:function(self){
1458 if(typeof e === "undefined")return;
1459 new ComSayHelloRecvEvent({
1461 "targetNode": self.yukkuri,
1462 "action": self.targetYukkuri.action,
1463 "myYukkuri": self.targetYukkuri
1468 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1469 initialize: function (_data){
1471 this.yukkuri = _data.myYukkuri;
1472 this.targetYukkuri = _data.targetNode;
1473 this.action = _data.action;
1474 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1475 this.yukkuri.addAddress(this.targetYukkuri);
1476 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1478 var sec = BASE_FPS * 2;
1479 this.yukkuri.wait(sec, {
1480 "onactiontick": this.onactiontick(this),
1481 "onactionend": this.onactionend(this)
1484 onactiontick:function(self){
1486 if(typeof e === "undefined")return;
1489 onactionend:function(self){
1491 if(typeof e === "undefined")return;
1492 self.action.setStatus(EAction.THINK);
1494 self.yukkuri.action.setStatus(EAction.THINK);
1495 self.yukkuri.animation();
1496 self.targetYukkuri.action.setStatus(EAction.THINK);
1497 self.targetYukkuri.animation();
1501 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1502 initialize: function (_data){
1504 this.yukkuri = this.data.myYukkuri;
1505 this.action = this.data.action;
1507 var yukkuri = this.yukkuri;
1508 var node = this.data.targetNode;
1510 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1511 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
1512 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1513 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1514 var frame = distance + distance/5 + 1;
1515 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1517 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1520 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1521 "onactionend": this.onactionend(this)
1524 onactionend:function(self){
1526 if(typeof e === "undefined")return;
1527 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1529 self.yukkuri = null;
1534 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1535 initialize: function (_data){
1537 this.yukkuri = _data.myYukkuri;
1538 this.place = _data.targetNode;
1539 this.action = _data.action;
1540 this.action.setStatus(EAction.WAIT);
1543 var sec = BASE_FPS * 3;
1544 this.yukkuri.declarePlace(this.place);
1545 this.place.setOwner(this.yukkuri);
1546 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1548 this.yukkuri.setFaceImage(EFace.NORMAL);
1549 this.yukkuri.wait(sec, {
1550 "onactionend": this.onactionend(this)
1553 onactionend:function(self){
1555 if(typeof e === "undefined")return;
1556 self.action.setStatus(EAction.THINK);
1561 var Food = enchant.Class.create(ObjSprite,{
1562 initialize: function (type, x, y){
1563 this.classname = "Food";
1564 //一つにつきgiveの値分、hunguryを減少させられる
1565 if(type == "apple"){
1566 ObjSprite.call(this,16,16);
1567 this.image = game.assets[EResPath.OBJECT];
1571 }else if(type == "grass"){
1572 ObjSprite.call(this,64,64);
1573 this.image = game.assets[EResPath.GRASS];
1580 foodGroup.addChild(this);
1581 this.addEventListener('enterframe', function(){
1582 if(this.amount <= 0){
1587 getAmount: function(){
1590 getGive: function(){
1594 var Place = enchant.Class.create(ObjSprite,{
1595 initialize: function (type, x, y){
1596 ObjSprite.call(this,128,128);
1597 this.image = game.assets[EResPath.PLACE_TREE];
1598 this.x = x - this.width / 2;
1599 this.y = y - this.height / 2;
1600 backgroundMap.addChild(this);
1603 for(var key in EFood){
1604 var efood = EFood[key];
1605 this.foods[efood] = 0;
1607 // this.addEventListener('enterframe', function(){
1608 // if(this.age%10 === 0 && this.age !== 0){
1609 // console.log("x/y " + this.x + "/" + this.y);
1611 // if(game.input.left){
1614 // if(game.input.right){
1617 // if(game.input.up){
1620 // if(game.input.down){
1625 getStatusForDisplay: function(){
1628 if(this.owner == null)ownerId = "なし";
1629 else ownerId = this.owner.id;
1630 ret += "プレイスID " + this.id + "\n";
1631 ret += "オーナーID " + ownerId + "\n";
1632 ret += "食料うめぇ " + this.foods[EFood.GREAT] + "\n";
1633 ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1634 ret += "食料にがにが " + this.foods[EFood.BAD] + "\n";
1637 setItems:function(items){
1638 var len = items.length;
1639 for(var i=0; i<len; i++){
1640 var item = items[i];
1641 if(item instanceof Food){
1642 this.foods[EFood.NORMAL]++;
1649 for(var key in EFood){
1650 var efood = EFood[key];
1651 ret += this.foods[efood];
1655 getFoodHash:function(){
1656 if(this.foods[EFood.GREAT] !== 0){
1657 this.foods[EFood.GREAT]--;
1658 return {give:20,yukkuri:15,unun:20};
1660 else if(this.foods[EFood.NORMAL] !== 0){
1661 this.foods[EFood.NORMAL]--;
1662 return {give:10,yukkuri:5,unun:10};
1664 else if(this.foods[EFood.BAD] !== 0){
1665 this.foods[EFood.BAD]--;
1666 return {give:10,yukkuri:-2,unun:10};
1670 setOwner: function(yukkuri){
1671 this.owner = yukkuri;
1673 isOwner: function(){
1674 return this.owner !== null;
1677 var Unun = enchant.Class.create(ObjSprite,{
1678 initialize: function (x, y){
1679 this.classname = "Unun";
1680 ObjSprite.call(this,32,32);
1681 this.image = game.assets[EResPath.YUKKURI_UNUN];
1684 backgroundMap.addChild(this);
1685 this.lifetime = 30 * 24 * 3;
1686 this.addEventListener('enterframe', this.runEnterframe(this));
1687 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1690 runEnterframe:function(self){
1692 if(typeof e === "undefined")return;
1693 if(this.age%BASE_FPS === 0 && this.age !== 0){
1695 if(self.lifetime <= 0){
1696 this.parentNode.removeChild(this);
1697 ctl.backgroundMap.removeChild(this);
1698 ctl.removeObj(this);
1705 // runEnterframe: function(){
1706 // console.log("enterframe:" + this.id);
1709 var Okazari = enchant.Class.create(enchant.Sprite,{
1710 initialize: function(yukkuri){
1711 this.classname = "Okazari";
1712 if(yukkuri.myCode === "REIMU"){
1713 enchant.Sprite.call(this, 80, 32);
1714 this.image = game.assets[EResPathReimu.OKAZARI];
1715 this.x = -CHARA_WIDTH / 2;
1718 enchant.Sprite.call(this, 64, 64);
1719 this.image = game.assets[EResPath.OKAZARI];
1720 this.x = -CHARA_WIDTH / 2;
1721 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1723 this.yukkuri = yukkuri;
1725 getWidth: function(){
1727 // return this.width * this.yukkuri.myScaleX;
1729 getHeight: function(){
1731 // return this.height * this.yukkuri.myScaleY;
1734 var Address = enchant.Class.create({
1735 initialize: function(yukkuri){
1736 this.friendlyLv = 1;
1737 this.yukkuri = yukkuri;
1738 this.isGreeting = false;
1739 this.greetingWaitFrame = 0;
1741 "beginSayHello" : false,
1746 set:function(key, value){
1747 this.comMatrix[key] = value;
1750 return this.comMatrix[key];
1754 var Yukkuri = enchant.Class.create(ObjSprite,{
1755 initialize: function(x, y, grow){
1756 ObjSprite.call(this, 64, 64);
1757 this.searchObjectMang = new SearchObjectMang();
1759 this.myCode = "YUKKURI";
1760 this.myName = "ゆっくり";
1761 this.beforeHuntingFood = null;
1762 if(grow == EGrow.ADULT){
1767 else if(grow == EGrow.SUBADULT){
1768 this.myScaleX = 0.8;
1769 this.myScaleY = 0.8;
1772 else if(grow == EGrow.CHILD){
1773 this.myScaleX = 0.6;
1774 this.myScaleY = 0.6;
1777 else if(grow == EGrow.BABY){
1778 this.myScaleX = 0.3;
1779 this.myScaleY = 0.3;
1783 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1784 this.classname = "Yukkuri";
1785 this.addressBook = {};
1786 this.imgGroup = new SpriteGroup();
1787 this.imgBody = new SpriteGroup();
1788 this.imgGroup.id = guid();
1789 this.imgBody.id = guid();
1790 this.x = -CHARA_WIDTH / 2;
1791 this.y = -CHARA_HEIGHT / 2;
1794 this.image = game.assets[EResPath.YUKKURI_BASE];
1795 this.direction = EDirection.RIGHT;
1796 this.addEventListener('enterframe', this.runEnterframe);
1797 this.bodyStatus ={};
1798 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1799 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1800 this.walkAnimationStatus = EWalkAnimation.END;
1803 this.actionQueue = [];
1805 this.exValueHash = {};
1806 this.memoryHash = {};
1807 for(var _v in EExSkill){
1808 var key = EExSkill[_v];
1809 this.exLvHash[key] = 0;
1810 this.exValueHash[key] = 0;
1814 runEnterframe:function(){
1817 if(this.isDead())return;
1828 if(this.direction == EDirection.RIGHT){
1829 this.imgBody.scaleX = 1;
1831 else if(this.direction == EDirection.LEFT){
1832 this.imgBody.scaleX = -1;
1835 tweet:function(text){
1836 text = text.replace(/%name%/g, this.myName);
1837 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1839 moveTo:function(x, y, time){
1840 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1842 moveBy:function(x, y, time, eventFunctions){
1846 return self.imgGroup.x + x;
1849 return self.imgGroup.y + y;
1852 easing: enchant.Easing.SIN_EASEINOUT
1854 //-Event register [onactionstart,onactiontick,onactionend]
1855 if(eventFunctions !== undefined){
1856 for(var key in eventFunctions){
1857 params[key] = eventFunctions[key];
1860 return this.imgGroup.tl.tween(params);
1862 wait:function(frame, eventFunctions){
1863 this.moveBy(0,1,frame,eventFunctions);
1868 animation: function(){
1871 frame += plusFrameScale(frame, this.getMyScale());
1873 move -= plusFrameScale(move, this.getMyScale());
1874 if(this.walkAnimationStatus == EWalkAnimation.END){
1876 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1877 "onactionstart": function(e){
1878 this.walkAnimationStatus = EWalkAnimation.START;
1881 .moveByEx(0, move, frame, enchant.Easing.SWING,
1883 "onactionend": function(e){
1884 this.walkAnimationStatus = EWalkAnimation.END;
1889 this.imgBody.tl.loop();
1892 getMyScale: function(){
1893 return (this.myScaleX + this.myScaleY) / 2;
1895 getWidth: function(){
1896 return this.width * this.myScaleX;
1898 getHeight: function(){
1899 return this.height * this.myScaleY;
1902 return this.imgGroup.x;
1905 return this.imgGroup.y;
1908 this.imgGroup.x += x;
1910 // this.shadow.x += x;
1911 // this._tweet.x += x;
1914 this.imgGroup.y += y;
1916 // this.shadow.y += y;
1917 // this._tweet.y += y;
1919 // changeFace: function(erespath){
1920 // this.face.image = game.assets[erespath];
1922 loadParamsXML: function(url){
1923 var http = new JKL.ParseXML( url );
1924 return http.parse();
1926 runYukkuri: function(){
1927 if(this.param.hungry > 70){
1928 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1929 this.param.yukkuri -= 1;
1932 else if(this.param.hungry < 10){
1933 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1936 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1937 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1939 runHungry: function(){
1940 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1941 if(this.param.hungry >= 100)this.param.hungry = 100;
1943 runUnun: function(){
1944 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1945 if(this.param.unun >= 100)this.param.unun = 100;
1947 runSleep: function(){
1948 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1949 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1950 if(this.param.sleep >= 100){
1951 this.param.sleep = 100;
1955 runAddress: function(){
1956 for(var key in this.addressBook){
1957 var address = this.addressBook[key];
1959 if(address.isGreeting){
1960 address.greetingWaitFrame++;
1961 if(address.greetingWaitFrame >= DAY){
1962 address.greetingWaitFrame = 0;
1963 address.isGreeting = false;
1968 changeFace: function(){
1969 if(this.param.yukkuri >= 80){
1970 this.setFaceImage(EFace.HAPPY1);
1972 else if(this.param.yukkuri >= 50){
1973 this.setFaceImage(EFace.NORMAL);
1975 else if(this.param.yukkuri >= 30){
1976 this.setFaceImage(EFace.TIRED);
1978 else if(this.param.yukkuri >= 10){
1979 this.setFaceImage(EFace.CRY1);
1981 else if(this.param.yukkuri >= 1){
1982 this.setFaceImage(EFace.CRY2);
1985 getRange: function(){
1986 return this.param.range;
1988 isSleep: function(){
1989 return this.param.sleep >= 100;
1992 return this.param.yukkuri <= 0;
1994 isManpuku: function(){
1995 return this.param.hungry <= 20;
1997 isKuhuku: function(){
1998 return this.param.hungry >= 40;
2000 isVeryKuhuku: function(){
2001 return this.param.hungry >= 80;
2003 getYukkuri: function(){
2004 return this.param.yukkuri;
2006 setYukkuri: function(yukkuri){
2007 this.param.yukkuri = yukkuri;
2008 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2010 getHungry: function(){
2011 return this.param.hungry;
2013 setHungry: function(hungry){
2014 this.param.hungry = hungry;
2015 if(this.param.hungry < 0)this.param.hungry = 0;
2017 getUnun: function(){
2018 return this.param.unun;
2020 setUnun: function(unun){
2021 this.param.unun = unun;
2022 if(this.param.unun < 0)this.param.unun = 0;
2026 if(food instanceof Food){
2028 if(food.amount > 0){
2030 this.setHungry(this.param.hungry - food.getGive());
2031 this.setUnun(this.getUnun() + food.getGive() / 4);
2032 this.setYukkuri(this.getYukkuri() + 5);
2035 this.setYukkuri(this.getYukkuri() - 5);
2041 this.setHungry(this.param.hungry - food.give);
2042 this.setUnun(this.getUnun() + food.unun);
2043 this.setYukkuri(this.getYukkuri() + food.yukkuri);
2050 hunt:function(food){
2051 if(food.amount > 0){
2052 if(!this.isItemsMax()){
2054 this.items.push(food);
2055 this.setYukkuri(this.getYukkuri() + 1);
2061 declarePlace: function(place){
2064 getPlace:function(){
2067 isPlace: function(){
2068 return this.place !== null;
2072 if(this.direction == EDirection.RIGHT){
2073 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2075 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
2079 setBodyImage: function(ebody){
2080 var path = this.bodyStatus[ebody];
2081 this.image = game.assets[path];
2084 // this.imgBody.tl.pause();
2085 // this.imgGroup.tl.pause();
2086 this.imgBody.tl.clear();
2087 this.imgGroup.tl.clear();
2088 this.imgBody.tl.unloop();
2089 this.imgGroup.tl.unloop();
2093 tlResume: function(){
2094 // this.imgBody.tl.resume();
2095 // this.imgGroup.tl.resume();
2098 syncDirection:function(senderYukkuri){
2099 if(this.getX() > senderYukkuri.getX()){
2100 this.direction = EDirection.LEFT;
2101 senderYukkuri.direction = EDirection.RIGHT;
2103 this.direction = EDirection.RIGHT;
2104 senderYukkuri.direction = EDirection.LEFT;
2107 isCommunication: function(yukkuri){
2108 if(this.addressBook[yukkuri.id] === undefined) return true;
2109 if(this.addressBook[yukkuri.id].isGreeting) return false;
2112 addAddress: function(yukkuri){
2113 this.addressBook[yukkuri.id] = new Address(yukkuri);
2115 getAddress: function(yukkuri){
2116 if(this.addressBook[yukkuri.id] === undefined)return null;
2117 return this.addressBook[yukkuri.id];
2119 getStatusForDisplay: function (){
2121 var placeId = (this.place==null)?"無し" : this.place.id;
2122 ret += "ID " + this.id + "\n";
2123 ret += "プレイス " + placeId + "\n";
2124 ret += "ゆっくり " + this.getYukkuri() + "\n";
2125 ret += "空腹 " + this.getHungry() + "\n";
2126 ret += "うんうん " + this.getUnun() + "\n";
2127 ret += "もちもの " + this.items.length + "\n";
2128 ret += "debug " + this.action.status + "\n";
2131 isItemsMax:function(){
2132 return this.items.length >= this.param.items_max;
2134 getItems:function(){
2137 addSearchObject:function(esearch, node){
2138 this.searchObjectMang.add(esearch, node)
2140 clearSearchObject:function(){
2141 this.searchObjectMang.clear()
2143 setFaceImage: function(eface){
2144 var path = this.faceStatus[eface];
2145 this.face.image = game.assets[path];
2147 myScale: function(_scaleX, _scaleY){
2148 this.face.scale(_scaleX,_scaleY);
2149 if(this.myCode === "REIMU"){
2150 this.okazari.x = -CHARA_WIDTH / 2;
2151 this.okazari.x = -CHARA_WIDTH / 2 - CHARA_WIDTH / 8;
2152 this.okazari.y = -CHARA_HEIGHT / 3 - CHARA_HEIGHT/7;
2154 this.okazari.x = -CHARA_WIDTH /2;
2155 this.okazari.y = -CHARA_HEIGHT / 2 - CHARA_HEIGHT/6;
2158 this.okazari.scale(_scaleX,_scaleY);
2159 this.hear.scale(_scaleX,_scaleY);
2160 this.scale(_scaleX,_scaleY);
2161 this.shadow.scale(_scaleX, _scaleY);
2163 send: function(targetYukkuri){
2164 targetYukkuri.recv();
2166 recv: function(object, callback){
2167 this.actionQueue.push({
2169 actionStatus : EAction.COMMUNICATE_RECV,
2173 addExValue: function(eexskill, plus){
2174 this.exValueHash[eexskill] += plus;
2175 if(this.exValueHash[eexskill] >= 100){
2176 this.exLvHash[eexskill] = 1;
2179 getExValue: function(eexskill){
2180 return this.exValueHash[eexskill];
2182 getExSkill: function(eexskill){
2183 return this.exLvHash[eexskill];
2186 setMemory: function(ememory, value){
2187 this.memoryHash[ememory] = value;
2189 getMemory: function(ememory){
2190 return this.memoryHash[ememory];
2192 destruct: function(){
2196 var Marisa = enchant.Class.create(Yukkuri,{
2197 initialize: function(x, y, grow){
2198 Yukkuri.call(this,x,y, grow);
2199 this.classname = "Marisa";
2200 this.myCode = "MARISA";
2201 this.myName = "まりさ";
2203 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2204 // var json = net.load("./data/marisa/params.json");
2205 // this.param = json.root.param;
2206 this.param = MarisaParam;
2207 if(this.grow == EGrow.BABY){
2208 this.myName = "まりちゃ";
2209 this.param.range /= 4;
2211 else if(this.grow == EGrow.CHILD){
2212 this.param.range /= 3;
2214 else if(this.grow == EGrow.SUBADULT){
2215 this.param.range *= 0.8;
2217 this.shadow = new enchant.Sprite(64, 64);
2218 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2219 this.shadow.x = 0 + this.x;
2220 this.shadow.y = this.getWidth() / 16 + this.x;
2222 this._style.zIndex = 5;
2224 this.face = new enchant.Sprite(64, 64);
2225 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2226 this.face.x = -CHARA_WIDTH / 2;
2227 this.face.y = -CHARA_HEIGHT / 2;
2229 this.faceStatus ={};
2230 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2231 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2232 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2233 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2234 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2235 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2236 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2237 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2238 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2239 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2242 this.hear = new enchant.Sprite(64, 64);
2243 this.hear.image = game.assets[EResPath.MARISA_HEAR];
2244 this.hear.x = -CHARA_WIDTH / 2;
2245 this.hear.y = -CHARA_HEIGHT / 2;
2247 this.okazari = new Okazari(this);
2251 this.imgGroup.addChild(this.shadow);
2252 this.imgBody.addChild(this);
2253 this.imgBody.addChild(this.face);
2254 this.imgBody.addChild(this.hear);
2255 this.imgBody.addChild(this.okazari);
2256 this.myScale(this.myScaleX, this.myScaleY)
2257 if(this instanceof Player){
2258 // this.myScaleX = 0.5;
2259 // this.myScaleY = 0.5;
2261 this.budge = new enchant.Sprite(16, 16);
2262 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2263 this.imgBody.addChild(this.budge);
2264 this.budge.x -= this.getWidth()/2;
2265 this.budge.y -= this.getHeight()/2;
2266 this.budge.scale(this.myScaleX, this.myScaleX);
2268 this.imgGroup.width = this.getWidth();
2269 this.imgGroup.height = this.getHeight();
2270 this.imgGroup.addChild(this.imgBody);
2271 backgroundMap.addChild(this.imgGroup);
2272 this._tweet = new TTweet(148, 64);
2274 this.imgGroup.addChild(this._tweet);
2275 this.imgGroup.x = x;
2276 this.imgGroup.y = y;
2279 this.action = new Action(this);
2283 var Player = enchant.Class.create(Marisa,{
2284 initialize: function(x, y){
2285 // this.runEnterframe = function(){
2287 Marisa.call(this, x, y, EGrow.ADULT);
2288 this.classname = "Player";
2290 ctl.setPlayer(this);
2291 // this.removeEventListener('enterframe',this.runEnterframe);
2292 this.addEventListener('enterframe', function(){
2295 if(this.age%10 === 0 && this.age !== 0){
2296 // console.log("palyer:" + this.age);
2299 ///////////////////////////////////////////////
2300 //Action pattern debug
2301 if(game.input.left){
2302 // this.changeFace(EResPath.MARISA_FACE_TIRED);
2304 this.direction = EDirection.LEFT;
2306 if(game.input.right){
2308 this.direction = EDirection.RIGHT;
2313 if(game.input.down){
2317 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2318 ///////////////////////////////////////////////
2320 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2321 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
2323 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
2325 //- Display the circle of search range.
2326 // fieldBg.image.clear();
2327 // fieldBg.image.context.beginPath();
2328 // fieldBg.image.context.fillStyle = '#ff0000';
2329 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2330 // fieldBg.image.context.fill();
2334 var Reimu = enchant.Class.create(Yukkuri,{
2335 initialize: function(x, y, grow){
2336 Yukkuri.call(this,x,y, grow);
2337 this.classname = "Reimu";
2338 this.myCode = "REIMU";
2339 this.myName = "れいむ";
2341 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2342 // var json = net.load("./data/reimu/params.json");
2343 // this.param = json.root.param;
2344 this.param = ReimuParam;
2345 if(this.grow == EGrow.BABY){
2346 this.myName = "れいみゅ";
2347 this.param.range /= 4;
2349 else if(this.grow == EGrow.CHILD){
2350 this.param.range /= 3;
2352 else if(this.grow == EGrow.SUBADULT){
2353 this.param.range *= 0.8;
2355 this.shadow = new enchant.Sprite(64, 64);
2356 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2357 this.shadow.x = 0 + this.x;
2358 this.shadow.y = this.getWidth() / 16 + this.x;
2359 this.shadow.image._element.style.zIndex = 2;
2361 this._style.zIndex = 5;
2363 this.face = new enchant.Sprite(64, 64);
2364 this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2365 this.face.x = -CHARA_WIDTH / 2;
2366 this.face.y = -CHARA_HEIGHT / 2;
2367 this.face._style.zIndex = 0;
2369 this.faceStatus ={};
2370 this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2371 this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2372 this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2373 this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2374 this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2375 this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2376 this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2377 this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2378 this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2379 this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2382 this.hear = new enchant.Sprite(64, 64);
2383 this.hear.image = game.assets[EResPathReimu.HEAR];
2384 this.hear.x = -CHARA_WIDTH / 2;
2385 this.hear.y = -CHARA_HEIGHT / 2;
2387 this.sub1 = new enchant.Sprite(64, 64);
2388 this.sub1.image = game.assets[EResPathReimu.SUB1];
2389 this.sub1.x = -CHARA_WIDTH / 2;
2390 this.sub1.y = -CHARA_HEIGHT / 2;
2392 this.okazari = new Okazari(this);
2394 // this.imgGroup._style.zIndex = 1;
2397 this.imgGroup.addChild(this.shadow);
2398 this.imgBody.addChild(this.okazari);
2399 this.imgBody.addChild(this);
2400 this.imgBody.addChild(this.face);
2401 this.imgBody.addChild(this.hear);
2402 this.imgBody.addChild(this.sub1);
2403 this.myScale(this.myScaleX, this.myScaleY)
2404 if(this instanceof Player){
2405 // this.myScaleX = 0.5;
2406 // this.myScaleY = 0.5;
2408 this.budge = new enchant.Sprite(16, 16);
2409 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2410 this.imgBody.addChild(this.budge);
2411 this.budge.x -= this.getWidth()/2;
2412 this.budge.y -= this.getHeight()/2;
2413 this.budge.scale(this.myScaleX, this.myScaleX);
2415 this.imgGroup.width = this.getWidth();
2416 this.imgGroup.height = this.getHeight();
2417 this.imgGroup.addChild(this.imgBody);
2418 backgroundMap.addChild(this.imgGroup);
2419 this._tweet = new TTweet(148, 64);
2421 this.imgGroup.addChild(this._tweet);
2422 this.imgGroup.x = x;
2423 this.imgGroup.y = y;
2426 this.action = new Action(this);
2428 this.exLvHash[EExSkill.KEKKAI] = 1;
2429 this.exValueHash[EExSkill.KEKKAI] = 100;
2433 game.onload = function(){
2437 def.ObjSprite = ObjSprite;
2438 def.Yukkuri = Yukkuri;
2439 def.nodeSort = nodeSort;
2440 mangTouch = new MangTouch(ctl);
2441 mangMsg = new MangMsg(ctl);
2442 ctl.setDefined(def);
2443 backgroundMap.image = game.assets[EResPath.MAP0];
2444 backgroundMap.loadData(_mapData);
2445 backgroundMap.collisionData = _collisionData;
2447 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2448 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2449 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2450 fieldBg.image = fieldSurface;
2454 windowFront.image = windowSurface;
2457 windowFront.opacity = 0.5;
2459 windowSurface.context.fillStyle = '#000';
2460 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2463 menuSurface.context.fillStyle = '#000';
2464 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2465 menuBg.image = menuSurface;
2466 menuBg.x = EMenuPos.X;
2467 menuBg.y = EMenuPos.Y;
2468 backgroundMap.addChild(fieldBg);
2469 mangIcon = new MangIcon(ctl, menuBg);
2471 game.rootScene.addChild(backgroundMap);
2472 game.rootScene.addChild(windowFront);
2473 game.rootScene.addChild(menuBg);
2475 // var labelGroup = new LabelGroup();
2476 mangLabel = new MangLabel(ctl, menuBg);
2477 // var info = new Label("ゆっくり");
2478 // info.color = "#ffffff";
2479 // info.font = "14px 'Times New Roman'";
2481 // info.y = GAME_HEIGHT / 2;
2482 // labelGroup.addChild(info);
2483 // menuBg.addChild(labelGroup);
2486 // var food = new def.Food("apple", 200, 250);
2487 backgroundMap.addChild(foodGroup);
2488 // backgroundMap.addChild(placeGroup);
2489 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2490 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2491 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2492 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2493 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2494 // new Unun(100, 100);
2495 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2499 game.rootScene.addEventListener('touchstart', function (e) {
2500 game.touched = true;
2501 var mang = mangTouch.get(ctl.getCurrentCommand());
2504 game.rootScene.addEventListener('touchmove', function (e) {
2505 var mang = mangTouch.get(ctl.getCurrentCommand());
2508 game.rootScene.addEventListener('touchend', function (e) {
2509 var mang = mangTouch.get(ctl.getCurrentCommand());
2511 game.touched = false;
2515 game.rootScene.addEventListener('enterframe', function(){
2517 mangLabel.draw(player);
2518 if(this.age%BASE_FPS == 0 ){
2521 ctl.time += TIME_SPEED;
2523 this.addEventListener('enterframe', function(){
2524 //The priority processing of display instead of z-index
2526 backgroundMap.childNodes.sort(nodeSort);