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,
180 var EWalkAnimation = {
209 var ObjSprite = enchant.Class.create(enchant.Sprite,{
210 initialize: function (w, h){
211 enchant.Sprite.call(this, w, h);
216 // // new BoxLabel(this.ctl,100, e.x, e.y);
217 // var box = new Box(this.ctl, 200, 200);
219 // box.text("テスト\naaaaaa\nfffffffff\nテスト\naaaaaa\nfffffffff\nテスト\naaaaaa\n", e.x, e.y);
222 getStatusForDisplay: function (){
231 getWidth: function(){
234 getHeight: function(){
237 removeAll: function(){
244 enchant.Timeline.prototype.moveByEx = function(x, y, time, easing, eventFunctions){
255 //-Event register [onactionstart,onactiontick,onactionend]
256 if(eventFunctions !== undefined){
257 for(var key in eventFunctions){
258 params[key] = eventFunctions[key];
261 return this.tween(params);
263 function plusFrameScale(frame, scale){
264 return (frame/2) * (1 - scale)
269 include("./lang/ja.js");
270 window.onload = function(){
271 var nodeSort = function (a, b){
272 if(typeof a.id === "undefined" && typeof b.id === "undefined"){
275 else if(typeof a.id === "undefined"){
278 else if(typeof b.id === "undefined"){
283 if(a instanceof Box && b instanceof Box){
286 if(a instanceof Box){
289 if(b instanceof Box){
292 if(a instanceof SpriteGroup){
296 if(b instanceof SpriteGroup){
301 if(a instanceof Place){
302 ay += Math.round(a.height * 0.7);
304 if(b instanceof Place){
305 by += Math.round(b.height * 0.7);
308 if(ay < by)return -1;
309 else if(ay > by)return 1;
310 if(a.id < b.id)return -1;
311 else if(a.id > b.id)return 1;
317 var def = new Object();
318 var foodGroup = new Group();
319 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
320 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
321 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
322 var windowFront = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
323 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
327 var tmpName = EResPathReimu.getName();
329 for(var _v in EResPathReimu){
330 if(typeof EResPathReimu[_v] === "function")continue;
331 EResPath[_v + "_" + tmpName] = EResPathReimu[_v];
337 for(var _v in EResPath){
338 _loadArr[i] = EResPath[_v];
341 game.preload(_loadArr);
342 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
343 var backgroundMap = new MapGroup(16, 16);
344 include("./class.js");
345 include("./ctrl.js");
348 ctl.setBackgroundMap(backgroundMap);
349 var Action = enchant.Class.create({
350 initialize: function (yukkuri){
351 this.status = EAction.THINK;
352 this.yukkuri = yukkuri;
353 this.isMoving = false;
354 this.targetNode = null;
356 getStatus: function(){
359 setStatus: function(eaction){
360 this.status = eaction;
363 if(this.yukkuri.isDead()){
364 this.status = EAction.DEAD;
366 // else if(this.yukkuri.isSleep()){
367 // this.status = EAction.SLEEP;
378 case EAction.THINK_IN_HOME:
379 this.think_in_home();
382 if(this.yukkuri.age%2 === 0){
383 this.yukkuri.changeFace();
385 this.yukkuri.searchObjectMang.callEvent(this.yukkuri);
388 case EAction.MOVE_TO_EAT_START:
389 this.move_to_eat_start();
391 case EAction.MOVE_TO_EAT_UNDERWAY:
397 case EAction.SLEEP_START:
400 case EAction.SLEEP_WAIT:
405 case EAction.EAT_START:
408 case EAction.EAT_WAIT:
410 case EAction.UNUN_START:
413 case EAction.UNUN_WAIT:
415 case EAction.MOVE_TO_COMMAND:
416 this.move_to_command();
418 case EAction.UNUN_SMELL_START:
419 this.unun_smell_start();
421 case EAction.COMMUNICATE_START:
422 this.communicate_start();
424 case EAction.COMMUNICATE_WAIT:
426 case EAction.COMMUNICATE_RECV:
428 case EAction.MOVE_TO_PLACE_START_HOMELESS:
429 this.move_to_place_start_homeless();
431 case EAction.DECLARE_PLACE_HOMELESS:
432 this.declare_place_homeless();
434 case EAction.MOVE_TO_HUNT_START:
435 this.move_to_hunt_start();
437 case EAction.HUNT_START:
440 case EAction.MOVE_GOTO_HOME:
441 this.move_goto_home();
443 case EAction.IN_HOME:
448 this.yukkuri.reverse();
450 thinkHavePlace: function(){
451 var date = ctl.getDate();
452 if(this.yukkuri.isPlaceRange()){
455 if(date === EDate.EVENING
456 || date === EDate.NIGHT
457 || date === EDate.MIDNIGHT
459 this.setStatus(EAction.MOVE_GOTO_HOME);
462 else if(date === EDate.EVENING){
463 // if(this.yukkuri.isItemsMax()){
464 // this.setStatus(EAction.IN_HOME);
467 // this.setStatus(EAction.MOVE_TO_HUNT_START);
471 if(this.yukkuri.isVeryKuhuku()){
474 this.setStatus(EAction.MOVE_GOTO_HOME);
476 else if(this.yukkuri.isSleep()){
477 this.setStatus(EAction.SLEEP_START);
479 else if(this.yukkuri.getUnun() >= 80){
480 this.setStatus(EAction.UNUN_START);
483 this.yukkuri.changeFace();
487 think_in_home: function(){
488 var date = ctl.getDate();
489 if((date === EDate.MIDNIGHT || date === EDate.NIGHT)
490 && !this.yukkuri.isSleep()){
494 else if(date === EDate.EVENING){
498 //marisa is hunting move
499 if(this.yukkuri.beforeHuntingFood !== null){
500 new MoveToHuntEvent({
502 "targetNode": this.yukkuri.beforeHuntingFood,
504 "myYukkuri": this.yukkuri
508 this.setStatus(EAction.WALK);
512 move_to_eat_start : function(){
515 "targetNode": this.targetNode,
517 "myYukkuri": this.yukkuri
523 walk : function(retryCounter){
524 if(retryCounter > 15){
526 this.status = EAction.NONE;
527 console.log("retryCount over");
530 if(this.yukkuri.imgGroup.tl.queue.length === 0){
532 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
534 this.isMoving = false;
535 this.status = EAction.THINK;
539 var xpos = 150 + rand(40) - (retryCounter * 10);
540 var ypos = 150 + rand(40) - (retryCounter * 10);
543 this.yukkuri.vy = -ypos;
545 else if(rand(8) == 1){
546 this.yukkuri.vx = xpos;
547 this.yukkuri.vy = -ypos;
548 this.yukkuri.direction = EDirection.RIGHT;
550 else if(rand(8) == 2){
551 this.yukkuri.vx = xpos;
553 this.yukkuri.direction = EDirection.RIGHT;
555 else if(rand(8) == 3){
556 this.yukkuri.vx = xpos;
557 this.yukkuri.vy = ypos;
558 this.yukkuri.direction = EDirection.RIGHT;
560 else if(rand(8) == 4){
562 this.yukkuri.vy = ypos;
564 else if(rand(8) == 5){
565 this.yukkuri.vx = -xpos;
566 this.yukkuri.vy = ypos;
567 this.yukkuri.direction = EDirection.LEFT;
569 else if(rand(8) == 6){
570 this.yukkuri.vx = -xpos;
572 this.yukkuri.direction = EDirection.LEFT;
574 else if(rand(8) == 7){
575 this.yukkuri.vx = -xpos;
576 this.yukkuri.vy = -ypos;
577 this.yukkuri.direction = EDirection.LEFT;
579 if (this.yukkuri.vx || this.yukkuri.vy) {
580 var map = ctl.backgroundMap;
581 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
582 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
583 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
584 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
585 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
586 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
587 // console.log("X:" + this.yukkuri.moveX);
588 // console.log("Y:" + this.yukkuri.moveY);
589 this.isMoving = true;
590 this.yukkuri.reverse();
591 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
592 mangMsg.output(this.yukkuri,EMsg.WALK);
594 this.targetNode = null;
596 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
597 this.walk(retryCounter+1);
603 sleep_start: function(){
606 "myYukkuri": this.yukkuri
610 mangMsg.output(this.yukkuri, EMsg.DEAD);
611 this.yukkuri.tlPause();
612 this.yukkuri.setBodyImage(EBody.DEAD);
614 eat_start: function(){
617 "targetNode": this.targetNode,
619 "myYukkuri": this.yukkuri
623 unun_start: function(){
626 "myYukkuri": this.yukkuri
629 unun_smell_start: function(){
632 "myYukkuri": this.yukkuri
635 communicate_start:function(){
636 new ComSayHelloSendEvent({
638 "targetNode": this.targetNode,
640 "myYukkuri": this.yukkuri
643 move_to_place_start_homeless:function(){
644 new MoveToPlaceStartHomelessEvent({
645 "targetNode": this.targetNode,
647 "myYukkuri": this.yukkuri
650 declare_place_homeless:function(){
651 new DeclarePlaceHomelessEvent({
652 "targetNode": this.targetNode,
654 "myYukkuri": this.yukkuri
657 move_to_hunt_start:function(){
658 new MoveToHuntEvent({
660 "targetNode": this.targetNode,
662 "myYukkuri": this.yukkuri
665 hunt_start:function(){
668 "targetNode": this.targetNode,
670 "myYukkuri": this.yukkuri
673 move_goto_home:function(){
674 var place = this.yukkuri.getPlace();
675 new MoveGotoHomeEvent({
679 "myYukkuri": this.yukkuri
683 var place = this.yukkuri.getPlace();
688 "myYukkuri": this.yukkuri
691 move_to_command: function(){
695 this.yukkuri.clearSearchObject();
696 var nodes = ctl.getObjs();
700 for (var key in nodes) {
701 var node = nodes[key];
702 if(this.yukkuri.id === node.id)continue;
706 && !(this.targetNode instanceof Unun)
707 && this.yukkuri.within(node, this.yukkuri.getRange() / 3)) {
709 this.yukkuri.addSearchObject(ESearch.UNUN, node);
712 else if (node instanceof Food && node.amount > 0) {
713 if(this.yukkuri.within(node, this.yukkuri.getRange())){
714 this.yukkuri.addSearchObject(ESearch.FOOD, node);
718 else if(node instanceof Yukkuri){
719 if(this.yukkuri.within(node, this.yukkuri.getRange())){
720 this.yukkuri.addSearchObject(ESearch.YUKKURI, node);
724 else if(node instanceof Place){
725 if(this.yukkuri.within(node, this.yukkuri.getRange())){
726 this.yukkuri.addSearchObject(ESearch.PLACE, node);
730 this.status = EAction.WALK;
734 * Range範囲内のObjSprを管理する
735 * 注意!:ゆっくりプレイスを持って入るもののみ使用される
739 var SearchObjectMang = enchant.Class.create({
740 initialize: function (){
745 for(var key in ESearch){
746 var esearch = ESearch[key];
747 this.datas[esearch] = [];
750 add :function(esearch, node){
751 this.datas[esearch].push(node);
754 for(var key in ESearch){
755 var esearch = ESearch[key];
756 this.datas[esearch].length = 0;
758 // this.datas.length = 0;
761 get:function (esearch){
762 return this.datas[esearch];
764 getNear:function (esearch, yukkuri){
765 var objects = this.datas[esearch];
766 var nearDistance = null;
768 for(var i=0;i<objects.length;i++){
769 var object = objects[i];
770 var nowDistance = object.getX() + object.getY() - yukkuri.getX() + yukkuri.getY();
771 if(nearDistance === null || nearDistance > nowDistance){
772 nearDistance = nowDistance;
778 callEvent: function(yukkuri){
779 ununs = this.get(ESearch.UNUN);
780 if(ununs.length !== 0){
781 yukkuri.action.targetNode = yukkuri.getPlace();
782 yukkuri.action.setStatus(EAction.UNUN_SMELL_START);
785 if(yukkuri.isVeryKuhuku()){
787 var foods = this.get(ESearch.FOOD);
788 if(foods.length === 0 && yukkuri.isPlace()){
790 yukkuri.action.targetNode = yukkuri.getPlace();
791 yukkuri.action.setStatus(EAction.MOVE_GOTO_HOME);
794 var foods = this.get(ESearch.FOOD);
795 food = this.getNear(ESearch.FOOD, yukkuri);
797 yukkuri.action.targetNode = food;
798 yukkuri.action.setStatus(EAction.MOVE_TO_EAT_START);
804 if(yukkuri.isSleep()){
805 yukkuri.action.setStatus(EAction.SLEEP_START);
809 else if(yukkuri.getUnun() >= 80){
810 yukkuri.action.setStatus(EAction.UNUN_START);
815 if(!yukkuri.isItemsMax() && yukkuri.isPlace()){
816 food = this.getNear(ESearch.FOOD, yukkuri);
818 yukkuri.action.targetNode = food;
819 yukkuri.action.setStatus(EAction.MOVE_TO_HUNT_START);
823 var searchYukkuri = this.getNear(ESearch.YUKKURI, yukkuri);
824 if(searchYukkuri !== null && yukkuri.isCommunication(searchYukkuri)){
825 yukkuri.action.targetNode = searchYukkuri;
826 yukkuri.action.setStatus(EAction.COMMUNICATE_START);
829 if(!yukkuri.isPlace()){
830 var searchYukkuri = this.getNear(ESearch.PLACE, yukkuri);
831 if(searchYukkuri != null && !searchYukkuri.isOwner()){
832 yukkuri.action.targetNode = searchYukkuri;
833 yukkuri.action.setStatus(EAction.MOVE_TO_PLACE_START_HOMELESS);
837 yukkuri.action.setStatus(EAction.WALK);
842 var Event = enchant.Class.create({
843 initialize: function (_data){
846 onactionstart:function(self){
848 if(typeof e === "undefined")return;
851 onactiontick:function(self){
853 if(typeof e === "undefined")return;
856 onactionend:function(self){
858 if(typeof e === "undefined")return;
862 var WalkEvent = enchant.Class.create(Event,{
863 initialize: function (_data){
865 this.yukkuri = _data.myYukkuri;
866 this.action = _data.action;
868 mangMsg.output(this.yukkuri, EMsg.SLEEP);
869 this.action.setStatus(EAction.SLEEP_WAIT);
870 this.yukkuri.setFaceImage(EFace.SLEEP);
871 this.yukkuri.tlPause();
873 this.yukkuri.addEventListener('enterframe', function() {
874 var yukkuri = self.yukkuri;
882 var SleepEvent = enchant.Class.create(Event,{
883 initialize: function (_data){
885 this.yukkuri = _data.myYukkuri;
886 this.action = _data.action;
888 mangMsg.output(this.yukkuri, EMsg.SLEEP);
889 this.action.setStatus(EAction.SLEEP_WAIT);
890 this.yukkuri.setFaceImage(EFace.SLEEP);
891 this.yukkuri.tlPause();
894 this.yukkuri.addEventListener('enterframe', function() {
895 var yukkuri = self.yukkuri;
896 if(yukkuri.age%2 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
897 if(yukkuri.param.sleep <= 0){
898 yukkuri.param.sleep = 0;
899 this.removeEventListener("enterframe",arguments.callee);
900 mangMsg.output(self.yukkuri, EMsg.GET_UP);
901 yukkuri.setFaceImage(EFace.NORMAL);
903 // self.action.setStatus(EAction.WAIT);
904 if(this.data.nextStatus !== undefined){
905 self.action.setStatus(this.data.nextStatus);
907 self.action.setStatus(EAction.THINK);
914 var UnunEvent = enchant.Class.create(Event,{
915 initialize: function (_data){
917 this.yukkuri = _data.myYukkuri;
918 this.action = _data.action;
919 this.action.setStatus(EAction.UNUN_WAIT);
920 mangMsg.output(this.yukkuri, EMsg.UNUN);
921 this.yukkuri.setFaceImage(EFace.HAPPY2);
924 this.yukkuri.wait(sec, {
925 "onactionend": this.onactionend(this)
928 onactionend:function(self){
930 if(typeof e === "undefined")return;
932 self.action.setStatus(EAction.WAIT);
933 mangMsg.output(self.yukkuri, EMsg.UNUN_END);
935 "waitframe": FPS * 1.5,
936 "action": self.action,
937 "myYukkuri": self.yukkuri
942 var WaitEvent = enchant.Class.create(Event,{
943 initialize: function (_data){
945 this.yukkuri = _data.myYukkuri;
946 this.action = _data.action;
947 this.waitframe = _data.waitframe;
948 this.yukkuri.wait(this.waitframe, {
949 "onactionstart": this.onactionstart(this),
950 "onactiontick": this.onactiontick(this),
951 "onactionend": this.onactionend(this)
954 onactionend:function(self){
956 if(typeof e === "undefined")return;
957 self.action.setStatus(EAction.THINK);
961 var UnunSmellEvent = enchant.Class.create(Event,{
962 initialize: function (_data){
964 this.yukkuri = _data.myYukkuri;
965 this.action = _data.action;
966 this.action.setStatus(EAction.UNUN_SMELL_WAIT);
967 mangMsg.output(this.yukkuri, EMsg.UNUN_SMELL);
968 this.yukkuri.setFaceImage(EFace.CRY1);
970 this.yukkuri.setYukkuri(this.yukkuri.getYukkuri() - 3);
971 this.yukkuri.wait(sec, {
972 "onactionend": this.onactionend(this)
975 onactionend:function(self){
977 if(typeof e === "undefined")return;
978 self.action.setStatus(EAction.WALK);
983 var EatEvent = enchant.Class.create(Event,{
984 initialize: function (_data){
986 this.yukkuri = _data.myYukkuri;
987 this.food = _data.targetNode;
988 this.action = _data.action;
989 this.action.setStatus(EAction.EAT_WAIT);
992 var sec = BASE_FPS * 3;
993 if(this.yukkuri.eat(this.food)){
994 mangMsg.output(this.yukkuri, EMsg.EAT);
995 this.yukkuri.setFaceImage(EFace.EAT2);
998 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
999 this.yukkuri.setFaceImage(EFace.CRY2);
1001 this.yukkuri.wait(sec, {
1002 "onactionend": this.onactionend(this)
1005 onactionend:function(self){
1007 if(typeof e === "undefined")return;
1008 if(self.food.getAmount() <= 0 || self.yukkuri.isManpuku()){
1009 self.action.setStatus(EAction.THINK);
1010 self.yukkuri.setFaceImage(EFace.NORMAL);
1012 self.action.setStatus(EAction.EAT_START);
1019 * -When yukkuri find Food.
1022 * targetNode: enchant.Node
1026 var MoveToEatEvent = enchant.Class.create(Event,{
1027 initialize: function (_data){
1029 this.yukkuri = this.data.myYukkuri;
1030 this.action = this.data.action;
1032 var yukkuri = this.yukkuri;
1033 var node = this.data.targetNode;
1035 if(this.data.type == "food"){
1036 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1037 yukkuri.vx = node.x - yukkuri.getX() + node.width / 2;
1038 yukkuri.vy = node.y - yukkuri.getY() - yukkuri.getHeight() / 2 + node.height / 2;
1039 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1040 var frame = distance + distance/5 + 1;
1041 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1042 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1045 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1046 "onactionstart": this.onactionstart(this),
1047 "onactiontick": this.onactiontick(this),
1048 "onactionend": this.onactionend(this)
1052 onactionstart:function(self){
1054 if(typeof e === "undefined")return;
1055 mangMsg.output(self.yukkuri, EMsg.TARGETING_EAT);
1058 onactiontick:function(self){
1060 if(typeof e === "undefined")return;
1063 onactionend:function(self){
1065 if(typeof e === "undefined")return;
1066 self.action.setStatus(EAction.EAT_START);
1070 var MoveToHuntEvent = enchant.Class.create(Event,{
1071 initialize: function (_data){
1073 this.yukkuri = this.data.myYukkuri;
1074 this.action = this.data.action;
1076 var yukkuri = this.yukkuri;
1077 var node = this.data.targetNode;
1080 var nodeWidth = node.width;
1081 var nodeHeight = node.height;
1085 if(this.data.type == "food"){
1086 this.action.setStatus(EAction.WAIT);
1087 yukkuri.vx = nodeX - yukkuri.getX() + nodeWidth / 2;
1088 yukkuri.vy = nodeY - yukkuri.getY() - yukkuri.getHeight() / 2 + nodeHeight / 2;
1089 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1090 var frame = distance + distance/5 + 1;
1091 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1092 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1094 mangMsg.output(yukkuri, EMsg.TARGETING_EAT);
1096 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1097 "onactionend": this.onactionend(this)
1101 onactionend:function(self){
1103 if(typeof e === "undefined")return;
1104 self.action.setStatus(EAction.HUNT_START);
1108 var HuntStartEvent = enchant.Class.create(Event,{
1109 initialize: function (_data){
1110 Event.call(this, _data);
1113 this.yukkuri = _data.myYukkuri;
1114 this.food = _data.targetNode;
1115 this.action = _data.action;
1116 this.action.setStatus(EAction.WAIT);
1117 this.huntingStatus = "hunting";
1119 this.yukkuri.beforeHuntingFood = this.food;
1120 var sec = BASE_FPS * 8;
1121 if(this.yukkuri.hunt(this.food)){
1122 this.huntingStatus = "hunting";
1123 mangMsg.output(this.yukkuri, EMsg.HUNT);
1124 this.yukkuri.setFaceImage(EFace.HAPPY1);
1126 if(this.yukkuri.isItemsMax()){
1127 this.huntingStatus = "return";
1128 mangMsg.output(this.yukkuri, EMsg.REHUNT);
1129 this.yukkuri.setFaceImage(EFace.NORMAL);
1131 this.huntingStatus = "cry";
1132 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1133 this.yukkuri.setFaceImage(EFace.CRY2);
1137 this.yukkuri.wait(sec, {
1138 "onactiontick": this.onactiontick(this),
1139 "onactionend": this.onactionend(this)
1142 onactiontick:function(self){
1144 if(typeof e === "undefined")return;
1146 if(self.huntingStatus == "hunting" && self.tick > BASE_FPS * 2){
1147 if(this.age%(BASE_FPS * 3) == 0){
1148 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1153 onactionend:function(self){
1155 if(typeof e === "undefined")return;
1156 if(self.huntingStatus == "hunting"){
1157 if(self.yukkuri.isItemsMax()){
1158 self.action.setStatus(EAction.MOVE_GOTO_HOME);
1159 mangMsg.output(self.yukkuri, EMsg.MOVE_GOTO_HOME);
1161 self.action.setStatus(EAction.HUNT_START);
1164 else if(self.huntingStatus == "return"){
1165 self.action.setStatus(EAction.THINK);
1167 else if(self.huntingStatus === "cry"){
1168 self.action.setStatus(EAction.THINK);
1173 var MoveGotoHomeEvent = enchant.Class.create(Event,{
1174 initialize: function (_data){
1176 this.yukkuri = this.data.myYukkuri;
1177 this.action = this.data.action;
1179 var yukkuri = this.yukkuri;
1180 var place = this.data.targetNode;
1182 if(this.data.type == "hunt_end"){
1183 this.action.setStatus(EAction.WAIT);
1184 yukkuri.vx = place.x - yukkuri.getX() + place.width / 2;
1185 yukkuri.vy = place.y - yukkuri.getY() - yukkuri.getHeight() / 2 + place.height;
1186 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1187 var frame = distance + distance/2 + 1 ;
1188 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1189 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1191 mangMsg.output(this.yukkuri, EMsg.MOVE_GOTO_HOME)
1193 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1194 "onactiontick": this.onactiontick(this),
1195 "onactionend": this.onactionend(this)
1199 onactiontick:function(self){
1201 if(typeof e === "undefined")return;
1202 if(this.age%(BASE_FPS * 5) == 0){
1203 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1207 onactionend:function(self){
1209 if(typeof e === "undefined")return;
1210 self.action.setStatus(EAction.IN_HOME);
1214 var InHomeEvent = enchant.Class.create(Event,{
1215 initialize: function (_data){
1217 this.yukkuri = this.data.myYukkuri;
1218 this.action = this.data.action;
1220 var yukkuri = this.yukkuri;
1221 var place = this.data.targetNode;
1222 if(yukkuri.isVeryKuhuku()){
1224 new EatInHomeEvent({
1225 "targetNode": place,
1226 "action": this.action,
1227 "myYukkuri": yukkuri
1231 mangMsg.output(self.yukkuri, EMsg.EAT_FAILED);
1234 this.action.setStatus(EAction.WAIT);
1235 var items = this.yukkuri.getItems();
1236 if(items.length > 0){
1237 place.setItems(items);
1241 var sec = BASE_FPS * 10;
1242 this.yukkuri.wait(sec, {
1243 "onactiontick": this.onactiontick(this),
1244 "onactionend": this.onactionend(this)
1247 onactiontick:function(self){
1249 if(typeof e === "undefined")return;
1250 if(this.age%(BASE_FPS * 5) == 0){
1251 mangMsg.output(self.yukkuri, EMsg.YYUYYU)
1255 onactionend:function(self){
1257 if(typeof e === "undefined")return;
1258 self.action.setStatus(EAction.THINK);
1262 var EatInHomeEvent = enchant.Class.create(Event,{
1263 initialize: function (_data){
1265 this.yukkuri = _data.myYukkuri;
1266 this.place = _data.targetNode;
1267 this.action = _data.action;
1268 this.action.setStatus(EAction.EAT_WAIT);
1270 var sec = BASE_FPS * 3;
1271 var foodHash = this.place.getFoodHash();
1272 if(foodHash !== false && this.yukkuri.eat(foodHash)){
1273 mangMsg.output(this.yukkuri, EMsg.EAT);
1274 this.yukkuri.setFaceImage(EFace.EAT2);
1277 mangMsg.output(this.yukkuri, EMsg.EAT_FAILED);
1278 this.yukkuri.setFaceImage(EFace.CRY2);
1281 this.yukkuri.wait(sec, {
1282 "onactionend": this.onactionend(this)
1285 onactionend:function(self){
1287 if(typeof e === "undefined")return;
1288 if(self.place.isFood() && self.yukkuri.isManpuku()){
1290 self.action.setStatus(EAction.THINK);
1291 self.yukkuri.setFaceImage(EFace.NORMAL);
1293 new EatInHomeEvent({
1294 "targetNode": self.place,
1295 "action": self.action,
1296 "myYukkuri": self.yukkuri
1304 var MoveCommandEvent = enchant.Class.create(Event,{
1305 initialize: function (_data){
1307 this.yukkuri = this.data.myYukkuri;
1308 this.action = this.data.action;
1309 this.vx = this.data.vx;
1310 this.vy = this.data.vy;
1312 var yukkuri = this.yukkuri;
1313 this.action.status = EAction.MOVE_TO_EAT_UNDERWAY;
1314 yukkuri.vx = node.x - yukkuri.getX();
1315 yukkuri.vy = node.y - yukkuri.getY();
1316 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1317 var frame = distance + 1;
1318 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1320 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1321 "onactionstart": this.onactionstart(this),
1322 "onactiontick": this.onactiontick(this),
1323 "onactionend": this.onactionend(this)
1326 onactionstart:function(self){
1328 if(typeof e === "undefined")return;
1331 onactiontick:function(self){
1333 if(typeof e === "undefined")return;
1336 onactionend:function(self){
1338 if(typeof e === "undefined")return;
1339 self.action.setStatus(EAction.THINK);
1344 * Say hello contact to send communication .
1346 var ComSayHelloSendEvent = enchant.Class.create(Event,{
1347 initialize: function (_data){
1349 this.yukkuri = _data.myYukkuri;
1350 this.targetYukkuri = _data.targetNode;
1351 this.action = _data.action;
1352 this.action.setStatus(EAction.COMMUNICATE_WAIT);
1353 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1355 this.targetYukkuri.action.setStatus(EAction.COMMUNICATE_RECV);
1356 this.targetYukkuri.tlPause();
1357 this.yukkuri.tlPause();
1358 this.yukkuri.syncDirection(this.targetYukkuri);
1360 this.yukkuri.addAddress(this.targetYukkuri);
1361 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1363 var sec = BASE_FPS * 2;
1364 this.yukkuri.wait(sec, {
1365 "onactiontick": this.onactiontick(this),
1366 "onactionend": this.onactionend(this)
1369 onactiontick:function(self){
1371 if(typeof e === "undefined")return;
1374 onactionend:function(self){
1376 if(typeof e === "undefined")return;
1377 new ComSayHelloRecvEvent({
1379 "targetNode": self.yukkuri,
1380 "action": self.targetYukkuri.action,
1381 "myYukkuri": self.targetYukkuri
1386 var ComSayHelloRecvEvent = enchant.Class.create(Event,{
1387 initialize: function (_data){
1389 this.yukkuri = _data.myYukkuri;
1390 this.targetYukkuri = _data.targetNode;
1391 this.action = _data.action;
1392 mangMsg.output(this.yukkuri, EMsg.SAY_HELLO, this.targetYukkuri);
1393 this.yukkuri.addAddress(this.targetYukkuri);
1394 this.yukkuri.getAddress(this.targetYukkuri).isGreeting = true;
1396 var sec = BASE_FPS * 2;
1397 this.yukkuri.wait(sec, {
1398 "onactiontick": this.onactiontick(this),
1399 "onactionend": this.onactionend(this)
1402 onactiontick:function(self){
1404 if(typeof e === "undefined")return;
1407 onactionend:function(self){
1409 if(typeof e === "undefined")return;
1410 self.action.setStatus(EAction.THINK);
1412 self.yukkuri.action.setStatus(EAction.THINK);
1413 self.yukkuri.animation();
1414 self.targetYukkuri.action.setStatus(EAction.THINK);
1415 self.targetYukkuri.animation();
1419 var MoveToPlaceStartHomelessEvent = enchant.Class.create(Event,{
1420 initialize: function (_data){
1422 this.yukkuri = this.data.myYukkuri;
1423 this.action = this.data.action;
1425 var yukkuri = this.yukkuri;
1426 var node = this.data.targetNode;
1428 this.action.status = EAction.MOVE_TO_PLACE_HOMELESS_UNDERWAY;
1429 yukkuri.vx = node.x + node.width /2 - yukkuri.getX();
1430 yukkuri.vy = node.y + node.height - yukkuri.getY() - yukkuri.getHeight() / 2;
1431 var distance = (Math.abs(yukkuri.vx) + Math.abs(yukkuri.vy)) / 2;
1432 var frame = distance + distance/5 + 1;
1433 frame += plusFrameScale(frame, this.yukkuri.getMyScale());
1435 yukkuri.direction = yukkuri.vx > 0 ? EDirection.RIGHT : EDirection.LEFT;
1438 yukkuri.moveBy(yukkuri.vx, yukkuri.vy, frame, {
1439 "onactionend": this.onactionend(this)
1442 onactionend:function(self){
1444 if(typeof e === "undefined")return;
1445 self.action.setStatus(EAction.DECLARE_PLACE_HOMELESS);
1447 self.yukkuri = null;
1452 var DeclarePlaceHomelessEvent = enchant.Class.create(Event,{
1453 initialize: function (_data){
1455 this.yukkuri = _data.myYukkuri;
1456 this.place = _data.targetNode;
1457 this.action = _data.action;
1458 this.action.setStatus(EAction.WAIT);
1461 var sec = BASE_FPS * 3;
1462 this.yukkuri.declarePlace(this.place);
1463 this.place.setOwner(this.yukkuri);
1464 mangMsg.output(this.yukkuri, EMsg.DECLARE_PLACE);
1466 this.yukkuri.setFaceImage(EFace.NORMAL);
1467 this.yukkuri.wait(sec, {
1468 "onactionend": this.onactionend(this)
1471 onactionend:function(self){
1473 if(typeof e === "undefined")return;
1474 self.action.setStatus(EAction.THINK);
1479 var Food = enchant.Class.create(ObjSprite,{
1480 initialize: function (type, x, y){
1481 this.classname = "Food";
1482 //一つにつきgiveの値分、hunguryを減少させられる
1483 if(type == "apple"){
1484 ObjSprite.call(this,16,16);
1485 this.image = game.assets[EResPath.OBJECT];
1489 }else if(type == "grass"){
1490 ObjSprite.call(this,64,64);
1491 this.image = game.assets[EResPath.GRASS];
1498 foodGroup.addChild(this);
1499 this.addEventListener('enterframe', function(){
1500 if(this.amount <= 0){
1505 getAmount: function(){
1508 getGive: function(){
1512 var Place = enchant.Class.create(ObjSprite,{
1513 initialize: function (type, x, y){
1514 ObjSprite.call(this,128,128);
1515 this.image = game.assets[EResPath.PLACE_TREE];
1516 this.x = x - this.width / 2;
1517 this.y = y - this.height / 2;
1518 backgroundMap.addChild(this);
1521 for(var key in EFood){
1522 var efood = EFood[key];
1523 this.foods[efood] = 0;
1525 // this.addEventListener('enterframe', function(){
1526 // if(this.age%10 === 0 && this.age !== 0){
1527 // console.log("x/y " + this.x + "/" + this.y);
1529 // if(game.input.left){
1532 // if(game.input.right){
1535 // if(game.input.up){
1538 // if(game.input.down){
1543 getStatusForDisplay: function(){
1546 if(this.owner == null)ownerId = "なし";
1547 else ownerId = this.owner.id;
1548 ret += "プレイスID " + this.id + "\n";
1549 ret += "オーナーID " + ownerId + "\n";
1550 ret += "食料うめぇ " + this.foods[EFood.GREAT] + "\n";
1551 ret += "食料それなりー " + this.foods[EFood.NORMAL] + "\n";
1552 ret += "食料にがにが " + this.foods[EFood.BAD] + "\n";
1555 setItems:function(items){
1556 var len = items.length;
1557 for(var i=0; i<len; i++){
1558 var item = items[i];
1559 if(item instanceof Food){
1560 this.foods[EFood.NORMAL]++;
1567 for(var key in EFood){
1568 var efood = EFood[key];
1569 ret += this.foods[efood];
1573 getFoodHash:function(){
1574 if(this.foods[EFood.GREAT] !== 0){
1575 this.foods[EFood.GREAT]--;
1576 return {give:20,yukkuri:15,unun:20};
1578 else if(this.foods[EFood.NORMAL] !== 0){
1579 this.foods[EFood.NORMAL]--;
1580 return {give:10,yukkuri:5,unun:10};
1582 else if(this.foods[EFood.BAD] !== 0){
1583 this.foods[EFood.BAD]--;
1584 return {give:10,yukkuri:-2,unun:10};
1588 setOwner: function(yukkuri){
1589 this.owner = yukkuri;
1591 isOwner: function(){
1592 return this.owner !== null;
1595 var Unun = enchant.Class.create(ObjSprite,{
1596 initialize: function (x, y){
1597 this.classname = "Unun";
1598 ObjSprite.call(this,32,32);
1599 this.image = game.assets[EResPath.YUKKURI_UNUN];
1602 backgroundMap.addChild(this);
1603 this.lifetime = 60 * 24 * 3;
1604 this.addEventListener('enterframe', this.runEnterframe(this));
1605 // game.rootScene.addEventListener('enterframe', this.runEnterframe(this));
1608 runEnterframe:function(self){
1610 if(typeof e === "undefined")return;
1611 if(this.age%BASE_FPS === 0 && this.age !== 0){
1613 if(self.lifetime <= 0){
1614 this.parentNode.removeChild(this);
1615 ctl.backgroundMap.removeChild(this);
1616 ctl.removeObj(this);
1623 // runEnterframe: function(){
1624 // console.log("enterframe:" + this.id);
1627 var Okazari = enchant.Class.create(enchant.Sprite,{
1628 initialize: function(yukkuri){
1629 this.classname = "Okazari";
1630 if(yukkuri.myCode === "REIMU"){
1631 enchant.Sprite.call(this, 80, 32);
1632 this.image = game.assets[EResPathReimu.OKAZARI];
1633 this.x = -CHARA_WIDTH / 2;
1636 enchant.Sprite.call(this, 64, 64);
1637 this.image = game.assets[EResPath.OKAZARI];
1638 this.x = -CHARA_WIDTH / 2;
1639 this.y = -CHARA_HEIGHT / 2 - yukkuri.getWidth()/6;
1641 this.yukkuri = yukkuri;
1643 getWidth: function(){
1645 // return this.width * this.yukkuri.myScaleX;
1647 getHeight: function(){
1649 // return this.height * this.yukkuri.myScaleY;
1652 var Address = enchant.Class.create({
1653 initialize: function(yukkuri){
1654 this.friendlyLv = 1;
1655 this.yukkuri = yukkuri;
1656 this.isGreeting = false;
1657 this.greetingWaitFrame = 0;
1659 "beginSayHello" : false,
1664 set:function(key, value){
1665 this.comMatrix[key] = value;
1668 return this.comMatrix[key];
1672 var Yukkuri = enchant.Class.create(ObjSprite,{
1673 initialize: function(x, y, grow){
1674 ObjSprite.call(this, 64, 64);
1675 this.searchObjectMang = new SearchObjectMang();
1677 this.myCode = "YUKKURI";
1678 this.myName = "ゆっくり";
1679 this.beforeHuntingFood = null;
1680 if(grow == EGrow.ADULT){
1685 else if(grow == EGrow.SUBADULT){
1686 this.myScaleX = 0.8;
1687 this.myScaleY = 0.8;
1690 else if(grow == EGrow.CHILD){
1691 this.myScaleX = 0.6;
1692 this.myScaleY = 0.6;
1695 else if(grow == EGrow.BABY){
1696 this.myScaleX = 0.3;
1697 this.myScaleY = 0.3;
1701 // ctl.game.rootScene.addEventListener('touchstart', this.touchstart);
1702 this.classname = "Yukkuri";
1703 this.addressBook = {};
1704 this.imgGroup = new SpriteGroup();
1705 this.imgBody = new SpriteGroup();
1706 this.imgGroup.id = guid();
1707 this.imgBody.id = guid();
1708 this.x = -CHARA_WIDTH / 2;
1709 this.y = -CHARA_HEIGHT / 2;
1712 this.image = game.assets[EResPath.YUKKURI_BASE];
1713 this.direction = EDirection.RIGHT;
1714 this.addEventListener('enterframe', this.runEnterframe);
1715 this.bodyStatus ={};
1716 this.bodyStatus[EBody.NORMAL] = EResPath.YUKKURI_BASE;
1717 this.bodyStatus[EBody.DEAD] = EResPath.YUKKURI_BODY_DEAD;
1718 this.walkAnimationStatus = EWalkAnimation.END;
1722 runEnterframe:function(){
1725 if(this.isDead())return;
1736 if(this.direction == EDirection.RIGHT){
1737 this.imgBody.scaleX = 1;
1739 else if(this.direction == EDirection.LEFT){
1740 this.imgBody.scaleX = -1;
1743 tweet:function(text){
1744 text = text.replace(/%name%/g, this.myName);
1745 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
1747 moveTo:function(x, y, time){
1748 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
1750 moveBy:function(x, y, time, eventFunctions){
1754 return self.imgGroup.x + x;
1757 return self.imgGroup.y + y;
1760 easing: enchant.Easing.SIN_EASEINOUT
1762 //-Event register [onactionstart,onactiontick,onactionend]
1763 if(eventFunctions !== undefined){
1764 for(var key in eventFunctions){
1765 params[key] = eventFunctions[key];
1768 return this.imgGroup.tl.tween(params);
1770 wait:function(frame, eventFunctions){
1771 this.moveBy(0,1,frame,eventFunctions);
1776 animation: function(){
1779 frame += plusFrameScale(frame, this.getMyScale());
1781 move -= plusFrameScale(move, this.getMyScale());
1782 if(this.walkAnimationStatus == EWalkAnimation.END){
1784 this.imgBody.tl.moveByEx(0, -move, frame, enchant.Easing.SWING, {
1785 "onactionstart": function(e){
1786 this.walkAnimationStatus = EWalkAnimation.START;
1789 .moveByEx(0, move, frame, enchant.Easing.SWING,
1791 "onactionend": function(e){
1792 this.walkAnimationStatus = EWalkAnimation.END;
1797 this.imgBody.tl.loop();
1800 getMyScale: function(){
1801 return (this.myScaleX + this.myScaleY) / 2;
1803 getWidth: function(){
1804 return this.width * this.myScaleX;
1806 getHeight: function(){
1807 return this.height * this.myScaleY;
1810 return this.imgGroup.x;
1813 return this.imgGroup.y;
1816 this.imgGroup.x += x;
1818 // this.shadow.x += x;
1819 // this._tweet.x += x;
1822 this.imgGroup.y += y;
1824 // this.shadow.y += y;
1825 // this._tweet.y += y;
1827 // changeFace: function(erespath){
1828 // this.face.image = game.assets[erespath];
1830 loadParamsXML: function(url){
1831 var http = new JKL.ParseXML( url );
1832 return http.parse();
1834 runYukkuri: function(){
1835 if(this.param.hungry > 70){
1836 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
1837 this.param.yukkuri -= 1;
1840 else if(this.param.hungry < 10){
1841 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
1844 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
1845 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
1847 runHungry: function(){
1848 if(this.age%50 === 0 && this.age !== 0)this.param.hungry++;
1849 if(this.param.hungry >= 100)this.param.hungry = 100;
1851 runUnun: function(){
1852 if(this.age%50 === 0 && this.age !== 0)this.param.unun++;
1853 if(this.param.unun >= 100)this.param.unun = 100;
1855 runSleep: function(){
1856 if(this.action.getStatus() != EAction.SLEEP_START && this.action.getStatus() != EAction.SLEEP_WAIT){
1857 if(this.age%80 === 0 && this.age !== 0)this.param.sleep++;
1858 if(this.param.sleep >= 100){
1859 this.param.sleep = 100;
1863 runAddress: function(){
1864 for(var key in this.addressBook){
1865 var address = this.addressBook[key];
1867 if(address.isGreeting){
1868 address.greetingWaitFrame++;
1869 if(address.greetingWaitFrame >= DAY){
1870 address.greetingWaitFrame = 0;
1871 address.isGreeting = false;
1876 changeFace: function(){
1877 if(this.param.yukkuri >= 80){
1878 this.setFaceImage(EFace.HAPPY1);
1880 else if(this.param.yukkuri >= 50){
1881 this.setFaceImage(EFace.NORMAL);
1883 else if(this.param.yukkuri >= 30){
1884 this.setFaceImage(EFace.TIRED);
1886 else if(this.param.yukkuri >= 10){
1887 this.setFaceImage(EFace.CRY1);
1889 else if(this.param.yukkuri >= 1){
1890 this.setFaceImage(EFace.CRY2);
1893 getRange: function(){
1894 return this.param.range;
1896 isSleep: function(){
1897 return this.param.sleep >= 100;
1900 return this.param.yukkuri <= 0;
1902 isManpuku: function(){
1903 return this.param.hungry <= 20;
1905 isKuhuku: function(){
1906 return this.param.hungry >= 40;
1908 isVeryKuhuku: function(){
1909 return this.param.hungry >= 80;
1911 getYukkuri: function(){
1912 return this.param.yukkuri;
1914 setYukkuri: function(yukkuri){
1915 this.param.yukkuri = yukkuri;
1916 if(this.param.yukkuri < 0)this.param.yukkuri = 0;
1918 getHungry: function(){
1919 return this.param.hungry;
1921 setHungry: function(hungry){
1922 this.param.hungry = hungry;
1923 if(this.param.hungry < 0)this.param.hungry = 0;
1925 getUnun: function(){
1926 return this.param.unun;
1928 setUnun: function(unun){
1929 this.param.unun = unun;
1930 if(this.param.unun < 0)this.param.unun = 0;
1934 if(food instanceof Food){
1936 if(food.amount > 0){
1938 this.setHungry(this.param.hungry - food.getGive());
1939 this.setUnun(this.getUnun() + food.getGive() / 4);
1940 this.setYukkuri(this.getYukkuri() + 5);
1943 this.setYukkuri(this.getYukkuri() - 5);
1949 this.setHungry(this.param.hungry - food.give);
1950 this.setUnun(this.getUnun() + food.unun);
1951 this.setYukkuri(this.getYukkuri() + food.yukkuri);
1958 hunt:function(food){
1959 if(food.amount > 0){
1960 if(!this.isItemsMax()){
1962 this.items.push(food);
1963 this.setYukkuri(this.getYukkuri() + 1);
1969 declarePlace: function(place){
1972 getPlace:function(){
1975 isPlace: function(){
1976 return this.place !== null;
1980 if(this.direction == EDirection.RIGHT){
1981 new Unun(this.getX(), this.getY() + this.getHeight()/5 );
1983 new Unun(this.getX() - this.getWidth()/5, this.getY() + this.getHeight()/5 );
1987 setBodyImage: function(ebody){
1988 var path = this.bodyStatus[ebody];
1989 this.image = game.assets[path];
1992 // this.imgBody.tl.pause();
1993 // this.imgGroup.tl.pause();
1994 this.imgBody.tl.clear();
1995 this.imgGroup.tl.clear();
1996 this.imgBody.tl.unloop();
1997 this.imgGroup.tl.unloop();
2001 tlResume: function(){
2002 // this.imgBody.tl.resume();
2003 // this.imgGroup.tl.resume();
2006 syncDirection:function(senderYukkuri){
2007 if(this.getX() > senderYukkuri.getX()){
2008 this.direction = EDirection.LEFT;
2009 senderYukkuri.direction = EDirection.RIGHT;
2011 this.direction = EDirection.RIGHT;
2012 senderYukkuri.direction = EDirection.LEFT;
2015 isCommunication: function(yukkuri){
2016 if(this.addressBook[yukkuri.id] === undefined) return true;
2017 if(this.addressBook[yukkuri.id].isGreeting) return false;
2020 addAddress: function(yukkuri){
2021 this.addressBook[yukkuri.id] = new Address(yukkuri);
2023 getAddress: function(yukkuri){
2024 if(this.addressBook[yukkuri.id] === undefined)return null;
2025 return this.addressBook[yukkuri.id];
2027 getStatusForDisplay: function (){
2029 var placeId = (this.place==null)?"無し" : this.place.id;
2030 ret += "ID " + this.id + "\n";
2031 ret += "プレイス " + placeId + "\n";
2032 ret += "ゆっくり " + this.getYukkuri() + "\n";
2033 ret += "空腹 " + this.getHungry() + "\n";
2034 ret += "うんうん " + this.getUnun() + "\n";
2035 ret += "もちもの " + this.items.length + "\n";
2038 isItemsMax:function(){
2039 return this.items.length >= this.param.items_max;
2041 getItems:function(){
2044 addSearchObject:function(esearch, node){
2045 this.searchObjectMang.add(esearch, node)
2047 clearSearchObject:function(){
2048 this.searchObjectMang.clear()
2050 setFaceImage: function(eface){
2051 var path = this.faceStatus[eface];
2052 this.face.image = game.assets[path];
2054 myScale: function(_scaleX, _scaleY){
2055 this.face.scale(_scaleX,_scaleY);
2056 if(this.myCode === "REIMU"){
2057 this.okazari.x = -CHARA_WIDTH / 2;
2058 this.okazari.x = -CHARA_WIDTH / 2 - CHARA_WIDTH / 8;
2059 this.okazari.y = -CHARA_HEIGHT / 3 - CHARA_HEIGHT/7;
2061 this.okazari.x = -CHARA_WIDTH /2;
2062 this.okazari.y = -CHARA_HEIGHT / 2 - CHARA_HEIGHT/6;
2065 this.okazari.scale(_scaleX,_scaleY);
2066 this.hear.scale(_scaleX,_scaleY);
2067 this.scale(_scaleX,_scaleY);
2068 this.shadow.scale(_scaleX, _scaleY);
2070 destruct: function(){
2074 var Marisa = enchant.Class.create(Yukkuri,{
2075 initialize: function(x, y, grow){
2076 Yukkuri.call(this,x,y, grow);
2077 this.classname = "Marisa";
2078 this.myCode = "MARISA";
2079 this.myName = "まりさ";
2081 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2082 var json = net.load("./data/marisa/params.json");
2083 this.param = json.root.param;
2084 if(this.grow == EGrow.BABY){
2085 this.myName = "まりちゃ";
2086 this.param.range /= 4;
2088 else if(this.grow == EGrow.CHILD){
2089 this.param.range /= 3;
2091 else if(this.grow == EGrow.SUBADULT){
2092 this.param.range *= 0.8;
2094 this.shadow = new enchant.Sprite(64, 64);
2095 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2096 this.shadow.x = 0 + this.x;
2097 this.shadow.y = this.getWidth() / 16 + this.x;
2098 this.shadow.image._element.style.zIndex = 2;
2100 this._style.zIndex = 5;
2102 this.face = new enchant.Sprite(64, 64);
2103 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
2104 this.face.x = -CHARA_WIDTH / 2;
2105 this.face.y = -CHARA_HEIGHT / 2;
2106 this.face._style.zIndex = 0;
2108 this.faceStatus ={};
2109 this.faceStatus[EFace.NORMAL] = EResPath.MARISA_FACE_NORMAL;
2110 this.faceStatus[EFace.CRY1] = EResPath.MARISA_FACE_CRY1;
2111 this.faceStatus[EFace.CRY2] = EResPath.MARISA_FACE_CRY2;
2112 this.faceStatus[EFace.ANGRY] = EResPath.MARISA_FACE_ANGRY;
2113 this.faceStatus[EFace.HAPPY1] = EResPath.MARISA_FACE_HAPPY1;
2114 this.faceStatus[EFace.HAPPY2] = EResPath.MARISA_FACE_HAPPY2;
2115 this.faceStatus[EFace.EAT1] = EResPath.MARISA_FACE_EAT1;
2116 this.faceStatus[EFace.EAT2] = EResPath.MARISA_FACE_EAT2;
2117 this.faceStatus[EFace.TIRED] = EResPath.MARISA_FACE_TIRED;
2118 this.faceStatus[EFace.SLEEP] = EResPath.MARISA_FACE_SLEEP;
2121 this.hear = new enchant.Sprite(64, 64);
2122 this.hear.image = game.assets[EResPath.MARISA_HEAR];
2123 this.hear.x = -CHARA_WIDTH / 2;
2124 this.hear.y = -CHARA_HEIGHT / 2;
2125 this.hear._style.zIndex = 0;
2127 this.okazari = new Okazari(this);
2129 // this.imgGroup._style.zIndex = 1;
2132 this.imgGroup.addChild(this.shadow);
2133 this.imgBody.addChild(this);
2134 this.imgBody.addChild(this.face);
2135 this.imgBody.addChild(this.hear);
2136 this.imgBody.addChild(this.okazari);
2137 this.myScale(this.myScaleX, this.myScaleY)
2138 if(this instanceof Player){
2139 // this.myScaleX = 0.5;
2140 // this.myScaleY = 0.5;
2142 this.budge = new enchant.Sprite(16, 16);
2143 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2144 this.imgBody.addChild(this.budge);
2145 this.budge.x -= this.getWidth()/2;
2146 this.budge.y -= this.getHeight()/2;
2147 this.budge.scale(this.myScaleX, this.myScaleX);
2149 this.imgGroup.width = this.getWidth();
2150 this.imgGroup.height = this.getHeight();
2151 this.imgGroup.addChild(this.imgBody);
2152 backgroundMap.addChild(this.imgGroup);
2153 this._tweet = new TTweet(148, 64);
2155 this.imgGroup.addChild(this._tweet);
2156 this.imgGroup.x = x;
2157 this.imgGroup.y = y;
2160 this.action = new Action(this);
2164 var Player = enchant.Class.create(Marisa,{
2165 initialize: function(x, y){
2166 // this.runEnterframe = function(){
2168 Marisa.call(this, x, y, EGrow.ADULT);
2169 this.classname = "Player";
2171 ctl.setPlayer(this);
2172 // this.removeEventListener('enterframe',this.runEnterframe);
2173 this.addEventListener('enterframe', function(){
2176 if(this.age%10 === 0 && this.age !== 0){
2177 // console.log("palyer:" + this.age);
2180 ///////////////////////////////////////////////
2181 //Action pattern debug
2182 if(game.input.left){
2183 // this.changeFace(EResPath.MARISA_FACE_TIRED);
2185 this.direction = EDirection.LEFT;
2187 if(game.input.right){
2189 this.direction = EDirection.RIGHT;
2194 if(game.input.down){
2198 // if(this.age%20 == 0)console.log("player:" + (this.getY() + this.getHeight()/2));
2199 ///////////////////////////////////////////////
2201 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
2202 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
2204 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
2206 //- Display the circle of search range.
2207 // fieldBg.image.clear();
2208 // fieldBg.image.context.beginPath();
2209 // fieldBg.image.context.fillStyle = '#ff0000';
2210 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
2211 // fieldBg.image.context.fill();
2215 var Reimu = enchant.Class.create(Yukkuri,{
2216 initialize: function(x, y, grow){
2217 Yukkuri.call(this,x,y, grow);
2218 this.classname = "Reimu";
2219 this.myCode = "REIMU";
2220 this.myName = "れいむ";
2222 // var xml = this.loadParamsXML("./data/marisa/params.xml");
2223 var json = net.load("./data/reimu/params.json");
2224 this.param = json.root.param;
2225 if(this.grow == EGrow.BABY){
2226 this.myName = "れいみゅ";
2227 this.param.range /= 4;
2229 else if(this.grow == EGrow.CHILD){
2230 this.param.range /= 3;
2232 else if(this.grow == EGrow.SUBADULT){
2233 this.param.range *= 0.8;
2235 this.shadow = new enchant.Sprite(64, 64);
2236 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
2237 this.shadow.x = 0 + this.x;
2238 this.shadow.y = this.getWidth() / 16 + this.x;
2239 this.shadow.image._element.style.zIndex = 2;
2241 this._style.zIndex = 5;
2243 this.face = new enchant.Sprite(64, 64);
2244 this.face.image = game.assets[EResPathReimu.FACE_NORMAL];
2245 this.face.x = -CHARA_WIDTH / 2;
2246 this.face.y = -CHARA_HEIGHT / 2;
2247 this.face._style.zIndex = 0;
2249 this.faceStatus ={};
2250 this.faceStatus[EFace.NORMAL] = EResPathReimu.FACE_NORMAL;
2251 this.faceStatus[EFace.CRY1] = EResPathReimu.FACE_CRY1;
2252 this.faceStatus[EFace.CRY2] = EResPathReimu.FACE_CRY2;
2253 this.faceStatus[EFace.ANGRY] = EResPathReimu.FACE_ANGRY;
2254 this.faceStatus[EFace.HAPPY1] = EResPathReimu.FACE_HAPPY1;
2255 this.faceStatus[EFace.HAPPY2] = EResPathReimu.FACE_HAPPY2;
2256 this.faceStatus[EFace.EAT1] = EResPathReimu.FACE_EAT1;
2257 this.faceStatus[EFace.EAT2] = EResPathReimu.FACE_EAT2;
2258 this.faceStatus[EFace.TIRED] = EResPathReimu.FACE_TIRED;
2259 this.faceStatus[EFace.SLEEP] = EResPathReimu.FACE_SLEEP;
2262 this.hear = new enchant.Sprite(64, 64);
2263 this.hear.image = game.assets[EResPathReimu.HEAR];
2264 this.hear.x = -CHARA_WIDTH / 2;
2265 this.hear.y = -CHARA_HEIGHT / 2;
2267 this.sub1 = new enchant.Sprite(64, 64);
2268 this.sub1.image = game.assets[EResPathReimu.SUB1];
2269 this.sub1.x = -CHARA_WIDTH / 2;
2270 this.sub1.y = -CHARA_HEIGHT / 2;
2272 this.okazari = new Okazari(this);
2274 // this.imgGroup._style.zIndex = 1;
2277 this.imgGroup.addChild(this.shadow);
2278 this.imgBody.addChild(this.okazari);
2279 this.imgBody.addChild(this);
2280 this.imgBody.addChild(this.face);
2281 this.imgBody.addChild(this.hear);
2282 this.imgBody.addChild(this.sub1);
2283 this.myScale(this.myScaleX, this.myScaleY)
2284 if(this instanceof Player){
2285 // this.myScaleX = 0.5;
2286 // this.myScaleY = 0.5;
2288 this.budge = new enchant.Sprite(16, 16);
2289 this.budge.image = game.assets[EResPath.PLAYER_BADGE];
2290 this.imgBody.addChild(this.budge);
2291 this.budge.x -= this.getWidth()/2;
2292 this.budge.y -= this.getHeight()/2;
2293 this.budge.scale(this.myScaleX, this.myScaleX);
2295 this.imgGroup.width = this.getWidth();
2296 this.imgGroup.height = this.getHeight();
2297 this.imgGroup.addChild(this.imgBody);
2298 backgroundMap.addChild(this.imgGroup);
2299 this._tweet = new TTweet(148, 64);
2301 this.imgGroup.addChild(this._tweet);
2302 this.imgGroup.x = x;
2303 this.imgGroup.y = y;
2306 this.action = new Action(this);
2311 game.onload = function(){
2314 def.ObjSprite = ObjSprite;
2315 def.Yukkuri = Yukkuri;
2316 def.nodeSort = nodeSort;
2317 mangTouch = new MangTouch(ctl);
2318 mangMsg = new MangMsg(ctl);
2319 ctl.setDefined(def);
2320 backgroundMap.image = game.assets[EResPath.MAP0];
2321 backgroundMap.loadData(_mapData);
2322 backgroundMap.collisionData = _collisionData;
2324 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
2325 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2326 var windowSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
2327 fieldBg.image = fieldSurface;
2331 windowFront.image = windowSurface;
2334 windowFront.opacity = 0.5;
2336 windowSurface.context.fillStyle = '#000';
2337 windowSurface.context.fillRect(0 + 20, EFieldPos.HEIGHT - 60, EFieldPos.WIDTH - 40, EFieldPos.HEIGHT);
2340 menuSurface.context.fillStyle = '#000';
2341 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
2342 menuBg.image = menuSurface;
2343 menuBg.x = EMenuPos.X;
2344 menuBg.y = EMenuPos.Y;
2345 backgroundMap.addChild(fieldBg);
2346 mangIcon = new MangIcon(ctl, menuBg);
2348 game.rootScene.addChild(backgroundMap);
2349 game.rootScene.addChild(windowFront);
2350 game.rootScene.addChild(menuBg);
2352 // var labelGroup = new LabelGroup();
2353 mangLabel = new MangLabel(ctl, menuBg);
2354 // var info = new Label("ゆっくり");
2355 // info.color = "#ffffff";
2356 // info.font = "14px 'Times New Roman'";
2358 // info.y = GAME_HEIGHT / 2;
2359 // labelGroup.addChild(info);
2360 // menuBg.addChild(labelGroup);
2363 // var food = new def.Food("apple", 200, 250);
2364 backgroundMap.addChild(foodGroup);
2365 // backgroundMap.addChild(placeGroup);
2366 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
2367 // new Marisa(PALYER_INIT_X + 50, PALYER_INIT_Y + 200, EGrow.ADULT);
2368 // new Marisa(PALYER_INIT_X + 100, PALYER_INIT_Y + 200, EGrow.SUBADULT);
2369 // new Marisa(PALYER_INIT_X + 150, PALYER_INIT_Y + 200, EGrow.CHILD);
2370 new Reimu(PALYER_INIT_X + 100, PALYER_INIT_Y + 100, EGrow.ADULT);
2371 // new Unun(100, 100);
2372 // new Place("tree", PALYER_INIT_X, PALYER_INIT_Y - 50);
2376 game.rootScene.addEventListener('touchstart', function (e) {
2377 game.touched = true;
2378 var mang = mangTouch.get(ctl.getCurrentCommand());
2381 game.rootScene.addEventListener('touchmove', function (e) {
2382 var mang = mangTouch.get(ctl.getCurrentCommand());
2385 game.rootScene.addEventListener('touchend', function (e) {
2386 var mang = mangTouch.get(ctl.getCurrentCommand());
2388 game.touched = false;
2392 game.rootScene.addEventListener('enterframe', function(){
2394 mangLabel.draw(player);
2395 if(this.age%BASE_FPS == 0 ){
2400 this.addEventListener('enterframe', function(){
2401 //The priority processing of display instead of z-index
2403 backgroundMap.childNodes.sort(nodeSort);