/////////////////////////////////////// // 織姫を探せ! /////////////////////////////////////// var res = { back:"res/back/black.png", heart:"res/pancake/45.png", reset:"res/pancake/46.png", orihime:"res/pancake/09.png", hikoboshi:"res/pancake/05.png", //congratulations! c:"res/pancake/82.png", o:"res/pancake/8e.png", n:"res/pancake/8d.png", g:"res/pancake/86.png", r:"res/pancake/91.png", a:"res/pancake/80.png", t:"res/pancake/93.png", u:"res/pancake/95.png", l:"res/pancake/8b.png", i:"res/pancake/88.png", s:"res/pancake/92.png", ex:"res/pancake/a4.png", //find orihime! f:"res/pancake/85.png", d:"res/pancake/83.png", h:"res/pancake/87.png", m:"res/pancake/8c.png", e:"res/pancake/84.png", //3,2,1,go! s3:"res/pancake/a9.png", s2:"res/pancake/a8.png", s1:"res/pancake/a7.png", //see you next year y:"res/pancake/98.png", x:"res/pancake/97.png", }; var MyLayer = cc.KidspodLayer.extend({ _arrBatchNode:[], _dt:0, _time:null, _orihime:null, init:function(){ this._super(); var layer = new cc.LayerColor(cc.color(0, 0, 0, 0)); this.addChild(layer, 200, 200); layer.runAction(cc.fadeTo(1, 180)); var sprite = null; for (var i = 0; i < 13; i++) { // find orihime! if (i == 0) sprite = new cc.Sprite(res.f); else if (i == 1) sprite = new cc.Sprite(res.i); else if (i == 2) sprite = new cc.Sprite(res.n); else if (i == 3) sprite = new cc.Sprite(res.d); else if (i == 4) sprite = null; else if (i == 5) sprite = new cc.Sprite(res.o); else if (i == 6) sprite = new cc.Sprite(res.r); else if (i == 7) sprite = new cc.Sprite(res.i); else if (i == 8) sprite = new cc.Sprite(res.h); else if (i == 9) sprite = new cc.Sprite(res.i); else if (i == 10) sprite = new cc.Sprite(res.m); else if (i == 11) sprite = new cc.Sprite(res.e); else if (i == 12) sprite = new cc.Sprite(res.ex); if (sprite) { sprite.setPosition(cc.p(cc.winSize.width/2 - 110 + i*(16+2), cc.winSize.height/2 + 70)); sprite.setScale(0.75); sprite.setOpacity(0); layer.addChild(sprite); sprite.runAction(cc.sequence(cc.delayTime(i*0.05), cc.fadeTo(0.1, 255))); } } var orihime = new cc.Sprite(res.orihime); orihime.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2 + 35)); layer.addChild(orihime); //コード適当・・・ var spriteS3 = new cc.Sprite(res.s3); spriteS3.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2)); spriteS3.setOpacity(0); layer.addChild(spriteS3); spriteS3.runAction(cc.sequence(cc.delayTime(1.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0))); var spriteS2 = new cc.Sprite(res.s2); spriteS2.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2)); spriteS2.setOpacity(0); layer.addChild(spriteS2); spriteS2.runAction(cc.sequence(cc.delayTime(2.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0))); var spriteS1 = new cc.Sprite(res.s1); spriteS1.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2)); spriteS1.setOpacity(0); layer.addChild(spriteS1); spriteS1.runAction(cc.sequence(cc.delayTime(3.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0))); var spriteG = new cc.Sprite(res.g); spriteG.setPosition(cc.p(cc.winSize.width/2 - 32, cc.winSize.height/2)); spriteG.setOpacity(0); layer.addChild(spriteG); spriteG.runAction(cc.sequence(cc.delayTime(4.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0))); var spriteO = new cc.Sprite(res.o); spriteO.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2)); spriteO.setOpacity(0); layer.addChild(spriteO); spriteO.runAction(cc.sequence(cc.delayTime(4.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0))); var spriteEX = new cc.Sprite(res.ex); spriteEX.setPosition(cc.p(cc.winSize.width/2 + 32, cc.winSize.height/2)); spriteEX.setOpacity(0); layer.addChild(spriteEX); spriteEX.runAction(cc.sequence(cc.delayTime(4.5), cc.fadeTo(0.0, 255), cc.delayTime(1.0), cc.fadeTo(0.0, 0), cc.callFunc(this.start, this))); // var buttonReset = ccui.Button.create(res.reset); // buttonReset.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2 - 224)); // buttonReset.addTouchEventListener(function(sender, type) { // switch (type) { // case ccui.Widget.TOUCH_ENDED: // this.reset(); // break; // } // }, this); // this.addChild(buttonReset); return true; }, start:function(){ this.scheduleUpdate(); var layer = this.getChildByTag(200); if (layer) layer.runAction(cc.removeSelf()); //ミスタップ用 var buttonBack = ccui.Button.create(res.back); buttonBack.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2)); buttonBack.addTouchEventListener(function(sender, type) { switch (type) { case ccui.Widget.TOUCH_ENDED: this.miss(); break; } }, this); this.addChild(buttonBack); //35種類 for (var i = 32; i < 32+35; i++) { // res/pancake/20.png(32) ~ res/pancake/33.png(51) var s16 = i.toString(16); var spriteBatchNode = new cc.SpriteBatchNode("res/pancake/"+s16+".png"); this._arrBatchNode[s16] = spriteBatchNode; this.addChild(spriteBatchNode); } for (var i = 0; i < 1000; i++) { var s10 = Math.floor(Math.random()*35)+32; var s16 = s10.toString(16); var spriteBatchNode = this._arrBatchNode[s16]; var x = Math.floor(Math.random()*304)+16; var y = Math.floor(Math.random()*380)+50; var sprite = new cc.Sprite("res/pancake/"+s16+".png"); sprite.setPosition(cc.p(x, y)); spriteBatchNode.addChild(sprite); } var x = Math.floor(Math.random()*304)+16; var y = Math.floor(Math.random()*380)+50; this._orihime = ccui.Button.create(res.orihime); this._orihime.setPosition(cc.p(x, y)); console.log("%f, %f", x, y); this._orihime.addTouchEventListener(function(sender, type) { switch (type) { case ccui.Widget.TOUCH_ENDED: this.find(); break; } }, this); this.addChild(this._orihime); //time this._time = new cc.LabelTTF("0.00", "Arial", 30); this._time.setColor(cc.color(255, 255, 255)); this._time.setPosition(cc.p(cc.winSize.width/2, cc.winSize.height/2 + 215)); this.addChild(this._time); }, find:function(){ this.unscheduleUpdate(); if (this._dt > 77) { this.runAction(cc.sequence(cc.delayTime(1.0), cc.callFunc(this.reset, this))); } else { this.clear(); } }, miss:function(){ this._dt += 7;//###ペナルティ var labelMiss = new cc.LabelTTF("+7.0", "Arial", 20); labelMiss.setColor(cc.color(255, 255, 0)); labelMiss.setPosition(cc.p(cc.winSize.width/2 + 55, cc.winSize.height/2 + 227)); labelMiss.setOpacity(0); this.addChild(labelMiss); labelMiss.runAction(cc.sequence(cc.fadeTo(0.5, 255), cc.delayTime(1.0), cc.removeSelf())); }, clear:function(){ // this._orihime.runAction(cc.scaleTo(0.2, 3.0)); //orihime無効化 this._orihime.setTouchEnabled(false); var layer = new cc.LayerColor(cc.color(0, 0, 0, 0)); this.addChild(layer, 200); layer.runAction(cc.fadeTo(1, 180)); var sprite = null; for (var i = 0; i < 16; i++) { // congratulations! if (i == 0) sprite = new cc.Sprite(res.c); else if (i == 1) sprite = new cc.Sprite(res.o); else if (i == 2) sprite = new cc.Sprite(res.n); else if (i == 3) sprite = new cc.Sprite(res.g); else if (i == 4) sprite = new cc.Sprite(res.r); else if (i == 5) sprite = new cc.Sprite(res.a); else if (i == 6) sprite = new cc.Sprite(res.t); else if (i == 7) sprite = new cc.Sprite(res.u); else if (i == 8) sprite = new cc.Sprite(res.l); else if (i == 9) sprite = new cc.Sprite(res.a); else if (i == 10) sprite = new cc.Sprite(res.t); else if (i == 11) sprite = new cc.Sprite(res.i); else if (i == 12) sprite = new cc.Sprite(res.o); else if (i == 13) sprite = new cc.Sprite(res.n); else if (i == 14) sprite = new cc.Sprite(res.s); else if (i == 15) sprite = new cc.Sprite(res.ex); sprite.setPosition(cc.p(cc.winSize.width/2 - 135 + i*(16+2), cc.winSize.height/2 + 150)); sprite.setScale(0.75); sprite.setOpacity(0); layer.addChild(sprite); sprite.runAction(cc.sequence(cc.delayTime(i*0.05), cc.fadeTo(0.1, 255))); // heart sprite = new cc.Sprite(res.heart); sprite.setPosition(cc.p(cc.winSize.width/2 + 80*Math.cos(360/16*i/180*Math.PI), cc.winSize.height/2 + 80*Math.sin(360/16*i/180*Math.PI))); sprite.setScale(0.75); sprite.setOpacity(0); layer.addChild(sprite); sprite.runAction(cc.repeat(cc.sequence(cc.fadeTo((Math.floor(Math.random()*6)+5)/10, 255), cc.fadeTo((Math.floor(Math.random()*6)+5)/10, 0)), 10000)); } var hikoboshi = new cc.Sprite(res.hikoboshi); hikoboshi.setPosition(cc.p(cc.winSize.width/2 - 15, cc.winSize.height/2)); hikoboshi.setOpacity(0); layer.addChild(hikoboshi); hikoboshi.runAction(cc.fadeTo(0.5, 255)); var orihime = new cc.Sprite(res.orihime); orihime.setPosition(cc.p(cc.winSize.width/2 + 15, cc.winSize.height/2)); orihime.setOpacity(0); layer.addChild(orihime); orihime.runAction(cc.fadeTo(0.5, 255)); // cc.audioEngine.playEffect("sound/gamese/se_fanfare.m4a"); }, failed:function(){ // this._orihime.runAction(cc.scaleTo(0.2, 3.0)); //orihime無効化 this._orihime.setTouchEnabled(false); var layer = new cc.LayerColor(cc.color(0, 0, 0, 0)); this.addChild(layer, 200); layer.runAction(cc.fadeTo(1, 180)); var sprite = null; for (var i = 0; i < 17; i++) { // see you next year if (i == 0) sprite = new cc.Sprite(res.s); else if (i == 1) sprite = new cc.Sprite(res.e); else if (i == 2) sprite = new cc.Sprite(res.e); else if (i == 3) sprite = null; else if (i == 4) sprite = new cc.Sprite(res.y); else if (i == 5) sprite = new cc.Sprite(res.o); else if (i == 6) sprite = new cc.Sprite(res.u); else if (i == 7) sprite = null; else if (i == 8) sprite = new cc.Sprite(res.n); else if (i == 9) sprite = new cc.Sprite(res.e); else if (i == 10) sprite = new cc.Sprite(res.x); else if (i == 11) sprite = new cc.Sprite(res.t); else if (i == 12) sprite = null; else if (i == 13) sprite = new cc.Sprite(res.y); else if (i == 14) sprite = new cc.Sprite(res.e); else if (i == 15) sprite = new cc.Sprite(res.a); else if (i == 16) sprite = new cc.Sprite(res.r); if (sprite) { sprite.setPosition(cc.p(cc.winSize.width/2 - 140 + i*(16+2), cc.winSize.height/2)); sprite.setScale(0.60); sprite.setOpacity(0); layer.addChild(sprite); sprite.runAction(cc.sequence(cc.delayTime(i*0.05), cc.fadeTo(0.1, 255))); } } }, reset:function(){ this.unscheduleUpdate(); this._arrBatchNode.length = 0; this._arrBatchNode = []; this._dt = 0; if (this._time) this._time.runAction(cc.removeSelf()); this._time = null; if (this._orihime) this._orihime.runAction(cc.removeSelf()); this._orihime = null; var tran = cc.TransitionFade.create(0.3, new MyScene()); cc.director.runScene(tran); }, update:function(dt){ this._dt += dt; if (this._dt > 77) { this.unscheduleUpdate(); this._dt = 77; this.failed(); } var time = Math.floor(this._dt*100)/100; this._time.setString(time.toFixed(2)); }, }); var MyScene = cc.Scene.extend({ onEnter:function (){ this._super(); var layer = new MyLayer(); layer.init(); this.addChild(layer); } });