2 //////////////////////////////////////
8 var LabelGroup = enchant.Class.mixClasses(Label, Group,true);
10 //////////////////////////////////////
12 //////////////////////////////////////
13 var PALYER_INIT_X = 100;
14 var PALYER_INIT_Y = 100;
16 var CHARA_HEIGHT = 64;
18 var GAME_HEIGHT = 600;
20 YUKKURI_BASE : './data/yukkuri_base.png',
21 YUKKURI_SHADOW : './data/shadow.png',
22 MARISA_FACE_NORMAL : './data/marisa/face_normal.png',
23 MARISA_FACE_TIRED : './data/marisa/face_tired.png',
24 MARISA_HEAR : './data/marisa/hear.png',
25 OBJECT : './data/object.png',
26 MAP0 : './data/map0.png',
27 COMMAND : './data/command.png',
28 OKAZARI : './data/okazari.png',
44 WIDTH: GAME_WIDTH - EMenuPos.WIDTH,
61 window.onload = function(){
65 var SpriteGroup = enchant.Class.mixClasses(Sprite, Group,true);
66 var menuBg = new SpriteGroup(EMenuPos.WIDTH, EMenuPos.HEIGHT);
67 var fieldBg = new enchant.Sprite(EFieldPos.WIDTH, EFieldPos.HEIGHT);
68 var game = new Game(GAME_WIDTH, GAME_HEIGHT);
71 for(var _v in EResPath){
72 _loadArr[i] = EResPath[_v];
75 game.preload(_loadArr);
76 var MapGroup = enchant.Class.mixClasses(Map, Group,true);
77 var backgroundMap = new MapGroup(16, 16);
78 include("./class.js");
82 ctl.setBackgroundMap(backgroundMap);
83 var Action = enchant.Class.create({
84 initialize: function (yukkuri){
85 this.status = EAction.THINK;
86 // this.status = EAction.EAT;
87 this.yukkuri = yukkuri;
88 this.isMoving = false;
91 if(this.yukkuri.isDead()){
92 this.status = EAction.DEAD;
94 if(this.yukkuri.isSleep()){
95 this.status = EAction.SLEEP;
103 // this.status = EAction.WALK;
104 // yukkuri.moveTo(120, 120, 30);
105 if(this.yukkuri.age%10 === 0){
127 walk : function(retryCounter){
128 if(retryCounter > 15){
130 this.status = EAction.EAT;
131 console.log("retryCount over");
134 if(this.yukkuri.imgGroup.tl.queue.length === 0){
137 this.isMoving = false;
138 this.status = EAction.THINK;
142 // this.isMoving = true;
143 var xpos = 150 - (retryCounter * 10);
144 var ypos = 150 - (retryCounter * 10);
147 this.yukkuri.vy = -ypos;
149 else if(rand(8) == 1){
150 this.yukkuri.vx = xpos;
151 this.yukkuri.vy = -ypos;
152 this.yukkuri.direction = EDirection.RIGHT;
154 else if(rand(8) == 2){
155 this.yukkuri.vx = xpos;
157 this.yukkuri.direction = EDirection.RIGHT;
159 else if(rand(8) == 3){
160 this.yukkuri.vx = xpos;
161 this.yukkuri.vy = ypos;
162 this.yukkuri.direction = EDirection.RIGHT;
164 else if(rand(8) == 4){
166 this.yukkuri.vy = ypos;
168 else if(rand(8) == 5){
169 this.yukkuri.vx = -xpos;
170 this.yukkuri.vy = ypos;
171 this.yukkuri.direction = EDirection.LEFT;
173 else if(rand(8) == 6){
174 this.yukkuri.vx = -xpos;
176 this.yukkuri.direction = EDirection.LEFT;
178 else if(rand(8) == 7){
179 this.yukkuri.vx = -xpos;
180 this.yukkuri.vy = -ypos;
181 this.yukkuri.direction = EDirection.LEFT;
183 if (this.yukkuri.vx || this.yukkuri.vy) {
184 var map = ctl.backgroundMap;
185 // var x = this.yukkuri.x + (this.yukkuri.moveX ? this.yukkuri.moveX / Math.abs(this.yukkuri.moveX) * 16 : 0) + 16;
186 // var y = this.yukkuri.y + (this.yukkuri.moveY ? this.yukkuri.moveY / Math.abs(this.yukkuri.moveY) * 16 : 0) + 16;
187 var x = this.yukkuri.imgGroup.x + this.yukkuri.vx;
188 var y = this.yukkuri.imgGroup.y + this.yukkuri.vy + this.yukkuri.height / 2;
189 if (0 <= x && x < map.width && 0 <= y && y < map.height && !map.hitTest(x, y)) {
190 // console.log("あたってないよ:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
191 // console.log("X:" + this.yukkuri.moveX);
192 // console.log("Y:" + this.yukkuri.moveY);
193 this.isMoving = true;
194 this.yukkuri.reverse();
195 this.yukkuri.moveBy(this.yukkuri.vx, this.yukkuri.vy, frame);
197 // console.log("HIT:"+ this.yukkuri.imgGroup.x + ":" + this.yukkuri.imgGroup.y);
198 this.walk(retryCounter+1);
205 var yukkuri = this.yukkuri;
207 if(yukkuri.isSleeping){
208 if(yukkuri.age%10 === 0 && yukkuri.age !== 0)yukkuri.param.sleep--;
209 if(yukkuri.param.sleep <= 0){
210 yukkuri.param.sleep = 0;
211 yukkuri.isSleeping = false;
212 yukkuri.tweet("ゆっくりおきるよ!");
213 this.status = EAction.THINK;
218 this.yukkuri.tweet("もっとゆっくりしたかった…");
219 this.yukkuri.imgBody.tl.clear();
220 this.yukkuri.imgBody.tl.pause();
221 this.yukkuri.imgGroup.tl.clear();
222 this.yukkuri.imgGroup.tl.pause();
223 // this.yukkuri.imgBody.tl.unloop();
224 // this.yukkuri.imgBody.tl.removeFromScene();
225 // this.yukkuri.imgGroup.tl.removeFromScene();
229 for (var i = 0, l = game.rootScene.childNodes.length; i < l; i++) {
230 var node = game.rootScene.childNodes[i];
231 if (node instanceof Food) {
233 if(this.yukkuri.within(node, this.yukkuri.range)){
234 //A yukkuri to go to the food area
235 this.status = EAction.MOVE;
239 "myYukkuri": this.yukkuri
242 // console.log("no:");
246 this.status = EAction.WALK;
249 var MoveEvent = enchant.Class.create({
250 initialize: function (dataObj){
255 var Food = enchant.Class.create(enchant.Sprite,{
256 initialize: function (type, x, y){
257 enchant.Sprite.call(this,16,16);
258 this.image = game.assets[EResPath.OBJECT];
262 // this.moveTo(180, 252);
263 backgroundMap.addChild(this);
266 var Okazari = enchant.Class.create(enchant.Sprite,{
267 initialize: function(){
268 enchant.Sprite.call(this, 64, 64);
269 this.image = game.assets[EResPath.OKAZARI];
270 this.x = -CHARA_WIDTH / 2;
271 this.y = -12 - CHARA_HEIGHT / 2;
274 var Yukkuri = enchant.Class.create(enchant.Sprite,{
275 initialize: function(x, y){
276 this.imgGroup = new Group();
277 this.imgBody = new Group();
278 enchant.Sprite.call(this, 64, 64);
279 this.x = -CHARA_WIDTH / 2;
280 this.y = -CHARA_HEIGHT / 2;
283 this.image = game.assets[EResPath.YUKKURI_BASE];
284 this.direction = EDirection.RIGHT;
285 this.addEventListener('enterframe', this.runEnterframe);
286 this.isSleeping = false;
288 runEnterframe:function(){
293 if(this.direction == EDirection.RIGHT){
294 this.imgBody.scaleX = 1;
296 else if(this.direction == EDirection.LEFT){
297 this.imgBody.scaleX = -1;
300 tweet:function(text){
301 this._tweet.text(text, this.x - this._tweet.width/4, this.y - this._tweet.height);
303 moveTo:function(x, y, time){
304 this.imgGroup.tl.moveTo(x, y, time, enchant.Easing.SIN_EASEINOUT);
306 moveBy:function(x, y, time){
307 this.imgGroup.tl.moveBy(x, y, time, enchant.Easing.SIN_EASEINOUT);
313 animation: function(){
314 this.imgBody.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
315 // this.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
316 // this.okazari.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
317 // this.face.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
318 // this.hear.tl.moveBy(0, -5, 10, enchant.Easing.SWING).moveBy(0, 5, 10, enchant.Easing.SWING).loop();
321 this.imgGroup.x += x;
323 // this.shadow.x += x;
324 // this._tweet.x += x;
327 this.imgGroup.y += y;
329 // this.shadow.y += y;
330 // this._tweet.y += y;
332 changeFace: function(erespath){
333 this.face.image = game.assets[erespath];
335 loadParamsXML: function(url){
336 var http = new JKL.ParseXML( url );
339 runYukkuri: function(){
340 if(this.param.hungry > 70){
341 if(this.age%(50 - this.param.hungry - 70) === 0 && this.age !== 0){
342 this.param.yukkuri -= 1;
345 else if(this.param.hungry < 10){
346 if(this.age%50 === 0 && this.age !== 0) this.param.yukkuri += 1;
349 if(this.param.yukkuri <= 0)this.param.yukkuri = 0;
350 else if(this.param.yukkuri >= this.param.maxYukkuri)this.param.yukkuri = this.param.maxYukkuri;
352 runHungry: function(){
353 if(this.age%100 === 0 && this.age !== 0)this.param.hungry++;
354 if(this.param.hungry >= 100)this.param.hungry = 100;
356 runSleep: function(){
357 if(!this.isSleeping){
358 if(this.age%100 === 0 && this.age !== 0)this.param.sleep++;
359 if(this.param.sleep >= 100){
360 this.param.sleep = 100;
361 this.isSleeping = true;
367 return this.isSleeping;
370 return this.param.yukkuri <= 0;
372 destruct: function(){
376 var Marisa = enchant.Class.create(Yukkuri,{
377 initialize: function(x, y){
378 Yukkuri.call(this,x,y);
381 // var xml = this.loadParamsXML("./data/marisa/params.xml");
382 var json = net.load("./data/marisa/params.json");
383 this.param = json.root.param;
385 this.shadow = new enchant.Sprite(64, 64);
386 this.shadow.image = game.assets[EResPath.YUKKURI_SHADOW];
387 this.shadow.x = 0 + this.x;
388 this.shadow.y = CHARA_HEIGHT / 16 + this.x;
390 this.face = new enchant.Sprite(64, 64);
391 this.face.image = game.assets[EResPath.MARISA_FACE_NORMAL];
392 this.face.x = -CHARA_WIDTH / 2;
393 this.face.y = -CHARA_HEIGHT / 2;
395 this.hear = new enchant.Sprite(64, 64);
396 this.hear.image = game.assets[EResPath.MARISA_HEAR];
397 this.hear.x = -CHARA_WIDTH / 2;
398 this.hear.y = -CHARA_HEIGHT / 2;
400 this.okazari = new Okazari();
401 this.imgGroup.addChild(this.shadow);
402 this.imgBody.addChild(this);
403 this.imgBody.addChild(this.face);
404 this.imgBody.addChild(this.hear);
405 this.imgBody.addChild(this.okazari);
406 this.imgGroup.addChild(this.imgBody);
407 backgroundMap.addChild(this.imgGroup);
408 this._tweet = new TTweet(148, 64);
410 this.imgGroup.addChild(this._tweet);
414 this.action = new Action(this);
418 var Player = enchant.Class.create(Marisa,{
419 initialize: function(x, y){
420 // this.runEnterframe = function(){
422 Marisa.call(this, x, y);
424 // this.removeEventListener('enterframe',this.runEnterframe);
425 this.addEventListener('enterframe', function(){
426 if(this.age%10 === 0 && this.age !== 0){
427 // console.log("palyer:" + this.age);
431 //Action pattern for debug
433 this.changeFace(EResPath.MARISA_FACE_TIRED);
435 this.direction = EDirection.LEFT;
437 if(game.input.right){
439 this.direction = EDirection.RIGHT;
443 // this.tweet("ゆっくりしていってね!");
449 // if(ctl.backgroundMap.hitTest(this.imgGroup.x, this.imgGroup.y + this.height / 2)){
450 // console.log("hit:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.height/2) );
452 // console.log("not:" + this.imgGroup.x + ":" + (this.imgGroup.y + this.image.height/2));
454 //- Display the circle of search range.
455 // fieldBg.image.clear();
456 // fieldBg.image.context.beginPath();
457 // fieldBg.image.context.fillStyle = '#ff0000';
458 // fieldBg.image.context.arc(this.imgGroup.x + this.width/2, this.imgGroup.y + this.height/2, this.range, Math.PI * 2, false);
459 // fieldBg.image.context.fill();
463 game.onload = function(){
464 mangTouch = new MangTouch(ctl);
465 backgroundMap.image = game.assets[EResPath.MAP0];
466 backgroundMap.loadData(_mapData);
467 backgroundMap.collisionData = _collisionData;
469 var menuSurface = new enchant.Surface(EMenuPos.WIDTH, EMenuPos.HEIGHT);
470 var fieldSurface = new enchant.Surface(EFieldPos.WIDTH, EFieldPos.HEIGHT);
471 fieldBg.image = fieldSurface;
475 menuSurface.context.fillStyle = '#000';
476 menuSurface.context.fillRect(0, 0, EMenuPos.WIDTH, EMenuPos.HEIGHT);
477 menuBg.image = menuSurface;
478 menuBg.x = EMenuPos.X;
479 menuBg.y = EMenuPos.Y;
481 backgroundMap.addChild(fieldBg);
482 mangIcon = new MangIcon(ctl, menuBg);
484 game.rootScene.addChild(backgroundMap);
485 game.rootScene.addChild(menuBg);
487 // var labelGroup = new LabelGroup();
488 mangLabel = new MangLabel(ctl, menuBg);
489 // var info = new Label("ゆっくり");
490 // info.color = "#ffffff";
491 // info.font = "14px 'Times New Roman'";
493 // info.y = GAME_HEIGHT / 2;
494 // labelGroup.addChild(info);
495 // menuBg.addChild(labelGroup);
498 var food = new Food("apple", 200, 250);
499 var player = new Player(PALYER_INIT_X, PALYER_INIT_Y);
502 game.rootScene.addEventListener('touchstart', function (e) {
504 var mang = mangTouch.get(ctl.getCurrentCommand());
507 game.rootScene.addEventListener('touchmove', function (e) {
508 var mang = mangTouch.get(ctl.getCurrentCommand());
511 game.rootScene.addEventListener('touchend', function (e) {
512 var mang = mangTouch.get(ctl.getCurrentCommand());
514 game.touched = false;
518 game.rootScene.addEventListener('enterframe', function(){
520 mangLabel.draw(player);