2 //////////////////////////////////////
4 CanvasLayer初期化後にcanvasのコンテキストを操作する
6 // var initCanvas = CanvasLayer.prototype.initialize;
8 // CanvasLayer.prototype.initialize = function() {
9 // initCanvas.call(this);
10 // console.log("canvas");
12 // // 拡大時の処理をNearest Neighbor方式に切り替え
13 // // ただしChromeとFireFoxでのみ動作
14 // this.context.imageSmoothingEnabled = false;
15 // this.context.webkitImageSmoothingEnabled = false;
16 // this.context.mozImageSmoothingEnabled = false;
24 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
26 //////////////////////////////////////
28 //////////////////////////////////////
29 var PALYER_INIT_X = 100;
30 var PALYER_INIT_Y = 100;
32 var CHARA_HEIGHT = 64;
34 var GAME_HEIGHT = 600;
40 // var DAY = HOUR * 24;
42 var GAME_START_TIME = HOUR * 6;
45 YUKKURI_BASE : './data/yukkuri_base.png',
46 YUKKURI_BODY_DEAD : './data/yukkuri_dead.png',
47 YUKKURI_UNUN : './data/unun.png',
48 YUKKURI_SHADOW : './data/shadow.png',
49 MARISA_FACE_NORMAL : './data/marisa/face_normal1.png',
50 MARISA_FACE_TIRED : './data/marisa/face_tired1.png',
51 MARISA_FACE_ANGRY : './data/marisa/face_angry1.png',
52 MARISA_FACE_CRY1 : './data/marisa/face_cry1.png',
53 MARISA_FACE_CRY2 : './data/marisa/face_cry2.png',
54 MARISA_FACE_EAT1 : './data/marisa/face_eat1.png',
55 MARISA_FACE_EAT2 : './data/marisa/face_eat2.png',
56 MARISA_FACE_HAPPY1 : './data/marisa/face_happy1.png',
57 MARISA_FACE_HAPPY2 : './data/marisa/face_happy2.png',
58 MARISA_FACE_SLEEP : './data/marisa/face_sleep1.png',
59 MARISA_HEAR : './data/marisa/hear1.png',
60 OBJECT : './data/object.png',
61 MAP0 : './data/map0.png',
62 COMMAND : './data/command.png',
63 OKAZARI : './data/okazari.png',
64 PLACE_TREE : './data/system/place_tree.png',
65 GRASS : './data/system/grass.png',
66 PLAYER_BADGE : './data/system/player_badge.png',
67 // PLACE_TREE : './data/system/rapture.png',
73 FACE_NORMAL : './data/reimu/face_normal1.png',
74 FACE_TIRED : './data/reimu/face_tired1.png',
75 FACE_ANGRY : './data/reimu/face_angry1.png',
76 FACE_CRY1 : './data/reimu/face_cry1.png',
77 FACE_CRY2 : './data/reimu/face_cry2.png',
78 FACE_EAT1 : './data/reimu/face_eat1.png',
79 FACE_EAT2 : './data/reimu/face_eat2.png',
80 FACE_HAPPY1 : './data/reimu/face_happy1.png',
81 FACE_HAPPY2 : './data/reimu/face_happy2.png',
82 FACE_SLEEP : './data/reimu/face_sleep1.png',
83 HEAR : './data/reimu/hear1.png',
84 OKAZARI : './data/reimu/okazari.png',
85 SUB1 : './data/reimu/sub1.png',
117 HEIGHT : GAME_HEIGHT,
122 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
133 MOVE_TO_EAT_START: 10,
134 MOVE_TO_EAT_UNDERWAY: 11,
138 UNUN_SMELL_START : 15,
139 UNUN_SMELL_WAIT : 16,
142 COMMUNICATE_START : 19,
143 COMMUNICATE_WAIT: 20,
144 COMMUNICATE_RECV: 21,
145 MOVE_TO_PLACE_START_HOMELESS: 22,
146 MOVE_TO_PLACE_HOMELESS_UNDERWAY: 23,
147 DECLARE_PLACE_HOMELESS: 24,
148 MOVE_TO_HUNT_START: 25,
181 var EWalkAnimation = {
210 var ObjSprite = enchant.Class.create(enchant.Sprite,{
211 initialize: function (w, h){
212 enchant.Sprite.call(this, w, h);
217 // // new BoxLabel(this.ctl,100, e.x, e.y);
218 // var box = new Box(this.ctl, 200, 200);
220 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
223 getStatusForDisplay: function (){
232 getWidth: function(){
235 getHeight: function(){
238 removeAll: function(){
245 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
256 //-Event register [onactionstart,onactiontick,onactionend]
257 if(eventFunctions !== undefined){
258 for(var key in eventFunctions){
259 params[key] = eventFunctions[key];
262 return this.tween(params);
264 function plusFrameScale(frame, scale){
265 return (frame/2) * (1 - scale)
270 include("./lang/ja.js");
271 window.onload = function(){
272 var nodeSort = function (a, b){
273 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
276 else if(typeof a.id === "undefined"){
279 else if(typeof b.id === "undefined"){
284 if(a instanceof Box && b instanceof Box){
287 if(a instanceof Box){
290 if(b instanceof Box){
293 if(a instanceof SpriteGroup){
297 if(b instanceof SpriteGroup){
302 if(a instanceof Place){
303 ay += Math.round(a.height * 0.7);
305 if(b instanceof Place){
306 by += Math.round(b.height * 0.7);
309 if(ay < by)return -1;
310 else if(ay > by)return 1;
311 if(a.id < b.id)return -1;
312 else if(a.id > b.id)return 1;
318 var def = new Object();
319 var foodGroup = new Group();
320 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
321 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
322 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
323 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
324 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
328 var tmpName = EResPathReimu.getName();
330 for(var _v in EResPathReimu){
331 if(typeof EResPathReimu[_v] === "function")continue;
332 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
338 for(var _v in EResPath){
339 _loadArr[i] = EResPath[_v];
342 game.preload(_loadArr);
343 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
344 var backgroundMap = new MapGroup(16, 16);
345 include("./class.js");
346 include("./ctrl.js");
349 ctl.setBackgroundMap(backgroundMap);
350 var Action = enchant.Class.create({
351 initialize: function (yukkuri){
352 this.status = EAction.THINK;
353 this.yukkuri = yukkuri;
354 this.isMoving = false;
355 this.targetNode = null;
357 getStatus: function(){
360 setStatus: function(eaction){
361 this.status = eaction;
364 if(this.yukkuri.isDead()){
365 this.status = EAction.DEAD;
367 // else if(this.yukkuri.isSleep()){
368 // this.status = EAction.SLEEP;
378 if(this.waitCnt >= BASE_FPS * 60 * 24 * 3){
380 this.setStatus(EAction.THINK);
381 console.log("wait cnt end");
384 case EAction.THINK_IN_HOME:
387 this.think_in_home();
389 case EAction.EAT_IN_HOME:
394 if(this.yukkuri.age%2 === 0){
395 this.yukkuri.changeFace();
397 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
400 case EAction.MOVE_TO_EAT_START:
401 this.move_to_eat_start();
403 case EAction.MOVE_TO_EAT_UNDERWAY:
409 case EAction.SLEEP_START:
412 case EAction.SLEEP_WAIT:
417 case EAction.EAT_START:
420 case EAction.EAT_WAIT:
422 case EAction.UNUN_START:
425 case EAction.UNUN_WAIT:
427 case EAction.MOVE_TO_COMMAND:
428 this.move_to_command();
430 case EAction.UNUN_SMELL_START:
431 this.unun_smell_start();
433 case EAction.COMMUNICATE_START:
434 this.communicate_start();
436 case EAction.COMMUNICATE_WAIT:
438 case EAction.COMMUNICATE_RECV:
440 case EAction.MOVE_TO_PLACE_START_HOMELESS:
441 this.move_to_place_start_homeless();
443 case EAction.DECLARE_PLACE_HOMELESS:
444 this.declare_place_homeless();
446 case EAction.MOVE_TO_HUNT_START:
447 this.move_to_hunt_start();
449 case EAction.HUNT_START:
452 case EAction.MOVE_GOTO_HOME:
453 this.move_goto_home();
455 case EAction.IN_HOME:
460 this.yukkuri.reverse();
462 thinkHavePlace: function(){
463 var date = ctl.getDate();
464 if(this.yukkuri.isPlaceRange()){
467 if(date === EDate.EVENING
468 || date === EDate.NIGHT
469 || date === EDate.MIDNIGHT
471 this.setStatus(EAction.MOVE_GOTO_HOME);
474 else if(date === EDate.EVENING){
475 // if(this.yukkuri.isItemsMax()){
476 // this.setStatus(EAction.IN_HOME);
479 // this.setStatus(EAction.MOVE_TO_HUNT_START);
483 if(this.yukkuri.isVeryKuhuku()){
486 this.setStatus(EAction.MOVE_GOTO_HOME);
488 else if(this.yukkuri.isSleep()){
489 this.setStatus(EAction.SLEEP_START);
491 else if(this.yukkuri.getUnun() >= 80){
492 this.setStatus(EAction.UNUN_START);
495 this.yukkuri.changeFace();
499 think_in_home: function(){
500 var date = ctl.getDate();
501 if((date === EDate.MIDNIGHT || date === EDate.NIGHT)
502 && !this.yukkuri.isSleep()){
506 "nextStatus":EAction.THINK_IN_HOME,
507 "myYukkuri": this.yukkuri
511 else if(date === EDate.EVENING){
515 //marisa is hunting move
516 if(this.yukkuri.beforeHuntingFood !== null){
517 new MoveToHuntEvent({
519 "targetNode": this.yukkuri.beforeHuntingFood,
521 "myYukkuri": this.yukkuri
525 this.setStatus(EAction.WALK);
529 eat_in_home: function(){
531 "targetNode": this.yukkuri.getPlace(),
533 "myYukkuri": this.yukkuri
536 move_to_eat_start : function(){
539 "targetNode": this.targetNode,
541 "myYukkuri": this.yukkuri
547 walk : function(retryCounter){
548 if(retryCounter > 15){
550 this.status = EAction.NONE;
551 console.log("retryCount over");
554 if(this.yukkuri.imgGroup.tl.queue.length === 0){
556 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
558 this.isMoving = false;
559 this.status = EAction.THINK;
563 var xpos = 150 + rand(40) - (retryCounter * 10);
564 var ypos = 150 + rand(40) - (retryCounter * 10);
567 this.yukkuri.vy = -ypos;
569 else if(rand(8) == 1){
570 this.yukkuri.vx = xpos;
571 this.yukkuri.vy = -ypos;
572 this.yukkuri.direction = EDirection.RIGHT;
574 else if(rand(8) == 2){
575 this.yukkuri.vx = xpos;
577 this.yukkuri.direction = EDirection.RIGHT;
579 else if(rand(8) == 3){
580 this.yukkuri.vx = xpos;
581 this.yukkuri.vy = ypos;
582 this.yukkuri.direction = EDirection.RIGHT;
584 else if(rand(8) == 4){
586 this.yukkuri.vy = ypos;
588 else if(rand(8) == 5){
589 this.yukkuri.vx = -xpos;
590 this.yukkuri.vy = ypos;
591 this.yukkuri.direction = EDirection.LEFT;
593 else if(rand(8) == 6){
594 this.yukkuri.vx = -xpos;
596 this.yukkuri.direction = EDirection.LEFT;
598 else if(rand(8) == 7){
599 this.yukkuri.vx = -xpos;
600 this.yukkuri.vy = -ypos;
601 this.yukkuri.direction = EDirection.LEFT;
603 if (this.yukkuri.vx || this.yukkuri.vy) {
604 var map = ctl.backgroundMap;
605 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
606 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
607 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
608 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
609 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
610 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
611 // console.log("X:" + this.yukkuri.moveX);
612 // console.log("Y:" + this.yukkuri.moveY);
613 this.isMoving = true;
614 this.yukkuri.reverse();
615 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
616 mangMsg.output(this.yukkuri,EMsg.WALK);
618 this.targetNode = null;
620 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
621 this.walk(retryCounter+1);
627 sleep_start: function(){
630 "myYukkuri": this.yukkuri
634 mangMsg.output(this.yukkuri, EMsg.DEAD);
635 this.yukkuri.tlPause();
636 this.yukkuri.setBodyImage(EBody.DEAD);
638 eat_start: function(){
641 "targetNode": this.targetNode,
643 "myYukkuri": this.yukkuri
647 unun_start: function(){
650 "myYukkuri": this.yukkuri
653 unun_smell_start: function(){
656 "myYukkuri": this.yukkuri
659 communicate_start:function(){
660 new ComSayHelloSendEvent({
662 "targetNode": this.targetNode,
664 "myYukkuri": this.yukkuri
667 move_to_place_start_homeless:function(){
668 new MoveToPlaceStartHomelessEvent({
669 "targetNode": this.targetNode,
671 "myYukkuri": this.yukkuri
674 declare_place_homeless:function(){
675 new DeclarePlaceHomelessEvent({
676 "targetNode": this.targetNode,
678 "myYukkuri": this.yukkuri
681 move_to_hunt_start:function(){
682 new MoveToHuntEvent({
684 "targetNode": this.targetNode,
686 "myYukkuri": this.yukkuri
689 hunt_start:function(){
692 "targetNode": this.targetNode,
694 "myYukkuri": this.yukkuri
697 move_goto_home:function(){
698 var place = this.yukkuri.getPlace();
699 new MoveGotoHomeEvent({
703 "myYukkuri": this.yukkuri
707 var place = this.yukkuri.getPlace();
712 "myYukkuri": this.yukkuri
715 move_to_command: function(){
719 this.yukkuri.clearSearchObject();
720 var nodes = ctl.getObjs();
724 for (var key in nodes) {
725 var node = nodes[key];
726 if(this.yukkuri.id === node.id)continue;
730 && !(this.targetNode instanceof Unun)
731 && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
733 this.yukkuri.addSearchObject(ESearch.UNUN, node);
736 else if (node instanceof Food && node.amount > 0) {
737 if(this.yukkuri.within(node, this.yukkuri.getRange())){
738 this.yukkuri.addSearchObject(ESearch.FOOD, node);
742 else if(node instanceof Yukkuri){
743 if(this.yukkuri.within(node, this.yukkuri.getRange())){
744 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
748 else if(node instanceof Place){
749 if(this.yukkuri.within(node, this.yukkuri.getRange())){
750 this.yukkuri.addSearchObject(ESearch.PLACE, node);
754 this.status = EAction.WALK;
758 * Range範囲内のObjSprを管理する
759 * 注意!:ゆっくりプレイスを持って入るもののみ使用される
763 var SearchObjectMang = enchant.Class.create({
764 initialize: function (){
769 for(var key in ESearch){
770 var esearch = ESearch[key];
771 this.datas[esearch] = [];
774 add :function(esearch, node){
775 this.datas[esearch].push(node);
778 for(var key in ESearch){
779 var esearch = ESearch[key];
780 this.datas[esearch].length = 0;
782 // this.datas.length = 0;
785 get:function (esearch){
786 return this.datas[esearch];
788 getNear:function (esearch, yukkuri){
789 var objects = this.datas[esearch];
790 var nearDistance = null;
792 for(var i=0;i<objects.length;i++){
793 var object = objects[i];
794 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
795 if(nearDistance === null || nearDistance > nowDistance){
796 nearDistance = nowDistance;
802 callEvent: function(yukkuri){
803 if(yukkuri.isItemsMax() && yukkuri.isPlace()){
804 yukkuri.action.targetNode = yukkuri.getPlace();
805 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
808 if(yukkuri.isVeryKuhuku()){
810 var foods = this.get(ESearch.FOOD);
811 if(foods.length === 0 && yukkuri.isPlace()){
813 yukkuri.action.targetNode = yukkuri.getPlace();
814 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
817 var foods = this.get(ESearch.FOOD);
818 food = this.getNear(ESearch.FOOD, yukkuri);
820 yukkuri.action.targetNode = food;
821 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
827 if(yukkuri.isSleep()){
828 yukkuri.action.setStatus(EAction.SLEEP_START);
832 else if(yukkuri.getUnun() >= 80){
833 yukkuri.action.setStatus(EAction.UNUN_START);
838 if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
839 food = this.getNear(ESearch.FOOD, yukkuri);
841 yukkuri.action.targetNode = food;
842 yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
846 ununs = this.get(ESearch.UNUN);
847 if(ununs.length !== 0){
848 yukkuri.action.targetNode = yukkuri.getPlace();
849 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
852 var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
853 if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
854 yukkuri.action.targetNode = searchYukkuri;
855 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
858 if(!yukkuri.isPlace()){
859 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
860 if(searchYukkuri != null && !searchYukkuri.isOwner()){
861 yukkuri.action.targetNode = searchYukkuri;
862 yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
866 yukkuri.action.setStatus(EAction.WALK);
871 var Event = enchant.Class.create({
872 initialize: function (_data){
875 onactionstart:function(self){
877 if(typeof e === "undefined")return;
880 onactiontick:function(self){
882 if(typeof e === "undefined")return;
885 onactionend:function(self){
887 if(typeof e === "undefined")return;
891 var WalkEvent = enchant.Class.create(Event,{
892 initialize: function (_data){
894 this.yukkuri = _data.myYukkuri;
895 this.action = _data.action;
897 mangMsg.output(this.yukkuri, EMsg.SLEEP);
898 this.action.setStatus(EAction.SLEEP_WAIT);
899 this.yukkuri.setFaceImage(EFace.SLEEP);
900 this.yukkuri.tlPause();
902 this.yukkuri.addEventListener('enterframe', function() {
903 var yukkuri = self.yukkuri;
911 var SleepEvent = enchant.Class.create(Event,{
912 initialize: function (_data){
914 this.yukkuri = _data.myYukkuri;
915 this.action = _data.action;
917 mangMsg.output(this.yukkuri, EMsg.SLEEP);
918 this.action.setStatus(EAction.SLEEP_WAIT);
919 this.yukkuri.setFaceImage(EFace.SLEEP);
920 this.yukkuri.tlPause();
923 this.yukkuri.addEventListener('enterframe', function() {
924 var yukkuri = self.yukkuri;
925 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
926 if(yukkuri.param.sleep <= 0){
927 yukkuri.param.sleep = 0;
928 this.removeEventListener("enterframe",arguments.callee);
929 mangMsg.output(self.yukkuri, EMsg.GET_UP);
930 yukkuri.setFaceImage(EFace.NORMAL);
932 // self.action.setStatus(EAction.WAIT);
933 if(self.data.nextStatus !== undefined){
934 self.action.setStatus(self.data.nextStatus);
936 self.action.setStatus(EAction.THINK);
943 var UnunEvent = enchant.Class.create(Event,{
944 initialize: function (_data){
946 this.yukkuri = _data.myYukkuri;
947 this.action = _data.action;
948 this.action.setStatus(EAction.UNUN_WAIT);
949 mangMsg.output(this.yukkuri, EMsg.UNUN);
950 this.yukkuri.setFaceImage(EFace.HAPPY2);
953 this.yukkuri.wait(sec, {
954 "onactionend": this.onactionend(this)
957 onactionend:function(self){
959 if(typeof e === "undefined")return;
961 self.action.setStatus(EAction.WAIT);
962 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
964 "waitframe": FPS * 1.5,
965 "action": self.action,
966 "myYukkuri": self.yukkuri
971 var WaitEvent = enchant.Class.create(Event,{
972 initialize: function (_data){
974 this.yukkuri = _data.myYukkuri;
975 this.action = _data.action;
976 this.waitframe = _data.waitframe;
977 this.yukkuri.wait(this.waitframe, {
978 "onactionstart": this.onactionstart(this),
979 "onactiontick": this.onactiontick(this),
980 "onactionend": this.onactionend(this)
983 onactionend:function(self){
985 if(typeof e === "undefined")return;
986 self.action.setStatus(EAction.THINK);
990 var UnunSmellEvent = enchant.Class.create(Event,{
991 initialize: function (_data){
993 this.yukkuri = _data.myYukkuri;
994 this.action = _data.action;
995 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
996 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
997 this.yukkuri.setFaceImage(EFace.CRY1);
999 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
1000 this.yukkuri.wait(sec, {
1001 "onactionend": this.onactionend(this)
1004 onactionend:function(self){
1006 if(typeof e === "undefined")return;
1007 self.action.setStatus(EAction.WALK);
1012 var EatEvent = enchant.Class.create(Event,{
1013 initialize: function (_data){
1015 this.yukkuri = _data.myYukkuri;
1016 this.food = _data.targetNode;
1017 this.action = _data.action;
1018 this.action.setStatus(EAction.EAT_WAIT);
1021 var sec = BASE_FPS * 3;
1022 if(this.yukkuri.eat(this.food)){
1023 mangMsg.output(this.yukkuri, EMsg.EAT);
1024 this.yukkuri.setFaceImage(EFace.EAT2);
1027 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1028 this.yukkuri.setFaceImage(EFace.CRY2);
1030 this.yukkuri.wait(sec, {
1031 "onactionend": this.onactionend(this)
1034 onactionend:function(self){
1036 if(typeof e === "undefined")return;
1037 if(self.food == null || self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1038 self.action.setStatus(EAction.THINK);
1039 self.yukkuri.setFaceImage(EFace.NORMAL);
1041 self.action.setStatus(EAction.EAT_START);
1048 * -When yukkuri find Food.
1051 * targetNode: enchant.Node
1055 var MoveToEatEvent = enchant.Class.create(Event,{
1056 initialize: function (_data){
1058 this.yukkuri = this.data.myYukkuri;
1059 this.action = this.data.action;
1061 var yukkuri = this.yukkuri;
1062 var node = this.data.targetNode;
1064 if(this.data.type == "food"){
1065 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1066 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1067 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1068 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1069 var frame = distance + distance/5 + 1;
1070 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1071 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1074 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1075 "onactionstart": this.onactionstart(this),
1076 "onactiontick": this.onactiontick(this),
1077 "onactionend": this.onactionend(this)
1081 onactionstart:function(self){
1083 if(typeof e === "undefined")return;
1084 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1087 onactiontick:function(self){
1089 if(typeof e === "undefined")return;
1092 onactionend:function(self){
1094 if(typeof e === "undefined")return;
1095 self.action.setStatus(EAction.EAT_START);
1099 var MoveToHuntEvent = enchant.Class.create(Event,{
1100 initialize: function (_data){
1102 this.yukkuri = this.data.myYukkuri;
1103 this.action = this.data.action;
1105 var yukkuri = this.yukkuri;
1106 var node = this.data.targetNode;
1109 var nodeWidth = node.width;
1110 var nodeHeight = node.height;
1114 if(this.data.type == "food"){
1115 this.action.setStatus(EAction.WAIT);
1116 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1117 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1118 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1119 var frame = distance + distance/5 + 1;
1120 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1121 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1123 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1125 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1126 "onactionend": this.onactionend(this)
1130 onactionend:function(self){
1132 if(typeof e === "undefined")return;
1133 self.action.setStatus(EAction.HUNT_START);
1137 var HuntStartEvent = enchant.Class.create(Event,{
1138 initialize: function (_data){
1139 Event.call(this, _data);
1142 this.yukkuri = _data.myYukkuri;
1143 this.food = _data.targetNode;
1144 this.action = _data.action;
1145 this.action.setStatus(EAction.WAIT);
1146 this.huntingStatus = "hunting";
1148 this.yukkuri.beforeHuntingFood = this.food;
1149 var sec = BASE_FPS * 8;
1150 if(this.yukkuri.hunt(this.food)){
1151 this.huntingStatus = "hunting";
1152 mangMsg.output(this.yukkuri, EMsg.HUNT);
1153 this.yukkuri.setFaceImage(EFace.HAPPY1);
1155 if(this.yukkuri.isItemsMax()){
1157 this.huntingStatus = "return";
1158 // mangMsg.output(this.yukkuri, EMsg.REHUNT);
1159 this.yukkuri.setFaceImage(EFace.NORMAL);
1162 this.huntingStatus = "cry";
1163 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1164 this.yukkuri.setFaceImage(EFace.CRY2);
1168 this.yukkuri.wait(sec, {
1169 "onactiontick": this.onactiontick(this),
1170 "onactionend": this.onactionend(this)
1173 onactiontick:function(self){
1175 if(typeof e === "undefined")return;
1177 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 2){
1178 if(this.age%(BASE_FPS * 3) == 0){
1179 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1184 onactionend:function(self){
1186 if(typeof e === "undefined")return;
1187 if(self.huntingStatus == "hunting"){
1188 if(self.yukkuri.isItemsMax()){
1189 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1190 // mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1192 self.action.setStatus(EAction.HUNT_START);
1195 else if(self.huntingStatus == "return"){
1196 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1198 else if(self.huntingStatus === "cry"){
1199 self.action.setStatus(EAction.THINK);
1206 this.yukkuri = null;
1211 var MoveGotoHomeEvent = enchant.Class.create(Event,{
1212 initialize: function (_data){
1214 this.yukkuri = this.data.myYukkuri;
1215 this.action = this.data.action;
1217 var yukkuri = this.yukkuri;
1218 var place = this.data.targetNode;
1220 if(this.data.type == "hunt_end"){
1221 this.action.setStatus(EAction.WAIT);
1222 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1223 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1224 // console.log("place.x:" + place.x);
1225 // console.log("place.y:" + place.y);
1226 // console.log("yukkuri.getX():" + yukkuri.getX());
1227 // console.log("yukkuri.getY():" + yukkuri.getY());
1228 // console.log("yukkuri.vx:" + yukkuri.vx);
1229 // console.log("yukkuri.vy:" + yukkuri.vy);
1230 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1231 var frame = distance + distance/2 + 1 ;
1232 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1233 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1235 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1237 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1238 "onactiontick": this.onactiontick(this),
1239 "onactionend": this.onactionend(this)
1243 onactiontick:function(self){
1245 if(typeof e === "undefined")return;
1246 if(this.age%(BASE_FPS * 5) == 0){
1247 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1251 onactionend:function(self){
1253 if(typeof e === "undefined")return;
1254 self.action.setStatus(EAction.IN_HOME);
1260 this.yukkuri = null;
1264 var InHomeEvent = enchant.Class.create(Event,{
1265 initialize: function (_data){
1267 this.yukkuri = this.data.myYukkuri;
1268 this.action = this.data.action;
1270 var yukkuri = this.yukkuri;
1271 var place = this.data.targetNode;
1272 if(yukkuri.isVeryKuhuku()){
1274 this.action.setStatus(EAction.EAT_IN_HOME);
1277 mangMsg.output(yukkuri, EMsg.EAT_FAILED);
1280 this.action.setStatus(EAction.WAIT);
1281 var items = this.yukkuri.getItems();
1282 if(items.length > 0){
1283 place.setItems(items);
1287 var sec = BASE_FPS * 10;
1288 this.yukkuri.wait(sec, {
1289 "onactiontick": this.onactiontick(this),
1290 "onactionend": this.onactionend(this)
1293 onactiontick:function(self){
1295 if(typeof e === "undefined")return;
1296 if(this.age%(BASE_FPS * 5) == 0){
1297 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1301 onactionend:function(self){
1303 if(typeof e === "undefined")return;
1304 self.action.setStatus(EAction.THINK);
1308 var EatInHomeEvent = enchant.Class.create(Event,{
1309 initialize: function (_data){
1311 this.yukkuri = _data.myYukkuri;
1312 this.place = _data.targetNode;
1313 this.action = _data.action;
1314 this.action.setStatus(EAction.EAT_WAIT);
1316 var sec = BASE_FPS * 3;
1317 var foodHash = this.place.getFoodHash();
1318 if(foodHash !== false && this.yukkuri.eat(foodHash)){
1319 mangMsg.output(this.yukkuri, EMsg.EAT);
1320 this.yukkuri.setFaceImage(EFace.EAT2);
1323 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1324 this.yukkuri.setFaceImage(EFace.CRY2);
1327 this.yukkuri.wait(sec, {
1328 "onactionend": this.onactionend(this)
1331 onactionend:function(self){
1333 if(typeof e === "undefined")return;
1334 if(self.place.isFood() && !self.yukkuri.isManpuku()){
1335 self.action.setStatus(EAction.EAT_IN_HOME);
1337 // new EatInHomeEvent({
1338 // "targetNode": self.place,
1339 // "action": self.action,
1340 // "myYukkuri": self.yukkuri
1343 self.action.setStatus(EAction.THINK_IN_HOME);
1344 self.yukkuri.setFaceImage(EFace.NORMAL);
1351 var MoveCommandEvent = enchant.Class.create(Event,{
1352 initialize: function (_data){
1354 this.yukkuri = this.data.myYukkuri;
1355 this.action = this.data.action;
1356 this.vx = this.data.vx;
1357 this.vy = this.data.vy;
1359 var yukkuri = this.yukkuri;
1360 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1361 yukkuri.vx = node.x - yukkuri.getX();
1362 yukkuri.vy = node.y - yukkuri.getY();
1363 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1364 var frame = distance + 1;
1365 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1367 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1368 "onactionstart": this.onactionstart(this),
1369 "onactiontick": this.onactiontick(this),
1370 "onactionend": this.onactionend(this)
1373 onactionstart:function(self){
1375 if(typeof e === "undefined")return;
1378 onactiontick:function(self){
1380 if(typeof e === "undefined")return;
1383 onactionend:function(self){
1385 if(typeof e === "undefined")return;
1386 self.action.setStatus(EAction.THINK);
1391 * Say hello contact to send communication .
1393 var ComSayHelloSendEvent = enchant.Class.create(Event,{
1394 initialize: function (_data){
1396 this.yukkuri = _data.myYukkuri;
1397 this.targetYukkuri = _data.targetNode;
1398 this.action = _data.action;
1399 this.action.setStatus(EAction.COMMUNICATE_WAIT);
1400 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1402 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1403 this.targetYukkuri.tlPause();
1404 this.yukkuri.tlPause();
1405 this.yukkuri.syncDirection(this.targetYukkuri);
1407 this.yukkuri.addAddress(this.targetYukkuri);
1408 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1410 var sec = BASE_FPS * 2;
1411 this.yukkuri.wait(sec, {
1412 "onactiontick": this.onactiontick(this),
1413 "onactionend": this.onactionend(this)
1416 onactiontick:function(self){
1418 if(typeof e === "undefined")return;
1421 onactionend:function(self){
1423 if(typeof e === "undefined")return;
1424 new ComSayHelloRecvEvent({
1426 "targetNode": self.yukkuri,
1427 "action": self.targetYukkuri.action,
1428 "myYukkuri": self.targetYukkuri
1433 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1434 initialize: function (_data){
1436 this.yukkuri = _data.myYukkuri;
1437 this.targetYukkuri = _data.targetNode;
1438 this.action = _data.action;
1439 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1440 this.yukkuri.addAddress(this.targetYukkuri);
1441 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1443 var sec = BASE_FPS * 2;
1444 this.yukkuri.wait(sec, {
1445 "onactiontick": this.onactiontick(this),
1446 "onactionend": this.onactionend(this)
1449 onactiontick:function(self){
1451 if(typeof e === "undefined")return;
1454 onactionend:function(self){
1456 if(typeof e === "undefined")return;
1457 self.action.setStatus(EAction.THINK);
1459 self.yukkuri.action.setStatus(EAction.THINK);
1460 self.yukkuri.animation();
1461 self.targetYukkuri.action.setStatus(EAction.THINK);
1462 self.targetYukkuri.animation();
1466 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1467 initialize: function (_data){
1469 this.yukkuri = this.data.myYukkuri;
1470 this.action = this.data.action;
1472 var yukkuri = this.yukkuri;
1473 var node = this.data.targetNode;
1475 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1476 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
1477 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1478 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1479 var frame = distance + distance/5 + 1;
1480 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1482 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1485 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1486 "onactionend": this.onactionend(this)
1489 onactionend:function(self){
1491 if(typeof e === "undefined")return;
1492 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1494 self.yukkuri = null;
1499 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1500 initialize: function (_data){
1502 this.yukkuri = _data.myYukkuri;
1503 this.place = _data.targetNode;
1504 this.action = _data.action;
1505 this.action.setStatus(EAction.WAIT);
1508 var sec = BASE_FPS * 3;
1509 this.yukkuri.declarePlace(this.place);
1510 this.place.setOwner(this.yukkuri);
1511 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1513 this.yukkuri.setFaceImage(EFace.NORMAL);
1514 this.yukkuri.wait(sec, {
1515 "onactionend": this.onactionend(this)
1518 onactionend:function(self){
1520 if(typeof e === "undefined")return;
1521 self.action.setStatus(EAction.THINK);
1526 var Food = enchant.Class.create(ObjSprite,{
1527 initialize: function (type, x, y){
1528 this.classname = "Food";
1529 //一つにつきgiveの値分、hunguryを減少させられる
1530 if(type == "apple"){
1531 ObjSprite.call(this,16,16);
1532 this.image = game.assets[EResPath.OBJECT];
1536 }else if(type == "grass"){
1537 ObjSprite.call(this,64,64);
1538 this.image = game.assets[EResPath.GRASS];
1545 foodGroup.addChild(this);
1546 this.addEventListener('enterframe', function(){
1547 if(this.amount <= 0){
1552 getAmount: function(){
1555 getGive: function(){
1559 var Place = enchant.Class.create(ObjSprite,{
1560 initialize: function (type, x, y){
1561 ObjSprite.call(this,128,128);
1562 this.image = game.assets[EResPath.PLACE_TREE];
1563 this.x = x - this.width / 2;
1564 this.y = y - this.height / 2;
1565 backgroundMap.addChild(this);
1568 for(var key in EFood){
1569 var efood = EFood[key];
1570 this.foods[efood] = 0;
1572 // this.addEventListener('enterframe', function(){
1573 // if(this.age%10 === 0 && this.age !== 0){
1574 // console.log("x/y " + this.x + "/" + this.y);
1576 // if(game.input.left){
1579 // if(game.input.right){
1582 // if(game.input.up){
1585 // if(game.input.down){
1590 getStatusForDisplay: function(){
1593 if(this.owner == null)ownerId = "なし";
1594 else ownerId = this.owner.id;
1595 ret += "プレイスID " + this.id + "\n";
1596 ret += "オーナーID " + ownerId + "\n";
1597 ret += "食料うめぇ " + this.foods[EFood.GREAT] + "\n";
1598 ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1599 ret += "食料にがにが " + this.foods[EFood.BAD] + "\n";
1602 setItems:function(items){
1603 var len = items.length;
1604 for(var i=0; i<len; i++){
1605 var item = items[i];
1606 if(item instanceof Food){
1607 this.foods[EFood.NORMAL]++;
1614 for(var key in EFood){
1615 var efood = EFood[key];
1616 ret += this.foods[efood];
1620 getFoodHash:function(){
1621 if(this.foods[EFood.GREAT] !== 0){
1622 this.foods[EFood.GREAT]--;
1623 return {give:20,yukkuri:15,unun:20};
1625 else if(this.foods[EFood.NORMAL] !== 0){
1626 this.foods[EFood.NORMAL]--;
1627 return {give:10,yukkuri:5,unun:10};
1629 else if(this.foods[EFood.BAD] !== 0){
1630 this.foods[EFood.BAD]--;
1631 return {give:10,yukkuri:-2,unun:10};
1635 setOwner: function(yukkuri){
1636 this.owner = yukkuri;
1638 isOwner: function(){
1639 return this.owner !== null;
1642 var Unun = enchant.Class.create(ObjSprite,{
1643 initialize: function (x, y){
1644 this.classname = "Unun";
1645 ObjSprite.call(this,32,32);
1646 this.image = game.assets[EResPath.YUKKURI_UNUN];
1649 backgroundMap.addChild(this);
1650 this.lifetime = 30 * 24 * 3;
1651 this.addEventListener('enterframe', this.runEnterframe(this));
1652 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1655 runEnterframe:function(self){
1657 if(typeof e === "undefined")return;
1658 if(this.age%BASE_FPS === 0 && this.age !== 0){
1660 if(self.lifetime <= 0){
1661 this.parentNode.removeChild(this);
1662 ctl.backgroundMap.removeChild(this);
1663 ctl.removeObj(this);
1670 // runEnterframe: function(){
1671 // console.log("enterframe:" + this.id);
1674 var Okazari = enchant.Class.create(enchant.Sprite,{
1675 initialize: function(yukkuri){
1676 this.classname = "Okazari";
1677 if(yukkuri.myCode === "REIMU"){
1678 enchant.Sprite.call(this, 80, 32);
1679 this.image = game.assets[EResPathReimu.OKAZARI];
1680 this.x = -CHARA_WIDTH / 2;
1683 enchant.Sprite.call(this, 64, 64);
1684 this.image = game.assets[EResPath.OKAZARI];
1685 this.x = -CHARA_WIDTH / 2;
1686 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1688 this.yukkuri = yukkuri;
1690 getWidth: function(){
1692 // return this.width * this.yukkuri.myScaleX;
1694 getHeight: function(){
1696 // return this.height * this.yukkuri.myScaleY;
1699 var Address = enchant.Class.create({
1700 initialize: function(yukkuri){
1701 this.friendlyLv = 1;
1702 this.yukkuri = yukkuri;
1703 this.isGreeting = false;
1704 this.greetingWaitFrame = 0;
1706 "beginSayHello" : false,
1711 set:function(key, value){
1712 this.comMatrix[key] = value;
1715 return this.comMatrix[key];
1719 var Yukkuri = enchant.Class.create(ObjSprite,{
1720 initialize: function(x, y, grow){
1721 ObjSprite.call(this, 64, 64);
1722 this.searchObjectMang = new SearchObjectMang();
1724 this.myCode = "YUKKURI";
1725 this.myName = "ゆっくり";
1726 this.beforeHuntingFood = null;
1727 if(grow == EGrow.ADULT){
1732 else if(grow == EGrow.SUBADULT){
1733 this.myScaleX = 0.8;
1734 this.myScaleY = 0.8;
1737 else if(grow == EGrow.CHILD){
1738 this.myScaleX = 0.6;
1739 this.myScaleY = 0.6;
1742 else if(grow == EGrow.BABY){
1743 this.myScaleX = 0.3;
1744 this.myScaleY = 0.3;
1748 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1749 this.classname = "Yukkuri";
1750 this.addressBook = {};
1751 this.imgGroup = new SpriteGroup();
1752 this.imgBody = new SpriteGroup();
1753 this.imgGroup.id = guid();
1754 this.imgBody.id = guid();
1755 this.x = -CHARA_WIDTH / 2;
1756 this.y = -CHARA_HEIGHT / 2;
1759 this.image = game.assets[EResPath.YUKKURI_BASE];
1760 this.direction = EDirection.RIGHT;
1761 this.addEventListener('enterframe', this.runEnterframe);
1762 this.bodyStatus ={};
1763 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1764 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1765 this.walkAnimationStatus = EWalkAnimation.END;
1769 runEnterframe:function(){
1772 if(this.isDead())return;
1783 if(this.direction == EDirection.RIGHT){
1784 this.imgBody.scaleX = 1;
1786 else if(this.direction == EDirection.LEFT){
1787 this.imgBody.scaleX = -1;
1790 tweet:function(text){
1791 text = text.replace(/%name%/g, this.myName);
1792 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1794 moveTo:function(x, y, time){
1795 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1797 moveBy:function(x, y, time, eventFunctions){
1801 return self.imgGroup.x + x;
1804 return self.imgGroup.y + y;
1807 easing: enchant.Easing.SIN_EASEINOUT
1809 //-Event register [onactionstart,onactiontick,onactionend]
1810 if(eventFunctions !== undefined){
1811 for(var key in eventFunctions){
1812 params[key] = eventFunctions[key];
1815 return this.imgGroup.tl.tween(params);
1817 wait:function(frame, eventFunctions){
1818 this.moveBy(0,1,frame,eventFunctions);
1823 animation: function(){
1826 frame += plusFrameScale(frame, this.getMyScale());
1828 move -= plusFrameScale(move, this.getMyScale());
1829 if(this.walkAnimationStatus == EWalkAnimation.END){
1831 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1832 "onactionstart": function(e){
1833 this.walkAnimationStatus = EWalkAnimation.START;
1836 .moveByEx(0, move, frame, enchant.Easing.SWING,
1838 "onactionend": function(e){
1839 this.walkAnimationStatus = EWalkAnimation.END;
1844 this.imgBody.tl.loop();
1847 getMyScale: function(){
1848 return (this.myScaleX + this.myScaleY) / 2;
1850 getWidth: function(){
1851 return this.width * this.myScaleX;
1853 getHeight: function(){
1854 return this.height * this.myScaleY;
1857 return this.imgGroup.x;
1860 return this.imgGroup.y;
1863 this.imgGroup.x += x;
1865 // this.shadow.x += x;
1866 // this._tweet.x += x;
1869 this.imgGroup.y += y;
1871 // this.shadow.y += y;
1872 // this._tweet.y += y;
1874 // changeFace: function(erespath){
1875 // this.face.image = game.assets[erespath];
1877 loadParamsXML: function(url){
1878 var http = new JKL.ParseXML( url );
1879 return http.parse();
1881 runYukkuri: function(){
1882 if(this.param.hungry > 70){
1883 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1884 this.param.yukkuri -= 1;
1887 else if(this.param.hungry < 10){
1888 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1891 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1892 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1894 runHungry: function(){
1895 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1896 if(this.param.hungry >= 100)this.param.hungry = 100;
1898 runUnun: function(){
1899 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1900 if(this.param.unun >= 100)this.param.unun = 100;
1902 runSleep: function(){
1903 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1904 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1905 if(this.param.sleep >= 100){
1906 this.param.sleep = 100;
1910 runAddress: function(){
1911 for(var key in this.addressBook){
1912 var address = this.addressBook[key];
1914 if(address.isGreeting){
1915 address.greetingWaitFrame++;
1916 if(address.greetingWaitFrame >= DAY){
1917 address.greetingWaitFrame = 0;
1918 address.isGreeting = false;
1923 changeFace: function(){
1924 if(this.param.yukkuri >= 80){
1925 this.setFaceImage(EFace.HAPPY1);
1927 else if(this.param.yukkuri >= 50){
1928 this.setFaceImage(EFace.NORMAL);
1930 else if(this.param.yukkuri >= 30){
1931 this.setFaceImage(EFace.TIRED);
1933 else if(this.param.yukkuri >= 10){
1934 this.setFaceImage(EFace.CRY1);
1936 else if(this.param.yukkuri >= 1){
1937 this.setFaceImage(EFace.CRY2);
1940 getRange: function(){
1941 return this.param.range;
1943 isSleep: function(){
1944 return this.param.sleep >= 100;
1947 return this.param.yukkuri <= 0;
1949 isManpuku: function(){
1950 return this.param.hungry <= 20;
1952 isKuhuku: function(){
1953 return this.param.hungry >= 40;
1955 isVeryKuhuku: function(){
1956 return this.param.hungry >= 80;
1958 getYukkuri: function(){
1959 return this.param.yukkuri;
1961 setYukkuri: function(yukkuri){
1962 this.param.yukkuri = yukkuri;
1963 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1965 getHungry: function(){
1966 return this.param.hungry;
1968 setHungry: function(hungry){
1969 this.param.hungry = hungry;
1970 if(this.param.hungry < 0)this.param.hungry = 0;
1972 getUnun: function(){
1973 return this.param.unun;
1975 setUnun: function(unun){
1976 this.param.unun = unun;
1977 if(this.param.unun < 0)this.param.unun = 0;
1981 if(food instanceof Food){
1983 if(food.amount > 0){
1985 this.setHungry(this.param.hungry - food.getGive());
1986 this.setUnun(this.getUnun() + food.getGive() / 4);
1987 this.setYukkuri(this.getYukkuri() + 5);
1990 this.setYukkuri(this.getYukkuri() - 5);
1996 this.setHungry(this.param.hungry - food.give);
1997 this.setUnun(this.getUnun() + food.unun);
1998 this.setYukkuri(this.getYukkuri() + food.yukkuri);
2005 hunt:function(food){
2006 if(food.amount > 0){
2007 if(!this.isItemsMax()){
2009 this.items.push(food);
2010 this.setYukkuri(this.getYukkuri() + 1);
2016 declarePlace: function(place){
2019 getPlace:function(){
2022 isPlace: function(){
2023 return this.place !== null;
2027 if(this.direction == EDirection.RIGHT){
2028 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
2030 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
2034 setBodyImage: function(ebody){
2035 var path = this.bodyStatus[ebody];
2036 this.image = game.assets[path];
2039 // this.imgBody.tl.pause();
2040 // this.imgGroup.tl.pause();
2041 this.imgBody.tl.clear();
2042 this.imgGroup.tl.clear();
2043 this.imgBody.tl.unloop();
2044 this.imgGroup.tl.unloop();
2048 tlResume: function(){
2049 // this.imgBody.tl.resume();
2050 // this.imgGroup.tl.resume();
2053 syncDirection:function(senderYukkuri){
2054 if(this.getX() > senderYukkuri.getX()){
2055 this.direction = EDirection.LEFT;
2056 senderYukkuri.direction = EDirection.RIGHT;
2058 this.direction = EDirection.RIGHT;
2059 senderYukkuri.direction = EDirection.LEFT;
2062 isCommunication: function(yukkuri){
2063 if(this.addressBook[yukkuri.id] === undefined) return true;
2064 if(this.addressBook[yukkuri.id].isGreeting) return false;
2067 addAddress: function(yukkuri){
2068 this.addressBook[yukkuri.id] = new Address(yukkuri);
2070 getAddress: function(yukkuri){
2071 if(this.addressBook[yukkuri.id] === undefined)return null;
2072 return this.addressBook[yukkuri.id];
2074 getStatusForDisplay: function (){
2076 var placeId = (this.place==null)?"無し" : this.place.id;
2077 ret += "ID " + this.id + "\n";
2078 ret += "プレイス " + placeId + "\n";
2079 ret += "ゆっくり " + this.getYukkuri() + "\n";
2080 ret += "空腹 " + this.getHungry() + "\n";
2081 ret += "うんうん " + this.getUnun() + "\n";
2082 ret += "もちもの " + this.items.length + "\n";
2085 isItemsMax:function(){
2086 return this.items.length >= this.param.items_max;
2088 getItems:function(){
2091 addSearchObject:function(esearch, node){
2092 this.searchObjectMang.add(esearch, node)
2094 clearSearchObject:function(){
2095 this.searchObjectMang.clear()
2097 setFaceImage: function(eface){
2098 var path = this.faceStatus[eface];
2099 this.face.image = game.assets[path];
2101 myScale: function(_scaleX, _scaleY){
2102 this.face.scale(_scaleX,_scaleY);
2103 if(this.myCode === "REIMU"){
2104 this.okazari.x = -CHARA_WIDTH / 2;
2105 this.okazari.x = -CHARA_WIDTH / 2 - CHARA_WIDTH / 8;
2106 this.okazari.y = -CHARA_HEIGHT / 3 - CHARA_HEIGHT/7;
2108 this.okazari.x = -CHARA_WIDTH /2;
2109 this.okazari.y = -CHARA_HEIGHT / 2 - CHARA_HEIGHT/6;
2112 this.okazari.scale(_scaleX,_scaleY);
2113 this.hear.scale(_scaleX,_scaleY);
2114 this.scale(_scaleX,_scaleY);
2115 this.shadow.scale(_scaleX, _scaleY);
2117 destruct: function(){
2121 var Marisa = enchant.Class.create(Yukkuri,{
2122 initialize: function(x, y, grow){
2123 Yukkuri.call(this,x,y, grow);
2124 this.classname = "Marisa";
2125 this.myCode = "MARISA";
2126 this.myName = "まりさ";
2128 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2129 var json = net.load("./data/marisa/params.json");
2130 this.param = json.root.param;
2131 if(this.grow == EGrow.BABY){
2132 this.myName = "まりちゃ";
2133 this.param.range /= 4;
2135 else if(this.grow == EGrow.CHILD){
2136 this.param.range /= 3;
2138 else if(this.grow == EGrow.SUBADULT){
2139 this.param.range *= 0.8;
2141 this.shadow = new enchant.Sprite(64, 64);
2142 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2143 this.shadow.x = 0 + this.x;
2144 this.shadow.y = this.getWidth() / 16 + this.x;
2145 this.shadow.image._element.style.zIndex = 2;
2147 this._style.zIndex = 5;
2149 this.face = new enchant.Sprite(64, 64);
2150 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2151 this.face.x = -CHARA_WIDTH / 2;
2152 this.face.y = -CHARA_HEIGHT / 2;
2153 this.face._style.zIndex = 0;
2155 this.faceStatus ={};
2156 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2157 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2158 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2159 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2160 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2161 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2162 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2163 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2164 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2165 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2168 this.hear = new enchant.Sprite(64, 64);
2169 this.hear.image = game.assets[EResPath.MARISA_HEAR];
2170 this.hear.x = -CHARA_WIDTH / 2;
2171 this.hear.y = -CHARA_HEIGHT / 2;
2172 this.hear._style.zIndex = 0;
2174 this.okazari = new Okazari(this);
2176 // this.imgGroup._style.zIndex = 1;
2179 this.imgGroup.addChild(this.shadow);
2180 this.imgBody.addChild(this);
2181 this.imgBody.addChild(this.face);
2182 this.imgBody.addChild(this.hear);
2183 this.imgBody.addChild(this.okazari);
2184 this.myScale(this.myScaleX, this.myScaleY)
2185 if(this instanceof Player){
2186 // this.myScaleX = 0.5;
2187 // this.myScaleY = 0.5;
2189 this.budge = new enchant.Sprite(16, 16);
2190 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2191 this.imgBody.addChild(this.budge);
2192 this.budge.x -= this.getWidth()/2;
2193 this.budge.y -= this.getHeight()/2;
2194 this.budge.scale(this.myScaleX, this.myScaleX);
2196 this.imgGroup.width = this.getWidth();
2197 this.imgGroup.height = this.getHeight();
2198 this.imgGroup.addChild(this.imgBody);
2199 backgroundMap.addChild(this.imgGroup);
2200 this._tweet = new TTweet(148, 64);
2202 this.imgGroup.addChild(this._tweet);
2203 this.imgGroup.x = x;
2204 this.imgGroup.y = y;
2207 this.action = new Action(this);
2211 var Player = enchant.Class.create(Marisa,{
2212 initialize: function(x, y){
2213 // this.runEnterframe = function(){
2215 Marisa.call(this, x, y, EGrow.ADULT);
2216 this.classname = "Player";
2218 ctl.setPlayer(this);
2219 // this.removeEventListener('enterframe',this.runEnterframe);
2220 this.addEventListener('enterframe', function(){
2223 if(this.age%10 === 0 && this.age !== 0){
2224 // console.log("palyer:" + this.age);
2227 ///////////////////////////////////////////////
2228 //Action pattern debug
2229 if(game.input.left){
2230 // this.changeFace(EResPath.MARISA_FACE_TIRED);
2232 this.direction = EDirection.LEFT;
2234 if(game.input.right){
2236 this.direction = EDirection.RIGHT;
2241 if(game.input.down){
2245 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2246 ///////////////////////////////////////////////
2248 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2249 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
2251 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
2253 //- Display the circle of search range.
2254 // fieldBg.image.clear();
2255 // fieldBg.image.context.beginPath();
2256 // fieldBg.image.context.fillStyle = '#ff0000';
2257 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2258 // fieldBg.image.context.fill();
2262 var Reimu = enchant.Class.create(Yukkuri,{
2263 initialize: function(x, y, grow){
2264 Yukkuri.call(this,x,y, grow);
2265 this.classname = "Reimu";
2266 this.myCode = "REIMU";
2267 this.myName = "れいむ";
2269 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2270 var json = net.load("./data/reimu/params.json");
2271 this.param = json.root.param;
2272 if(this.grow == EGrow.BABY){
2273 this.myName = "れいみゅ";
2274 this.param.range /= 4;
2276 else if(this.grow == EGrow.CHILD){
2277 this.param.range /= 3;
2279 else if(this.grow == EGrow.SUBADULT){
2280 this.param.range *= 0.8;
2282 this.shadow = new enchant.Sprite(64, 64);
2283 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2284 this.shadow.x = 0 + this.x;
2285 this.shadow.y = this.getWidth() / 16 + this.x;
2286 this.shadow.image._element.style.zIndex = 2;
2288 this._style.zIndex = 5;
2290 this.face = new enchant.Sprite(64, 64);
2291 this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2292 this.face.x = -CHARA_WIDTH / 2;
2293 this.face.y = -CHARA_HEIGHT / 2;
2294 this.face._style.zIndex = 0;
2296 this.faceStatus ={};
2297 this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2298 this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2299 this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2300 this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2301 this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2302 this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2303 this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2304 this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2305 this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2306 this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2309 this.hear = new enchant.Sprite(64, 64);
2310 this.hear.image = game.assets[EResPathReimu.HEAR];
2311 this.hear.x = -CHARA_WIDTH / 2;
2312 this.hear.y = -CHARA_HEIGHT / 2;
2314 this.sub1 = new enchant.Sprite(64, 64);
2315 this.sub1.image = game.assets[EResPathReimu.SUB1];
2316 this.sub1.x = -CHARA_WIDTH / 2;
2317 this.sub1.y = -CHARA_HEIGHT / 2;
2319 this.okazari = new Okazari(this);
2321 // this.imgGroup._style.zIndex = 1;
2324 this.imgGroup.addChild(this.shadow);
2325 this.imgBody.addChild(this.okazari);
2326 this.imgBody.addChild(this);
2327 this.imgBody.addChild(this.face);
2328 this.imgBody.addChild(this.hear);
2329 this.imgBody.addChild(this.sub1);
2330 this.myScale(this.myScaleX, this.myScaleY)
2331 if(this instanceof Player){
2332 // this.myScaleX = 0.5;
2333 // this.myScaleY = 0.5;
2335 this.budge = new enchant.Sprite(16, 16);
2336 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2337 this.imgBody.addChild(this.budge);
2338 this.budge.x -= this.getWidth()/2;
2339 this.budge.y -= this.getHeight()/2;
2340 this.budge.scale(this.myScaleX, this.myScaleX);
2342 this.imgGroup.width = this.getWidth();
2343 this.imgGroup.height = this.getHeight();
2344 this.imgGroup.addChild(this.imgBody);
2345 backgroundMap.addChild(this.imgGroup);
2346 this._tweet = new TTweet(148, 64);
2348 this.imgGroup.addChild(this._tweet);
2349 this.imgGroup.x = x;
2350 this.imgGroup.y = y;
2353 this.action = new Action(this);
2358 game.onload = function(){
2361 def.ObjSprite = ObjSprite;
2362 def.Yukkuri = Yukkuri;
2363 def.nodeSort = nodeSort;
2364 mangTouch = new MangTouch(ctl);
2365 mangMsg = new MangMsg(ctl);
2366 ctl.setDefined(def);
2367 backgroundMap.image = game.assets[EResPath.MAP0];
2368 backgroundMap.loadData(_mapData);
2369 backgroundMap.collisionData = _collisionData;
2371 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2372 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2373 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2374 fieldBg.image = fieldSurface;
2378 windowFront.image = windowSurface;
2381 windowFront.opacity = 0.5;
2383 windowSurface.context.fillStyle = '#000';
2384 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2387 menuSurface.context.fillStyle = '#000';
2388 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2389 menuBg.image = menuSurface;
2390 menuBg.x = EMenuPos.X;
2391 menuBg.y = EMenuPos.Y;
2392 backgroundMap.addChild(fieldBg);
2393 mangIcon = new MangIcon(ctl, menuBg);
2395 game.rootScene.addChild(backgroundMap);
2396 game.rootScene.addChild(windowFront);
2397 game.rootScene.addChild(menuBg);
2399 // var labelGroup = new LabelGroup();
2400 mangLabel = new MangLabel(ctl, menuBg);
2401 // var info = new Label("ゆっくり");
2402 // info.color = "#ffffff";
2403 // info.font = "14px 'Times New Roman'";
2405 // info.y = GAME_HEIGHT / 2;
2406 // labelGroup.addChild(info);
2407 // menuBg.addChild(labelGroup);
2410 // var food = new def.Food("apple", 200, 250);
2411 backgroundMap.addChild(foodGroup);
2412 // backgroundMap.addChild(placeGroup);
2413 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2414 new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2415 new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2416 new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2417 new Reimu(PALYER_INIT_X + 400, PALYER_INIT_Y + 400, EGrow.ADULT);
2418 // new Unun(100, 100);
2419 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2423 game.rootScene.addEventListener('touchstart', function (e) {
2424 game.touched = true;
2425 var mang = mangTouch.get(ctl.getCurrentCommand());
2428 game.rootScene.addEventListener('touchmove', function (e) {
2429 var mang = mangTouch.get(ctl.getCurrentCommand());
2432 game.rootScene.addEventListener('touchend', function (e) {
2433 var mang = mangTouch.get(ctl.getCurrentCommand());
2435 game.touched = false;
2439 game.rootScene.addEventListener('enterframe', function(){
2441 mangLabel.draw(player);
2442 if(this.age%BASE_FPS == 0 ){
2447 this.addEventListener('enterframe', function(){
2448 //The priority processing of display instead of z-index
2450 backgroundMap.childNodes.sort(nodeSort);