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;
49 YUKKURI_BASE : './data/yukkuri_base.png',
50 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
51 YUKKURI_UNUN : './data/unun.png',
52 YUKKURI_SHADOW : './data/shadow.png',
53 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
54 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
55 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
56 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
57 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
58 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
59 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
60 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
61 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
62 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
63 MARISA_HEAR : './data/marisa/hear1.png',
64 MARISA_OKAZARI : './data/marisa/okazari.png',
65 OBJECT : './data/object.png',
66 MAP0 : './data/map0.png',
67 COMMAND : './data/command.png',
68 PLACE_TREE : './data/system/place_tree.png',
69 GRASS : './data/system/grass.png',
70 PLAYER_BADGE : './data/system/player_badge.png',
71 // PLACE_TREE : './data/system/rapture.png',
77 FACE_NORMAL : './data/reimu/face_normal1.png',
78 FACE_TIRED : './data/reimu/face_tired1.png',
79 FACE_ANGRY : './data/reimu/face_angry1.png',
80 FACE_CRY1 : './data/reimu/face_cry1.png',
81 FACE_CRY2 : './data/reimu/face_cry2.png',
82 FACE_EAT1 : './data/reimu/face_eat1.png',
83 FACE_EAT2 : './data/reimu/face_eat2.png',
84 FACE_HAPPY1 : './data/reimu/face_happy1.png',
85 FACE_HAPPY2 : './data/reimu/face_happy2.png',
86 FACE_SLEEP : './data/reimu/face_sleep1.png',
87 HEAR : './data/reimu/hear1.png',
88 OKAZARI : './data/reimu/okazari.png',
89 SUB1 : './data/reimu/sub1.png',
121 HEIGHT : GAME_HEIGHT,
127 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
138 MOVE_TO_EAT_START: 10,
139 MOVE_TO_EAT_UNDERWAY: 11,
143 UNUN_SMELL_START : 15,
144 UNUN_SMELL_WAIT : 16,
147 COMMUNICATE_START : 19,
148 COMMUNICATE_WAIT: 20,
149 COMMUNICATE_RECV: 21,
150 MOVE_TO_PLACE_START_HOMELESS: 22,
151 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
152 DECLARE_PLACE_HOMELESS: 24,
153 MOVE_TO_HUNT_START: 25,
186 LEARN_NO_FOOD_IN_PLACE:19,
188 var EWalkAnimation = {
218 NO_FOOD_IN_PLACE : 1,
224 var ObjSprite = enchant.Class.create(enchant.Sprite,{
225 initialize: function (w, h){
226 enchant.Sprite.call(this, w, h);
229 // // new BoxLabel(this.ctl,100, e.x, e.y);
230 // var box = new Box(this.ctl, 200, 200);
231 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
233 getStatusForDisplay: function (){
242 getWidth: function(){
245 getHeight: function(){
248 removeAll: function(){
255 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
266 //-Event register [onactionstart,onactiontick,onactionend]
267 if(eventFunctions !== undefined){
268 for(var key in eventFunctions){
269 params[key] = eventFunctions[key];
272 return this.tween(params);
274 function plusFrameScale(frame, scale){
275 return (frame/2) * (1 - scale)
280 include("./lang/ja.js");
281 window.onload = function(){
282 var nodeSort = function (a, b){
283 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
286 else if(typeof a.id === "undefined"){
289 else if(typeof b.id === "undefined"){
294 if(a instanceof Box && b instanceof Box){
297 if(a instanceof Box){
300 if(b instanceof Box){
303 if(a instanceof SpriteGroup){
307 if(b instanceof SpriteGroup){
312 if(a instanceof Place){
313 ay += Math.round(a.height * 0.7);
315 if(b instanceof Place){
316 by += Math.round(b.height * 0.7);
319 if(ay < by)return -1;
320 else if(ay > by)return 1;
321 if(a.id < b.id)return -1;
322 else if(a.id > b.id)return 1;
328 var def = new Object();
329 var foodGroup = new Group();
330 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
331 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
332 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
333 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
334 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
338 var tmpName = EResPathReimu.getName();
340 for(var _v in EResPathReimu){
341 if(typeof EResPathReimu[_v] === "function")continue;
342 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
348 for(var _v in EResPath){
349 _loadArr[i] = EResPath[_v];
352 game.preload(_loadArr);
353 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
354 var backgroundMap = new MapGroup(16, 16);
355 include("./class.js");
356 include("./ctrl.js");
359 ctl.setBackgroundMap(backgroundMap);
360 var Action = enchant.Class.create({
361 initialize: function (yukkuri){
362 this.status = EAction.THINK;
363 this.yukkuri = yukkuri;
364 this.isMoving = false;
365 this.targetNode = null;
367 getStatus: function(){
370 setStatus: function(eaction){
371 this.status = eaction;
374 if(this.yukkuri.isDead()){
375 this.status = EAction.DEAD;
377 // else if(this.yukkuri.isSleep()){
378 // this.status = EAction.SLEEP;
388 if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
390 this.setStatus(EAction.THINK);
391 console.log("wait cnt end");
394 case EAction.THINK_IN_HOME:
397 this.think_in_home();
399 case EAction.EAT_IN_HOME:
404 if(this.yukkuri.age%2 === 0){
405 this.yukkuri.changeFace();
407 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
410 case EAction.MOVE_TO_EAT_START:
411 this.move_to_eat_start();
413 case EAction.MOVE_TO_EAT_UNDERWAY:
419 case EAction.SLEEP_START:
422 case EAction.SLEEP_WAIT:
427 case EAction.EAT_START:
430 case EAction.EAT_WAIT:
432 case EAction.UNUN_START:
435 case EAction.UNUN_WAIT:
437 case EAction.MOVE_TO_COMMAND:
438 this.move_to_command();
440 case EAction.UNUN_SMELL_START:
441 this.unun_smell_start();
443 case EAction.COMMUNICATE_START:
444 this.communicate_start();
446 case EAction.COMMUNICATE_WAIT:
448 case EAction.COMMUNICATE_RECV:
450 case EAction.MOVE_TO_PLACE_START_HOMELESS:
451 this.move_to_place_start_homeless();
453 case EAction.DECLARE_PLACE_HOMELESS:
454 this.declare_place_homeless();
456 case EAction.MOVE_TO_HUNT_START:
457 this.move_to_hunt_start();
459 case EAction.HUNT_START:
462 case EAction.MOVE_GOTO_HOME:
463 this.move_goto_home();
465 case EAction.IN_HOME:
470 this.yukkuri.reverse();
472 // thinkHavePlace: function(){
473 // var date = ctl.getDate();
474 // if(this.yukkuri.isPlaceRange()){
477 // if(date === EDate.EVENING
478 // || date === EDate.NIGHT
479 // || date === EDate.MIDNIGHT
481 // this.setStatus(EAction.MOVE_GOTO_HOME);
484 // else if(date === EDate.EVENING){
485 // // if(this.yukkuri.isItemsMax()){
486 // // this.setStatus(EAction.IN_HOME);
489 // // this.setStatus(EAction.MOVE_TO_HUNT_START);
493 // if(this.yukkuri.isVeryKuhuku()){
497 // this.setStatus(EAction.MOVE_GOTO_HOME);
499 // else if(this.yukkuri.isSleep()){
500 // this.setStatus(EAction.SLEEP_START);
502 // else if(this.yukkuri.getUnun() >= 80){
503 // this.setStatus(EAction.UNUN_START);
506 // this.yukkuri.changeFace();
510 think_in_home: function(){
511 var date = ctl.getDate();
512 if((date === EDate.MIDNIGHT)
513 && !this.yukkuri.isSleep()
514 && !this.yukkuri.isVeryKuhuku()
518 "nextStatus":EAction.THINK_IN_HOME,
519 "myYukkuri": this.yukkuri
523 else if(date === EDate.EVENING){
526 else if(this.yukkuri.isVeryKuhuku() && this.yukkuri.getPlace().isFood()){
527 this.setStatus(EAction.EAT_IN_HOME);
530 //marisa is hunting move
531 if(this.yukkuri.beforeHuntingFood !== null){
532 new MoveToHuntEvent({
534 "targetNode": this.yukkuri.beforeHuntingFood,
536 "myYukkuri": this.yukkuri
540 this.setStatus(EAction.WALK);
544 eat_in_home: function(){
546 "targetNode": this.yukkuri.getPlace(),
548 "myYukkuri": this.yukkuri
551 move_to_eat_start : function(){
554 "targetNode": this.targetNode,
556 "myYukkuri": this.yukkuri
562 walk : function(retryCounter){
563 if(retryCounter > 15){
565 this.status = EAction.NONE;
566 console.log("retryCount over");
569 if(this.yukkuri.imgGroup.tl.queue.length === 0){
571 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
573 this.isMoving = false;
574 this.status = EAction.THINK;
578 var xpos = 150 + rand(40) - (retryCounter * 10);
579 var ypos = 150 + rand(40) - (retryCounter * 10);
582 this.yukkuri.vy = -ypos;
584 else if(rand(8) == 1){
585 this.yukkuri.vx = xpos;
586 this.yukkuri.vy = -ypos;
587 this.yukkuri.direction = EDirection.RIGHT;
589 else if(rand(8) == 2){
590 this.yukkuri.vx = xpos;
592 this.yukkuri.direction = EDirection.RIGHT;
594 else if(rand(8) == 3){
595 this.yukkuri.vx = xpos;
596 this.yukkuri.vy = ypos;
597 this.yukkuri.direction = EDirection.RIGHT;
599 else if(rand(8) == 4){
601 this.yukkuri.vy = ypos;
603 else if(rand(8) == 5){
604 this.yukkuri.vx = -xpos;
605 this.yukkuri.vy = ypos;
606 this.yukkuri.direction = EDirection.LEFT;
608 else if(rand(8) == 6){
609 this.yukkuri.vx = -xpos;
611 this.yukkuri.direction = EDirection.LEFT;
613 else if(rand(8) == 7){
614 this.yukkuri.vx = -xpos;
615 this.yukkuri.vy = -ypos;
616 this.yukkuri.direction = EDirection.LEFT;
618 if (this.yukkuri.vx || this.yukkuri.vy) {
619 var map = ctl.backgroundMap;
620 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
621 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
622 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
623 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
624 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
625 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
626 // console.log("X:" + this.yukkuri.moveX);
627 // console.log("Y:" + this.yukkuri.moveY);
628 this.isMoving = true;
629 this.yukkuri.reverse();
630 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
631 mangMsg.output(this.yukkuri,EMsg.WALK);
633 this.targetNode = null;
635 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
636 this.walk(retryCounter+1);
642 sleep_start: function(){
645 "myYukkuri": this.yukkuri
649 mangMsg.output(this.yukkuri, EMsg.DEAD);
650 this.yukkuri.tlPause();
651 this.yukkuri.setBodyImage(EBody.DEAD);
653 eat_start: function(){
656 "targetNode": this.targetNode,
658 "myYukkuri": this.yukkuri
662 unun_start: function(){
665 "myYukkuri": this.yukkuri
668 unun_smell_start: function(){
671 "myYukkuri": this.yukkuri
674 communicate_start:function(){
675 new ComSayHelloSendEvent({
677 "targetNode": this.targetNode,
679 "myYukkuri": this.yukkuri
682 move_to_place_start_homeless:function(){
683 new MoveToPlaceStartHomelessEvent({
684 "targetNode": this.targetNode,
686 "myYukkuri": this.yukkuri
689 declare_place_homeless:function(){
690 new DeclarePlaceHomelessEvent({
691 "targetNode": this.targetNode,
693 "myYukkuri": this.yukkuri
696 move_to_hunt_start:function(){
697 new MoveToHuntEvent({
699 "targetNode": this.targetNode,
701 "myYukkuri": this.yukkuri
704 hunt_start:function(){
707 "targetNode": this.targetNode,
709 "myYukkuri": this.yukkuri
712 move_goto_home:function(){
713 var place = this.yukkuri.getPlace();
714 new MoveGotoHomeEvent({
718 "myYukkuri": this.yukkuri
722 var place = this.yukkuri.getPlace();
727 "myYukkuri": this.yukkuri
730 move_to_command: function(){
734 this.yukkuri.clearSearchObject();
735 var nodes = ctl.getObjs();
739 for (var key in nodes) {
740 var node = nodes[key];
741 if(this.yukkuri.id === node.id)continue;
745 && !(this.targetNode instanceof Unun)
746 && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
748 this.yukkuri.addSearchObject(ESearch.UNUN, node);
751 else if (node instanceof Food && node.amount > 0) {
752 if(this.yukkuri.within(node, this.yukkuri.getRange())){
753 this.yukkuri.addSearchObject(ESearch.FOOD, node);
757 else if(node instanceof Yukkuri){
758 if(this.yukkuri.within(node, this.yukkuri.getRange())){
759 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
763 else if(node instanceof Place){
764 if(this.yukkuri.within(node, this.yukkuri.getRange())){
765 this.yukkuri.addSearchObject(ESearch.PLACE, node);
769 this.status = EAction.WALK;
773 * Range範囲内のObjSprを管理する
774 * 注意!:ゆっくりプレイスを持って入るもののみ使用される
778 var SearchObjectMang = enchant.Class.create({
779 initialize: function (){
784 for(var key in ESearch){
785 var esearch = ESearch[key];
786 this.datas[esearch] = [];
789 add :function(esearch, node){
790 this.datas[esearch].push(node);
793 for(var key in ESearch){
794 var esearch = ESearch[key];
795 this.datas[esearch].length = 0;
797 // this.datas.length = 0;
800 get:function (esearch){
801 return this.datas[esearch];
803 getNear:function (esearch, yukkuri){
804 var objects = this.datas[esearch];
805 var nearDistance = null;
807 for(var i=0;i<objects.length;i++){
808 var object = objects[i];
809 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
810 if(nearDistance === null || nearDistance > nowDistance){
811 nearDistance = nowDistance;
817 callEvent: function(yukkuri){
818 if(yukkuri.isItemsMax() && yukkuri.isPlace()){
819 yukkuri.action.targetNode = yukkuri.getPlace();
820 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
823 if(yukkuri.isVeryKuhuku()){
825 var foods = this.get(ESearch.FOOD);
826 if(foods.length > 0){
827 var foods = this.get(ESearch.FOOD);
828 food = this.getNear(ESearch.FOOD, yukkuri);
830 yukkuri.action.targetNode = food;
831 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
835 if(yukkuri.getMemory(EMemory.FOOD_IN_PLACE) === 0 && yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
836 yukkuri.action.setStatus(EAction.WALK);
840 if(foods.length === 0 && yukkuri.isPlace()){
842 yukkuri.action.targetNode = yukkuri.getPlace();
843 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
849 if(yukkuri.isSleep()){
850 yukkuri.action.setStatus(EAction.SLEEP_START);
854 else if(yukkuri.getUnun() >= 80){
855 yukkuri.action.setStatus(EAction.UNUN_START);
860 if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
861 food = this.getNear(ESearch.FOOD, yukkuri);
863 yukkuri.action.targetNode = food;
864 yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
868 ununs = this.get(ESearch.UNUN);
869 if(ununs.length !== 0){
870 yukkuri.action.targetNode = yukkuri.getPlace();
871 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
874 var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
875 if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
876 yukkuri.action.targetNode = searchYukkuri;
877 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
880 if(!yukkuri.isPlace()){
881 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
882 if(searchYukkuri != null && !searchYukkuri.isOwner()){
883 yukkuri.action.targetNode = searchYukkuri;
884 yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
888 yukkuri.action.setStatus(EAction.WALK);
893 var Event = enchant.Class.create({
894 initialize: function (_data){
897 onactionstart:function(self){
898 return this._onactionstart;
900 _onactionstart:function(e){
901 if(typeof e === "undefined")return;
903 onactiontick:function(self){
905 if(typeof e === "undefined")return;
908 onactionend:function(self){
910 if(typeof e === "undefined")return;
914 var WalkEvent = enchant.Class.create(Event,{
915 initialize: function (_data){
917 this.yukkuri = _data.myYukkuri;
918 this.action = _data.action;
920 mangMsg.output(this.yukkuri, EMsg.SLEEP);
921 this.action.setStatus(EAction.SLEEP_WAIT);
922 this.yukkuri.setFaceImage(EFace.SLEEP);
923 this.yukkuri.tlPause();
925 this.yukkuri.addEventListener('enterframe', function() {
926 var yukkuri = self.yukkuri;
934 var SleepEvent = enchant.Class.create(Event,{
935 initialize: function (_data){
937 this.yukkuri = _data.myYukkuri;
938 this.action = _data.action;
940 mangMsg.output(this.yukkuri, EMsg.SLEEP);
941 this.action.setStatus(EAction.SLEEP_WAIT);
942 this.yukkuri.setFaceImage(EFace.SLEEP);
943 this.yukkuri.tlPause();
946 this.yukkuri.addEventListener('enterframe', function() {
947 var yukkuri = self.yukkuri;
948 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
949 if(yukkuri.param.sleep <= 0){
950 yukkuri.param.sleep = 0;
951 this.removeEventListener("enterframe",arguments.callee);
952 mangMsg.output(self.yukkuri, EMsg.GET_UP);
953 yukkuri.setFaceImage(EFace.NORMAL);
955 // self.action.setStatus(EAction.WAIT);
956 if(self.data.nextStatus !== undefined){
957 self.action.setStatus(self.data.nextStatus);
959 self.action.setStatus(EAction.THINK);
966 var UnunEvent = enchant.Class.create(Event,{
967 initialize: function (_data){
969 this.yukkuri = _data.myYukkuri;
970 this.action = _data.action;
971 this.action.setStatus(EAction.UNUN_WAIT);
972 mangMsg.output(this.yukkuri, EMsg.UNUN);
973 this.yukkuri.setFaceImage(EFace.HAPPY2);
976 this.yukkuri.wait(sec, {
977 "onactionend": this.onactionend(this)
980 onactionend:function(self){
982 if(typeof e === "undefined")return;
984 self.action.setStatus(EAction.WAIT);
985 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
987 "waitframe": FPS * 1.5,
988 "action": self.action,
989 "myYukkuri": self.yukkuri
994 var WaitEvent = enchant.Class.create(Event,{
995 initialize: function (_data){
997 this.yukkuri = _data.myYukkuri;
998 this.action = _data.action;
999 this.waitframe = _data.waitframe;
1000 this.yukkuri.wait(this.waitframe, {
1001 "onactionstart": this.onactionstart(this),
1002 "onactiontick": this.onactiontick(this),
1003 "onactionend": this.onactionend(this)
1006 onactionend:function(self){
1008 if(typeof e === "undefined")return;
1009 self.action.setStatus(EAction.THINK);
1013 var UnunSmellEvent = enchant.Class.create(Event,{
1014 initialize: function (_data){
1016 this.yukkuri = _data.myYukkuri;
1017 this.action = _data.action;
1018 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
1019 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
1020 this.yukkuri.setFaceImage(EFace.CRY1);
1022 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1023 this.yukkuri.wait(sec, {
1024 "onactionend": this.onactionend(this)
1027 onactionend:function(self){
1029 if(typeof e === "undefined")return;
1030 self.action.setStatus(EAction.WALK);
1035 var EatEvent = enchant.Class.create(Event,{
1036 initialize: function (_data){
1038 this.yukkuri = _data.myYukkuri;
1039 this.food = _data.targetNode;
1040 this.action = _data.action;
1041 this.action.setStatus(EAction.EAT_WAIT);
1044 var sec = BASE_FPS * 3;
1045 if(this.yukkuri.eat(this.food)){
1046 mangMsg.output(this.yukkuri, EMsg.EAT);
1047 this.yukkuri.setFaceImage(EFace.EAT2);
1050 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1051 this.yukkuri.setFaceImage(EFace.CRY2);
1053 this.yukkuri.wait(sec, {
1054 "onactionend": this.onactionend(this)
1057 onactionend:function(self){
1059 if(typeof e === "undefined")return;
1060 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1061 self.action.setStatus(EAction.THINK);
1062 self.yukkuri.setFaceImage(EFace.NORMAL);
1064 self.action.setStatus(EAction.EAT_START);
1071 * -When yukkuri find Food.
1074 * targetNode: enchant.Node
1078 var MoveToEatEvent = enchant.Class.create(Event,{
1079 initialize: function (_data){
1081 this.yukkuri = this.data.myYukkuri;
1082 this.action = this.data.action;
1084 var yukkuri = this.yukkuri;
1085 var node = this.data.targetNode;
1087 if(this.data.type == "food"){
1088 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1089 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1090 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1091 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1092 var frame = distance + distance/5 + 1;
1093 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1094 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1097 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1098 "onactionstart": this.onactionstart(this),
1099 "onactiontick": this.onactiontick(this),
1100 "onactionend": this.onactionend(this)
1104 onactionstart:function(self){
1106 if(typeof e === "undefined")return;
1107 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1110 onactiontick:function(self){
1112 if(typeof e === "undefined")return;
1115 onactionend:function(self){
1117 if(typeof e === "undefined")return;
1118 self.action.setStatus(EAction.EAT_START);
1122 var MoveToHuntEvent = enchant.Class.create(Event,{
1123 initialize: function (_data){
1125 this.yukkuri = this.data.myYukkuri;
1126 this.action = this.data.action;
1128 var yukkuri = this.yukkuri;
1129 var node = this.data.targetNode;
1132 var nodeWidth = node.width;
1133 var nodeHeight = node.height;
1137 if(this.data.type == "food"){
1138 this.action.setStatus(EAction.WAIT);
1139 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1140 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1141 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1142 var frame = distance + distance/5 + 1;
1143 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1144 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1146 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1148 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1149 "onactionend": this.onactionend(this)
1153 onactionend:function(self){
1155 if(typeof e === "undefined")return;
1156 self.action.setStatus(EAction.HUNT_START);
1160 var HuntStartEvent = enchant.Class.create(Event,{
1161 initialize: function (_data){
1162 Event.call(this, _data);
1165 this.yukkuri = _data.myYukkuri;
1166 this.food = _data.targetNode;
1167 this.action = _data.action;
1168 this.action.setStatus(EAction.WAIT);
1169 this.huntingStatus = "hunting";
1171 this.yukkuri.beforeHuntingFood = this.food;
1172 var sec = BASE_FPS * 8;
1173 if(this.yukkuri.hunt(this.food)){
1174 this.huntingStatus = "hunting";
1175 mangMsg.output(this.yukkuri, EMsg.HUNTING_MESSAGE);
1176 this.yukkuri.setFaceImage(EFace.HAPPY1);
1178 if(this.yukkuri.isItemsMax()){
1180 this.huntingStatus = "return";
1181 // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1182 this.yukkuri.setFaceImage(EFace.NORMAL);
1185 this.huntingStatus = "cry";
1186 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1187 this.yukkuri.setFaceImage(EFace.CRY2);
1191 this.yukkuri.wait(sec, {
1192 "onactiontick": this.onactiontick(this),
1193 "onactionend": this.onactionend(this)
1196 onactiontick:function(self){
1198 if(typeof e === "undefined")return;
1200 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 1){
1201 if(this.age%(BASE_FPS * 3) == 0){
1202 // mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1203 mangMsg.output(self.yukkuri, EMsg.HUNTING_MESSAGE);
1208 onactionend:function(self){
1210 if(typeof e === "undefined")return;
1211 if(self.huntingStatus == "hunting"){
1212 if(self.yukkuri.isItemsMax()){
1213 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1214 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1216 self.action.setStatus(EAction.HUNT_START);
1219 else if(self.huntingStatus == "return"){
1220 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1222 else if(self.huntingStatus === "cry"){
1223 // self.action.setStatus(EAction.THINK);
1224 self.action.setStatus(EAction.WALK);
1231 this.yukkuri = null;
1236 var MoveGotoHomeEvent = enchant.Class.create(Event,{
1237 initialize: function (_data){
1239 this.yukkuri = this.data.myYukkuri;
1240 this.action = this.data.action;
1242 var yukkuri = this.yukkuri;
1243 var place = this.data.targetNode;
1245 if(this.data.type == "hunt_end"){
1246 this.action.setStatus(EAction.WAIT);
1247 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1248 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1249 // console.log("place.x:" + place.x);
1250 // console.log("place.y:" + place.y);
1251 // console.log("yukkuri.getX():" + yukkuri.getX());
1252 // console.log("yukkuri.getY():" + yukkuri.getY());
1253 // console.log("yukkuri.vx:" + yukkuri.vx);
1254 // console.log("yukkuri.vy:" + yukkuri.vy);
1255 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1256 var frame = distance + distance/2 + 1 ;
1257 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1258 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1260 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1262 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1263 "onactiontick": this.onactiontick(this),
1264 "onactionend": this.onactionend(this)
1268 onactiontick:function(self){
1270 if(typeof e === "undefined")return;
1271 if(this.age%(BASE_FPS * 5) == 0){
1272 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1276 onactionend:function(self){
1278 if(typeof e === "undefined")return;
1279 self.action.setStatus(EAction.IN_HOME);
1285 this.yukkuri = null;
1289 var InHomeEvent = enchant.Class.create(Event,{
1290 initialize: function (_data){
1292 this.yukkuri = this.data.myYukkuri;
1293 this.action = this.data.action;
1295 var yukkuri = this.yukkuri;
1296 var place = this.data.targetNode;
1298 if(yukkuri.isVeryKuhuku()){
1300 yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1301 this.action.setStatus(EAction.EAT_IN_HOME);
1304 yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 0);
1306 if(yukkuri.getExSkill(EExSkill.NO_FOOD_IN_PLACE) >= 1){
1307 mangMsg.output(yukkuri, EMsg.LEARN_NO_FOOD_IN_PLACE);
1308 this.action.setStatus(EAction.THINK);
1311 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1312 yukkuri.addExValue(EExSkill.NO_FOOD_IN_PLACE, 50);
1317 this.action.setStatus(EAction.WAIT);
1318 var items = this.yukkuri.getItems();
1319 if(items.length > 0){
1320 place.setItems(items);
1324 var sec = BASE_FPS * 10;
1325 if(place.isFood())yukkuri.setMemory(EMemory.FOOD_IN_PLACE, 1);
1326 this.yukkuri.wait(sec, {
1327 "onactiontick": this.onactiontick(this),
1328 "onactionend": this.onactionend(this)
1331 onactiontick:function(self){
1333 if(typeof e === "undefined")return;
1334 if(this.age%(BASE_FPS * 5) == 0){
1335 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1339 onactionend:function(self){
1341 if(typeof e === "undefined")return;
1342 self.action.setStatus(EAction.THINK_IN_HOME);
1346 var EatInHomeEvent = enchant.Class.create(Event,{
1347 initialize: function (_data){
1349 this.yukkuri = _data.myYukkuri;
1350 this.place = _data.targetNode;
1351 this.action = _data.action;
1352 this.action.setStatus(EAction.EAT_WAIT);
1354 var sec = BASE_FPS * 3;
1355 var foodHash = this.place.getFoodHash();
1356 if(foodHash !== false && this.yukkuri.eat(foodHash)){
1357 mangMsg.output(this.yukkuri, EMsg.EAT);
1358 this.yukkuri.setFaceImage(EFace.EAT2);
1361 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1362 this.yukkuri.setFaceImage(EFace.CRY2);
1365 this.yukkuri.wait(sec, {
1366 "onactionend": this.onactionend(this)
1369 onactionend:function(self){
1371 if(typeof e === "undefined")return;
1372 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1373 self.action.setStatus(EAction.EAT_IN_HOME);
1375 // new EatInHomeEvent({
1376 // "targetNode": self.place,
1377 // "action": self.action,
1378 // "myYukkuri": self.yukkuri
1381 self.action.setStatus(EAction.THINK_IN_HOME);
1382 self.yukkuri.setFaceImage(EFace.NORMAL);
1389 var MoveCommandEvent = enchant.Class.create(Event,{
1390 initialize: function (_data){
1392 this.yukkuri = this.data.myYukkuri;
1393 this.action = this.data.action;
1394 this.vx = this.data.vx;
1395 this.vy = this.data.vy;
1397 var yukkuri = this.yukkuri;
1398 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1399 yukkuri.vx = node.x - yukkuri.getX();
1400 yukkuri.vy = node.y - yukkuri.getY();
1401 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1402 var frame = distance + 1;
1403 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1405 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1406 "onactionstart": this.onactionstart(this),
1407 "onactiontick": this.onactiontick(this),
1408 "onactionend": this.onactionend(this)
1411 onactionstart:function(self){
1413 if(typeof e === "undefined")return;
1416 onactiontick:function(self){
1418 if(typeof e === "undefined")return;
1421 onactionend:function(self){
1423 if(typeof e === "undefined")return;
1424 self.action.setStatus(EAction.THINK);
1429 * Say hello contact to send communication .
1431 var ComSayHelloSendEvent = enchant.Class.create(Event,{
1432 initialize: function (_data){
1434 this.yukkuri = _data.myYukkuri;
1435 this.targetYukkuri = _data.targetNode;
1436 this.action = _data.action;
1437 this.action.setStatus(EAction.COMMUNICATE_WAIT);
1438 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1441 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1442 this.targetYukkuri.tlPause();
1443 this.yukkuri.tlPause();
1444 this.yukkuri.syncDirection(this.targetYukkuri);
1446 this.yukkuri.addAddress(this.targetYukkuri);
1447 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1449 var sec = BASE_FPS * 2;
1450 this.yukkuri.wait(sec, {
1451 "onactiontick": this.onactiontick(this),
1452 "onactionend": this.onactionend(this)
1455 onactiontick:function(self){
1457 if(typeof e === "undefined")return;
1460 onactionend:function(self){
1462 if(typeof e === "undefined")return;
1463 new ComSayHelloRecvEvent({
1465 "targetNode": self.yukkuri,
1466 "action": self.targetYukkuri.action,
1467 "myYukkuri": self.targetYukkuri
1472 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1473 initialize: function (_data){
1475 this.yukkuri = _data.myYukkuri;
1476 this.targetYukkuri = _data.targetNode;
1477 this.action = _data.action;
1478 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1479 this.yukkuri.addAddress(this.targetYukkuri);
1480 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1482 var sec = BASE_FPS * 2;
1483 this.yukkuri.wait(sec, {
1484 "onactiontick": this.onactiontick(this),
1485 "onactionend": this.onactionend(this)
1488 onactiontick:function(self){
1490 if(typeof e === "undefined")return;
1493 onactionend:function(self){
1495 if(typeof e === "undefined")return;
1496 self.action.setStatus(EAction.THINK);
1498 self.yukkuri.action.setStatus(EAction.THINK);
1499 self.yukkuri.animation();
1500 self.targetYukkuri.action.setStatus(EAction.THINK);
1501 self.targetYukkuri.animation();
1505 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1506 initialize: function (_data){
1508 this.yukkuri = this.data.myYukkuri;
1509 this.action = this.data.action;
1511 var yukkuri = this.yukkuri;
1512 var node = this.data.targetNode;
1514 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1515 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
1516 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1517 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1518 var frame = distance + distance/5 + 1;
1519 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1521 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1524 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1525 "onactionend": this.onactionend(this)
1528 onactionend:function(self){
1530 if(typeof e === "undefined")return;
1531 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1533 self.yukkuri = null;
1538 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1539 initialize: function (_data){
1541 this.yukkuri = _data.myYukkuri;
1542 this.place = _data.targetNode;
1543 this.action = _data.action;
1544 this.action.setStatus(EAction.WAIT);
1547 var sec = BASE_FPS * 3;
1548 this.yukkuri.declarePlace(this.place);
1549 this.place.setOwner(this.yukkuri);
1550 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1552 this.yukkuri.setFaceImage(EFace.NORMAL);
1553 this.yukkuri.wait(sec, {
1554 "onactionend": this.onactionend(this)
1557 onactionend:function(self){
1559 if(typeof e === "undefined")return;
1560 self.action.setStatus(EAction.THINK);
1565 var Food = enchant.Class.create(ObjSprite,{
1566 initialize: function (type, x, y){
1567 this.classname = "Food";
1568 //一つにつきgiveの値分、hunguryを減少させられる
1569 if(type == "apple"){
1570 ObjSprite.call(this,16,16);
1571 this.image = game.assets[EResPath.OBJECT];
1575 }else if(type == "grass"){
1576 ObjSprite.call(this,64,64);
1577 this.image = game.assets[EResPath.GRASS];
1584 foodGroup.addChild(this);
1585 this.addEventListener('enterframe', function(){
1586 if(this.amount <= 0){
1591 getAmount: function(){
1594 getGive: function(){
1598 var Place = enchant.Class.create(ObjSprite,{
1599 initialize: function (type, x, y){
1600 ObjSprite.call(this,128,128);
1601 this.image = game.assets[EResPath.PLACE_TREE];
1602 this.x = x - this.width / 2;
1603 this.y = y - this.height / 2;
1604 backgroundMap.addChild(this);
1607 for(var key in EFood){
1608 var efood = EFood[key];
1609 this.foods[efood] = 0;
1611 // this.addEventListener('enterframe', function(){
1612 // if(this.age%10 === 0 && this.age !== 0){
1613 // console.log("x/y " + this.x + "/" + this.y);
1615 // if(game.input.left){
1618 // if(game.input.right){
1621 // if(game.input.up){
1624 // if(game.input.down){
1629 getStatusForDisplay: function(){
1632 if(this.owner == null)ownerId = "なし";
1633 else ownerId = this.owner.id;
1634 ret += "プレイスID " + this.id + "\n";
1635 ret += "オーナーID " + ownerId + "\n";
1636 ret += "食料うめぇ " + this.foods[EFood.GREAT] + "\n";
1637 ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1638 ret += "食料にがにが " + this.foods[EFood.BAD] + "\n";
1641 setItems:function(items){
1642 var len = items.length;
1643 for(var i=0; i<len; i++){
1644 var item = items[i];
1645 if(item instanceof Food){
1646 this.foods[EFood.NORMAL]++;
1653 for(var key in EFood){
1654 var efood = EFood[key];
1655 ret += this.foods[efood];
1659 getFoodHash:function(){
1660 if(this.foods[EFood.GREAT] !== 0){
1661 this.foods[EFood.GREAT]--;
1662 return {give:20,yukkuri:15,unun:20};
1664 else if(this.foods[EFood.NORMAL] !== 0){
1665 this.foods[EFood.NORMAL]--;
1666 return {give:10,yukkuri:5,unun:10};
1668 else if(this.foods[EFood.BAD] !== 0){
1669 this.foods[EFood.BAD]--;
1670 return {give:10,yukkuri:-2,unun:10};
1674 setOwner: function(yukkuri){
1675 this.owner = yukkuri;
1677 isOwner: function(){
1678 return this.owner !== null;
1681 var Unun = enchant.Class.create(ObjSprite,{
1682 initialize: function (x, y){
1683 this.classname = "Unun";
1684 ObjSprite.call(this,32,32);
1685 this.image = game.assets[EResPath.YUKKURI_UNUN];
1688 backgroundMap.addChild(this);
1689 this.lifetime = 30 * 24 * 3;
1690 this.addEventListener('enterframe', this.runEnterframe(this));
1691 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1694 runEnterframe:function(self){
1696 if(typeof e === "undefined")return;
1697 if(this.age%BASE_FPS === 0 && this.age !== 0){
1699 if(self.lifetime <= 0){
1700 this.parentNode.removeChild(this);
1701 ctl.backgroundMap.removeChild(this);
1702 ctl.removeObj(this);
1709 // runEnterframe: function(){
1710 // console.log("enterframe:" + this.id);
1713 var Okazari = enchant.Class.create(enchant.Sprite,{
1714 initialize: function(yukkuri){
1715 this.classname = "Okazari";
1716 if(yukkuri.myCode === "REIMU"){
1717 enchant.Sprite.call(this, 80, 32);
1718 this.image = game.assets[EResPathReimu.OKAZARI];
1719 this.x = -CHARA_WIDTH / 2 - 1;
1722 enchant.Sprite.call(this, 64, 64);
1723 this.image = game.assets[EResPath.MARISA_OKAZARI];
1724 this.x = -CHARA_WIDTH / 2;
1725 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1727 this.yukkuri = yukkuri;
1729 getWidth: function(){
1731 // return this.width * this.yukkuri.myScaleX;
1733 getHeight: function(){
1735 // return this.height * this.yukkuri.myScaleY;
1738 var Address = enchant.Class.create({
1739 initialize: function(yukkuri){
1740 this.friendlyLv = 1;
1741 this.yukkuri = yukkuri;
1742 this.isGreeting = false;
1743 this.greetingWaitFrame = 0;
1745 "beginSayHello" : false,
1750 set:function(key, value){
1751 this.comMatrix[key] = value;
1754 return this.comMatrix[key];
1758 var Yukkuri = enchant.Class.create(ObjSprite,{
1759 initialize: function(x, y, grow){
1760 ObjSprite.call(this, 64, 64);
1761 this.searchObjectMang = new SearchObjectMang();
1763 this.myCode = "YUKKURI";
1764 this.myName = "ゆっくり";
1765 this.beforeHuntingFood = null;
1766 if(grow == EGrow.ADULT){
1771 else if(grow == EGrow.SUBADULT){
1772 this.myScaleX = 0.8;
1773 this.myScaleY = 0.8;
1776 else if(grow == EGrow.CHILD){
1777 this.myScaleX = 0.6;
1778 this.myScaleY = 0.6;
1781 else if(grow == EGrow.BABY){
1782 this.myScaleX = 0.3;
1783 this.myScaleY = 0.3;
1787 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1788 this.classname = "Yukkuri";
1789 this.addressBook = {};
1790 this.imgGroup = new SpriteGroup();
1791 this.imgBody = new SpriteGroup();
1792 this.imgGroup.id = guid();
1793 this.imgBody.id = guid();
1794 this.x = -CHARA_WIDTH / 2;
1795 this.y = -CHARA_HEIGHT / 2;
1798 this.image = game.assets[EResPath.YUKKURI_BASE];
1799 this.direction = EDirection.RIGHT;
1800 this.addEventListener('enterframe', this.runEnterframe);
1801 this.bodyStatus ={};
1802 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1803 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1804 this.walkAnimationStatus = EWalkAnimation.END;
1807 this.actionQueue = [];
1809 this.exValueHash = {};
1810 this.memoryHash = {};
1811 for(var _v in EExSkill){
1812 var key = EExSkill[_v];
1813 this.exLvHash[key] = 0;
1814 this.exValueHash[key] = 0;
1818 runEnterframe:function(){
1821 if(this.isDead())return;
1832 if(this.direction == EDirection.RIGHT){
1833 this.imgBody.scaleX = 1;
1835 else if(this.direction == EDirection.LEFT){
1836 this.imgBody.scaleX = -1;
1839 tweet:function(text){
1840 text = text.replace(/%name%/g, this.myName);
1841 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1843 moveTo:function(x, y, time){
1844 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1846 moveBy:function(x, y, time, eventFunctions){
1850 return self.imgGroup.x + x;
1853 return self.imgGroup.y + y;
1856 easing: enchant.Easing.SIN_EASEINOUT
1858 //-Event register [onactionstart,onactiontick,onactionend]
1859 if(eventFunctions !== undefined){
1860 for(var key in eventFunctions){
1861 params[key] = eventFunctions[key];
1864 return this.imgGroup.tl.tween(params);
1866 wait:function(frame, eventFunctions){
1867 this.moveBy(0,1,frame,eventFunctions);
1872 animation: function(){
1875 frame -= plusFrameScale(frame, this.getMyScale()) / 2;
1877 move -= plusFrameScale(move, this.getMyScale());
1878 if(this.walkAnimationStatus == EWalkAnimation.END){
1880 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1881 "onactionstart": function(e){
1882 this.walkAnimationStatus = EWalkAnimation.START;
1885 .moveByEx(0, move, frame, enchant.Easing.SWING,
1887 "onactionend": function(e){
1888 this.walkAnimationStatus = EWalkAnimation.END;
1893 this.imgBody.tl.loop();
1896 getMyScale: function(){
1897 return (this.myScaleX + this.myScaleY) / 2;
1899 getWidth: function(){
1900 return this.width * this.myScaleX;
1902 getHeight: function(){
1903 return this.height * this.myScaleY;
1906 return this.imgGroup.x;
1909 return this.imgGroup.y;
1912 this.imgGroup.x += x;
1914 // this.shadow.x += x;
1915 // this._tweet.x += x;
1918 this.imgGroup.y += y;
1920 // this.shadow.y += y;
1921 // this._tweet.y += y;
1923 // changeFace: function(erespath){
1924 // this.face.image = game.assets[erespath];
1926 loadParamsXML: function(url){
1927 var http = new JKL.ParseXML( url );
1928 return http.parse();
1930 runYukkuri: function(){
1931 if(this.param.hungry > 70){
1932 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1933 this.param.yukkuri -= 1;
1936 else if(this.param.hungry < 10){
1937 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1940 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1941 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1943 runHungry: function(){
1944 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1945 if(this.param.hungry >= 100)this.param.hungry = 100;
1947 runUnun: function(){
1948 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1949 if(this.param.unun >= 100)this.param.unun = 100;
1951 runSleep: function(){
1952 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1953 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1954 if(this.param.sleep >= 100){
1955 this.param.sleep = 100;
1959 runAddress: function(){
1960 for(var key in this.addressBook){
1961 var address = this.addressBook[key];
1963 if(address.isGreeting){
1964 address.greetingWaitFrame++;
1965 if(address.greetingWaitFrame >= DAY){
1966 address.greetingWaitFrame = 0;
1967 address.isGreeting = false;
1972 changeFace: function(){
1973 if(this.param.yukkuri >= 80){
1974 this.setFaceImage(EFace.HAPPY1);
1976 else if(this.param.yukkuri >= 50){
1977 this.setFaceImage(EFace.NORMAL);
1979 else if(this.param.yukkuri >= 30){
1980 this.setFaceImage(EFace.TIRED);
1982 else if(this.param.yukkuri >= 10){
1983 this.setFaceImage(EFace.CRY1);
1985 else if(this.param.yukkuri >= 1){
1986 this.setFaceImage(EFace.CRY2);
1989 getRange: function(){
1990 return this.param.range;
1992 isSleep: function(){
1993 return this.param.sleep >= 100;
1996 return this.param.yukkuri <= 0;
1998 isManpuku: function(){
1999 return this.param.hungry <= 20;
2001 isKuhuku: function(){
2002 return this.param.hungry >= 40;
2004 isVeryKuhuku: function(){
2005 return this.param.hungry >= 80;
2007 getYukkuri: function(){
2008 return this.param.yukkuri;
2010 setYukkuri: function(yukkuri){
2011 this.param.yukkuri = yukkuri;
2012 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
2014 getHungry: function(){
2015 return this.param.hungry;
2017 setHungry: function(hungry){
2018 this.param.hungry = hungry;
2019 if(this.param.hungry < 0)this.param.hungry = 0;
2021 getUnun: function(){
2022 return this.param.unun;
2024 setUnun: function(unun){
2025 this.param.unun = unun;
2026 if(this.param.unun < 0)this.param.unun = 0;
2030 if(food instanceof Food){
2032 if(food.amount > 0){
2034 this.setHungry(this.param.hungry - food.getGive());
2035 this.setUnun(this.getUnun() + food.getGive() / 4);
2036 this.setYukkuri(this.getYukkuri() + 5);
2039 this.setYukkuri(this.getYukkuri() - 5);
2045 this.setHungry(this.param.hungry - food.give);
2046 this.setUnun(this.getUnun() + food.unun);
2047 this.setYukkuri(this.getYukkuri() + food.yukkuri);
2054 hunt:function(food){
2055 if(food.amount > 0){
2056 if(!this.isItemsMax()){
2058 this.items.push(food);
2059 this.setYukkuri(this.getYukkuri() + 1);
2065 declarePlace: function(place){
2068 getPlace:function(){
2071 isPlace: function(){
2072 return this.place !== null;
2076 if(this.direction == EDirection.RIGHT){
2077 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2079 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
2083 setBodyImage: function(ebody){
2084 var path = this.bodyStatus[ebody];
2085 this.image = game.assets[path];
2088 // this.imgBody.tl.pause();
2089 // this.imgGroup.tl.pause();
2090 this.imgBody.tl.clear();
2091 this.imgGroup.tl.clear();
2092 this.imgBody.tl.unloop();
2093 this.imgGroup.tl.unloop();
2097 tlResume: function(){
2098 // this.imgBody.tl.resume();
2099 // this.imgGroup.tl.resume();
2102 syncDirection:function(senderYukkuri){
2103 if(this.getX() > senderYukkuri.getX()){
2104 this.direction = EDirection.LEFT;
2105 senderYukkuri.direction = EDirection.RIGHT;
2107 this.direction = EDirection.RIGHT;
2108 senderYukkuri.direction = EDirection.LEFT;
2111 isCommunication: function(yukkuri){
2112 if(this.addressBook[yukkuri.id] === undefined) return true;
2113 if(this.addressBook[yukkuri.id].isGreeting) return false;
2116 addAddress: function(yukkuri){
2117 this.addressBook[yukkuri.id] = new Address(yukkuri);
2119 getAddress: function(yukkuri){
2120 if(this.addressBook[yukkuri.id] === undefined)return null;
2121 return this.addressBook[yukkuri.id];
2123 getStatusForDisplay: function (){
2125 var placeId = (this.place==null)?"無し" : this.place.id;
2126 ret += "ID " + this.id + "\n";
2127 ret += "プレイス " + placeId + "\n";
2128 ret += "ゆっくり " + this.getYukkuri() + "\n";
2129 ret += "空腹 " + this.getHungry() + "\n";
2130 ret += "うんうん " + this.getUnun() + "\n";
2131 ret += "もちもの " + this.items.length + "\n";
2132 ret += "debug " + this.action.status + "\n";
2135 isItemsMax:function(){
2136 return this.items.length >= this.param.items_max;
2138 getItems:function(){
2141 addSearchObject:function(esearch, node){
2142 this.searchObjectMang.add(esearch, node)
2144 clearSearchObject:function(){
2145 this.searchObjectMang.clear()
2147 setFaceImage: function(eface){
2148 var path = this.faceStatus[eface];
2149 this.face.image = game.assets[path];
2151 myScale: function(_scaleX, _scaleY){
2152 this.face.scale(_scaleX,_scaleY);
2153 if(this.myCode === "REIMU"){
2154 this.okazari.x = -this.okazari.width / 2;
2155 this.okazari.y = -CHARA_HEIGHT / 2 + (this.okazari.height * (1 - _scaleY)) / 2;
2157 this.okazari.x = -CHARA_WIDTH /2;
2158 this.okazari.y = -CHARA_HEIGHT / 2 - (CHARA_HEIGHT * _scaleY)/6;
2160 if(this.sub1 != null){
2161 this.sub1.scale(_scaleX,_scaleY);
2164 this.okazari.scale(_scaleX,_scaleY);
2165 this.hear.scale(_scaleX,_scaleY);
2166 this.scale(_scaleX,_scaleY);
2167 this.shadow.scale(_scaleX, _scaleY);
2169 send: function(targetYukkuri, object, callback){
2170 targetYukkuri.recv(object, callback);
2172 recv: function(object, callback){
2173 this.actionQueue.push({
2175 actionStatus : EAction.COMMUNICATE_RECV,
2179 addExValue: function(eexskill, plus){
2180 this.exValueHash[eexskill] += plus;
2181 if(this.exValueHash[eexskill] >= 100){
2182 this.exLvHash[eexskill] = 1;
2185 getExValue: function(eexskill){
2186 return this.exValueHash[eexskill];
2188 getExSkill: function(eexskill){
2189 return this.exLvHash[eexskill];
2192 setMemory: function(ememory, value){
2193 this.memoryHash[ememory] = value;
2195 getMemory: function(ememory){
2196 return this.memoryHash[ememory];
2198 destruct: function(){
2202 var Marisa = enchant.Class.create(Yukkuri,{
2203 initialize: function(x, y, grow){
2204 Yukkuri.call(this,x,y, grow);
2205 this.classname = "Marisa";
2206 this.myCode = "MARISA";
2207 this.myName = "まりさ";
2209 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2210 // var json = net.load("./data/marisa/params.json");
2211 // this.param = json.root.param;
2212 this.param = MarisaParam;
2213 if(this.grow == EGrow.BABY){
2214 this.myName = "まりちゃ";
2215 this.param.range /= 4;
2217 else if(this.grow == EGrow.CHILD){
2218 this.param.range /= 3;
2220 else if(this.grow == EGrow.SUBADULT){
2221 this.param.range *= 0.8;
2223 this.shadow = new enchant.Sprite(64, 64);
2224 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2225 this.shadow.x = 0 + this.x;
2226 this.shadow.y = this.getWidth() / 16 + this.x;
2228 this._style.zIndex = 5;
2230 this.face = new enchant.Sprite(64, 64);
2231 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2232 this.face.x = -CHARA_WIDTH / 2;
2233 this.face.y = -CHARA_HEIGHT / 2;
2235 this.faceStatus ={};
2236 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2237 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2238 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2239 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2240 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2241 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2242 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2243 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2244 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2245 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2248 this.hear = new enchant.Sprite(64, 64);
2249 this.hear.image = game.assets[EResPath.MARISA_HEAR];
2250 this.hear.x = -CHARA_WIDTH / 2;
2251 this.hear.y = -CHARA_HEIGHT / 2;
2253 this.okazari = new Okazari(this);
2257 this.imgGroup.addChild(this.shadow);
2258 this.imgBody.addChild(this);
2259 this.imgBody.addChild(this.face);
2260 this.imgBody.addChild(this.hear);
2261 this.imgBody.addChild(this.okazari);
2262 this.myScale(this.myScaleX, this.myScaleY)
2263 if(this instanceof Player){
2264 // this.myScaleX = 0.5;
2265 // this.myScaleY = 0.5;
2267 this.budge = new enchant.Sprite(16, 16);
2268 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2269 this.imgBody.addChild(this.budge);
2270 this.budge.x -= this.getWidth()/2;
2271 this.budge.y -= this.getHeight()/2;
2272 this.budge.scale(this.myScaleX, this.myScaleX);
2274 this.imgGroup.width = this.getWidth();
2275 this.imgGroup.height = this.getHeight();
2276 this.imgGroup.addChild(this.imgBody);
2277 backgroundMap.addChild(this.imgGroup);
2278 this._tweet = new TTweet(148, 64);
2280 this.imgGroup.addChild(this._tweet);
2281 this.imgGroup.x = x;
2282 this.imgGroup.y = y;
2285 this.action = new Action(this);
2289 var Player = enchant.Class.create(Marisa,{
2290 initialize: function(x, y){
2291 // this.runEnterframe = function(){
2293 Marisa.call(this, x, y, EGrow.ADULT);
2294 this.classname = "Player";
2296 ctl.setPlayer(this);
2297 // this.removeEventListener('enterframe',this.runEnterframe);
2298 this.addEventListener('enterframe', function(){
2301 if(this.age%10 === 0 && this.age !== 0){
2302 // console.log("palyer:" + this.age);
2305 ///////////////////////////////////////////////
2306 //Action pattern debug
2307 if(game.input.left){
2308 // this.changeFace(EResPath.MARISA_FACE_TIRED);
2310 this.direction = EDirection.LEFT;
2312 if(game.input.right){
2314 this.direction = EDirection.RIGHT;
2319 if(game.input.down){
2323 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2324 ///////////////////////////////////////////////
2326 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2327 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
2329 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
2331 //- Display the circle of search range.
2332 // fieldBg.image.clear();
2333 // fieldBg.image.context.beginPath();
2334 // fieldBg.image.context.fillStyle = '#ff0000';
2335 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2336 // fieldBg.image.context.fill();
2340 var Reimu = enchant.Class.create(Yukkuri,{
2341 initialize: function(x, y, grow){
2342 Yukkuri.call(this,x,y, grow);
2343 this.classname = "Reimu";
2344 this.myCode = "REIMU";
2345 this.myName = "れいむ";
2347 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2348 // var json = net.load("./data/reimu/params.json");
2349 // this.param = json.root.param;
2350 this.param = ReimuParam;
2351 if(this.grow == EGrow.BABY){
2352 this.myName = "れいみゅ";
2353 this.param.range /= 4;
2355 else if(this.grow == EGrow.CHILD){
2356 this.param.range /= 3;
2358 else if(this.grow == EGrow.SUBADULT){
2359 this.param.range *= 0.8;
2361 this.shadow = new enchant.Sprite(64, 64);
2362 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2363 this.shadow.x = 0 + this.x;
2364 this.shadow.y = this.getWidth() / 16 + this.x;
2365 this.shadow.image._element.style.zIndex = 2;
2367 this._style.zIndex = 5;
2369 this.face = new enchant.Sprite(64, 64);
2370 this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2371 this.face.x = -CHARA_WIDTH / 2;
2372 this.face.y = -CHARA_HEIGHT / 2;
2373 this.face._style.zIndex = 0;
2375 this.faceStatus ={};
2376 this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2377 this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2378 this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2379 this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2380 this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2381 this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2382 this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2383 this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2384 this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2385 this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2388 this.hear = new enchant.Sprite(64, 64);
2389 this.hear.image = game.assets[EResPathReimu.HEAR];
2390 this.hear.x = -CHARA_WIDTH / 2;
2391 this.hear.y = -CHARA_HEIGHT / 2;
2393 this.sub1 = new enchant.Sprite(64, 64);
2394 this.sub1.image = game.assets[EResPathReimu.SUB1];
2395 this.sub1.x = -CHARA_WIDTH / 2;
2396 this.sub1.y = -CHARA_HEIGHT / 2;
2398 this.okazari = new Okazari(this);
2400 // this.imgGroup._style.zIndex = 1;
2403 this.imgGroup.addChild(this.shadow);
2404 this.imgBody.addChild(this.okazari);
2405 this.imgBody.addChild(this);
2406 this.imgBody.addChild(this.face);
2407 this.imgBody.addChild(this.hear);
2408 this.imgBody.addChild(this.sub1);
2409 this.myScale(this.myScaleX, this.myScaleY)
2410 if(this instanceof Player){
2411 // this.myScaleX = 0.5;
2412 // this.myScaleY = 0.5;
2414 this.budge = new enchant.Sprite(16, 16);
2415 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2416 this.imgBody.addChild(this.budge);
2417 this.budge.x -= this.getWidth()/2;
2418 this.budge.y -= this.getHeight()/2;
2419 this.budge.scale(this.myScaleX, this.myScaleX);
2421 this.imgGroup.width = this.getWidth();
2422 this.imgGroup.height = this.getHeight();
2423 this.imgGroup.addChild(this.imgBody);
2424 backgroundMap.addChild(this.imgGroup);
2425 this._tweet = new TTweet(148, 64);
2427 this.imgGroup.addChild(this._tweet);
2428 this.imgGroup.x = x;
2429 this.imgGroup.y = y;
2432 this.action = new Action(this);
2434 this.exLvHash[EExSkill.KEKKAI] = 1;
2435 this.exValueHash[EExSkill.KEKKAI] = 100;
2439 game.onload = function(){
2443 def.ObjSprite = ObjSprite;
2444 def.Yukkuri = Yukkuri;
2445 def.nodeSort = nodeSort;
2446 mangTouch = new MangTouch(ctl);
2447 mangMsg = new MangMsg(ctl);
2448 ctl.setDefined(def);
2449 backgroundMap.image = game.assets[EResPath.MAP0];
2450 backgroundMap.loadData(_mapData);
2451 backgroundMap.collisionData = _collisionData;
2453 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2454 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2455 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2456 fieldBg.image = fieldSurface;
2460 windowFront.image = windowSurface;
2463 windowFront.opacity = 0.5;
2465 windowSurface.context.fillStyle = '#000';
2466 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2469 menuSurface.context.fillStyle = '#000';
2470 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2471 menuBg.image = menuSurface;
2472 menuBg.x = EMenuPos.X;
2473 menuBg.y = EMenuPos.Y;
2474 backgroundMap.addChild(fieldBg);
2475 mangIcon = new MangIcon(ctl, menuBg);
2477 game.rootScene.addChild(backgroundMap);
2478 game.rootScene.addChild(windowFront);
2479 game.rootScene.addChild(menuBg);
2481 // var labelGroup = new LabelGroup();
2482 mangLabel = new MangLabel(ctl, menuBg);
2483 // var info = new Label("ゆっくり");
2484 // info.color = "#ffffff";
2485 // info.font = "14px 'Times New Roman'";
2487 // info.y = GAME_HEIGHT / 2;
2488 // labelGroup.addChild(info);
2489 // menuBg.addChild(labelGroup);
2492 // var food = new def.Food("apple", 200, 250);
2493 backgroundMap.addChild(foodGroup);
2494 // backgroundMap.addChild(placeGroup);
2495 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2496 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2497 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2498 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2499 new Marisa(PALYER_INIT_X + 200, PALYER_INIT_Y + 200, EGrow.BABY);
2500 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2501 new Reimu(PALYER_INIT_X + 350, PALYER_INIT_Y + 400, EGrow.SUBADULT);
2502 new Reimu(PALYER_INIT_X + 300, PALYER_INIT_Y + 400, EGrow.CHILD);
2503 new Reimu(PALYER_INIT_X + 250, PALYER_INIT_Y + 400, EGrow.BABY);
2504 // new Unun(100, 100);
2505 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2509 game.rootScene.addEventListener('touchstart', function (e) {
2510 game.touched = true;
2511 var mang = mangTouch.get(ctl.getCurrentCommand());
2514 game.rootScene.addEventListener('touchmove', function (e) {
2515 var mang = mangTouch.get(ctl.getCurrentCommand());
2518 game.rootScene.addEventListener('touchend', function (e) {
2519 var mang = mangTouch.get(ctl.getCurrentCommand());
2521 game.touched = false;
2525 game.rootScene.addEventListener('enterframe', function(){
2527 mangLabel.draw(player);
2528 if(this.age%BASE_FPS == 0 ){
2531 ctl.time += TIME_SPEED;
2533 this.addEventListener('enterframe', function(){
2534 //The priority processing of display instead of z-index
2536 backgroundMap.childNodes.sort(nodeSort);