/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var CocoCharacter = Container.expand(function () { var self = Container.call(this); var cocoGraphics = self.attachAsset('coco', { anchorX: 0.5, anchorY: 0.5 }); var cocoText = new Text2('COCO', { size: 30, fill: 0xFFFFFF }); cocoText.anchor.set(0.5, 0.5); cocoText.y = 80; self.addChild(cocoText); self.down = function (x, y, obj) { LK.getSound('iceMagic').play(); createIceFireworks(self.x, self.y); tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeOut }); } }); }; return self; }); var CountdownButton = Container.expand(function (number) { var self = Container.call(this); self.number = number; self.isActive = number === 10; var buttonGraphics = self.attachAsset('countdownButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2(number.toString(), { size: 60, fill: self.isActive ? "#ffffff" : "#666666" }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.activate = function () { self.isActive = true; buttonText.fill = "#ffffff"; buttonGraphics.tint = 0xffffff; }; self.deactivate = function () { self.isActive = false; buttonText.fill = "#333333"; buttonGraphics.tint = 0x333333; }; self.down = function (x, y, obj) { if (self.isActive && currentNumber === self.number) { LK.getSound('buttonTap').play(); self.deactivate(); currentNumber--; if (currentNumber > 0) { for (var i = 0; i < countdownButtons.length; i++) { if (countdownButtons[i].number === currentNumber) { countdownButtons[i].activate(); break; } } } lightLevel += 0.1; lightOverlay.alpha = lightLevel; if (currentNumber === 0) { LK.getSound('victory').play(); LK.effects.flashScreen(0xffffff, 1000); LK.setTimeout(function () { LK.showYouWin(); }, 1000); } } }; return self; }); var IceSpark = Container.expand(function () { var self = Container.call(this); var sparkGraphics = self.attachAsset('iceSpark', { anchorX: 0.5, anchorY: 0.5 }); self.vx = (Math.random() - 0.5) * 10; self.vy = (Math.random() - 0.5) * 10; self.life = 60; self.update = function () { self.x += self.vx; self.y += self.vy; self.life--; sparkGraphics.alpha = self.life / 60; if (self.life <= 0) { self.destroy(); for (var i = iceFireworks.length - 1; i >= 0; i--) { if (iceFireworks[i] === self) { iceFireworks.splice(i, 1); break; } } } }; return self; }); var PowerpuffGirl = Container.expand(function (assetId, color) { var self = Container.call(this); var girlGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); var girlText = new Text2(assetId.toUpperCase(), { size: 30, fill: 0xFFFFFF }); girlText.anchor.set(0.5, 0.5); girlText.y = 80; self.addChild(girlText); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x0f0f23 }); /**** * Game Code ****/ var currentNumber = 10; var lightLevel = 0; var countdownButtons = []; var iceFireworks = []; var darkGarden = game.addChild(LK.getAsset('darkGarden', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366 })); var lightOverlay = game.addChild(LK.getAsset('lightOverlay', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1366, alpha: 0 })); var blossom = game.addChild(new PowerpuffGirl('blossom', 0xff69b4)); blossom.x = 300; blossom.y = 600; var buttercup = game.addChild(new PowerpuffGirl('buttercup', 0x90ee90)); buttercup.x = 700; buttercup.y = 800; var bubbles = game.addChild(new PowerpuffGirl('bubbles', 0x00bfff)); bubbles.x = 1400; bubbles.y = 600; var coco = game.addChild(new CocoCharacter()); coco.x = 1024; coco.y = 1000; for (var i = 10; i >= 1; i--) { var button = new CountdownButton(i); var angle = (i - 1) * (Math.PI * 2 / 10); var radius = 400; button.x = 1024 + Math.cos(angle) * radius; button.y = 1366 + Math.sin(angle) * radius; countdownButtons.push(button); game.addChild(button); } var titleText = new Text2('Tap numbers 10 to 1!', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 300; game.addChild(titleText); var instructionText = new Text2('Tap Coco for ice fireworks!', { size: 50, fill: 0x87CEEB }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 380; game.addChild(instructionText); function createIceFireworks(x, y) { for (var i = 0; i < 15; i++) { var spark = new IceSpark(); spark.x = x; spark.y = y; iceFireworks.push(spark); game.addChild(spark); } } game.update = function () { for (var i = iceFireworks.length - 1; i >= 0; i--) { if (iceFireworks[i].life <= 0) { continue; } } if (lightLevel > 0) { for (var j = 0; j < countdownButtons.length; j++) { if (countdownButtons[j].number > currentNumber) { countdownButtons[j].alpha = 0.3 + lightLevel * 0.7; } } blossom.alpha = 0.3 + lightLevel * 0.7; buttercup.alpha = 0.3 + lightLevel * 0.7; bubbles.alpha = 0.3 + lightLevel * 0.7; coco.alpha = 0.3 + lightLevel * 0.7; } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CocoCharacter = Container.expand(function () {
var self = Container.call(this);
var cocoGraphics = self.attachAsset('coco', {
anchorX: 0.5,
anchorY: 0.5
});
var cocoText = new Text2('COCO', {
size: 30,
fill: 0xFFFFFF
});
cocoText.anchor.set(0.5, 0.5);
cocoText.y = 80;
self.addChild(cocoText);
self.down = function (x, y, obj) {
LK.getSound('iceMagic').play();
createIceFireworks(self.x, self.y);
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut
});
}
});
};
return self;
});
var CountdownButton = Container.expand(function (number) {
var self = Container.call(this);
self.number = number;
self.isActive = number === 10;
var buttonGraphics = self.attachAsset('countdownButton', {
anchorX: 0.5,
anchorY: 0.5
});
var buttonText = new Text2(number.toString(), {
size: 60,
fill: self.isActive ? "#ffffff" : "#666666"
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.activate = function () {
self.isActive = true;
buttonText.fill = "#ffffff";
buttonGraphics.tint = 0xffffff;
};
self.deactivate = function () {
self.isActive = false;
buttonText.fill = "#333333";
buttonGraphics.tint = 0x333333;
};
self.down = function (x, y, obj) {
if (self.isActive && currentNumber === self.number) {
LK.getSound('buttonTap').play();
self.deactivate();
currentNumber--;
if (currentNumber > 0) {
for (var i = 0; i < countdownButtons.length; i++) {
if (countdownButtons[i].number === currentNumber) {
countdownButtons[i].activate();
break;
}
}
}
lightLevel += 0.1;
lightOverlay.alpha = lightLevel;
if (currentNumber === 0) {
LK.getSound('victory').play();
LK.effects.flashScreen(0xffffff, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
}
}
};
return self;
});
var IceSpark = Container.expand(function () {
var self = Container.call(this);
var sparkGraphics = self.attachAsset('iceSpark', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 10;
self.vy = (Math.random() - 0.5) * 10;
self.life = 60;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.life--;
sparkGraphics.alpha = self.life / 60;
if (self.life <= 0) {
self.destroy();
for (var i = iceFireworks.length - 1; i >= 0; i--) {
if (iceFireworks[i] === self) {
iceFireworks.splice(i, 1);
break;
}
}
}
};
return self;
});
var PowerpuffGirl = Container.expand(function (assetId, color) {
var self = Container.call(this);
var girlGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
var girlText = new Text2(assetId.toUpperCase(), {
size: 30,
fill: 0xFFFFFF
});
girlText.anchor.set(0.5, 0.5);
girlText.y = 80;
self.addChild(girlText);
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0f0f23
});
/****
* Game Code
****/
var currentNumber = 10;
var lightLevel = 0;
var countdownButtons = [];
var iceFireworks = [];
var darkGarden = game.addChild(LK.getAsset('darkGarden', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
}));
var lightOverlay = game.addChild(LK.getAsset('lightOverlay', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366,
alpha: 0
}));
var blossom = game.addChild(new PowerpuffGirl('blossom', 0xff69b4));
blossom.x = 300;
blossom.y = 600;
var buttercup = game.addChild(new PowerpuffGirl('buttercup', 0x90ee90));
buttercup.x = 700;
buttercup.y = 800;
var bubbles = game.addChild(new PowerpuffGirl('bubbles', 0x00bfff));
bubbles.x = 1400;
bubbles.y = 600;
var coco = game.addChild(new CocoCharacter());
coco.x = 1024;
coco.y = 1000;
for (var i = 10; i >= 1; i--) {
var button = new CountdownButton(i);
var angle = (i - 1) * (Math.PI * 2 / 10);
var radius = 400;
button.x = 1024 + Math.cos(angle) * radius;
button.y = 1366 + Math.sin(angle) * radius;
countdownButtons.push(button);
game.addChild(button);
}
var titleText = new Text2('Tap numbers 10 to 1!', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 300;
game.addChild(titleText);
var instructionText = new Text2('Tap Coco for ice fireworks!', {
size: 50,
fill: 0x87CEEB
});
instructionText.anchor.set(0.5, 0.5);
instructionText.x = 1024;
instructionText.y = 380;
game.addChild(instructionText);
function createIceFireworks(x, y) {
for (var i = 0; i < 15; i++) {
var spark = new IceSpark();
spark.x = x;
spark.y = y;
iceFireworks.push(spark);
game.addChild(spark);
}
}
game.update = function () {
for (var i = iceFireworks.length - 1; i >= 0; i--) {
if (iceFireworks[i].life <= 0) {
continue;
}
}
if (lightLevel > 0) {
for (var j = 0; j < countdownButtons.length; j++) {
if (countdownButtons[j].number > currentNumber) {
countdownButtons[j].alpha = 0.3 + lightLevel * 0.7;
}
}
blossom.alpha = 0.3 + lightLevel * 0.7;
buttercup.alpha = 0.3 + lightLevel * 0.7;
bubbles.alpha = 0.3 + lightLevel * 0.7;
coco.alpha = 0.3 + lightLevel * 0.7;
}
};