/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Confetti = Container.expand(function () {
var self = Container.call(this);
var confettiGraphics = self.attachAsset('confetti', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 8;
self.vy = (Math.random() - 0.5) * 8 - 2;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.lifetime = 0;
self.maxLifetime = 1500;
self.update = function () {
self.lifetime += 16;
self.x += self.vx;
self.y += self.vy;
self.vy += 0.15;
self.rotation += self.rotationSpeed;
var progress = self.lifetime / self.maxLifetime;
confettiGraphics.alpha = 1 - progress;
};
return self;
});
var Confetti_2 = Container.expand(function () {
var self = Container.call(this);
var confetti2Graphics = self.attachAsset('Confetti_2', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 10;
self.vy = (Math.random() - 0.5) * 10 - 3;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.3;
self.lifetime = 0;
self.maxLifetime = 1500;
self.update = function () {
self.lifetime += 16;
self.x += self.vx;
self.y += self.vy;
self.vy += 0.15;
self.rotation += self.rotationSpeed;
var progress = self.lifetime / self.maxLifetime;
confetti2Graphics.alpha = 1 - progress;
};
return self;
});
var GameButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.isPressed = false;
self.lifetime = 0;
self.maxLifetime = 2000;
self.colorIndex = Math.floor(Math.random() * 6);
var colors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
buttonGraphics.tint = colors[self.colorIndex];
self.update = function () {
self.lifetime += 16;
var progress = self.lifetime / self.maxLifetime;
var scale = 1 - progress * 0.3;
buttonGraphics.scale.x = scale;
buttonGraphics.scale.y = scale;
buttonGraphics.alpha = 1 - progress * 0.5;
};
self.press = function () {
self.isPressed = true;
};
return self;
});
var Rabbit = Container.expand(function () {
var self = Container.call(this);
var rabbitBody = self.attachAsset('rabbit', {
anchorX: 0.5,
anchorY: 0.5
});
var leftEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
var rightEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
var leftEar = LK.getAsset('rabbitEar', {
anchorX: 0.5,
anchorY: 1
});
var rightEar = LK.getAsset('rabbitEar', {
anchorX: 0.5,
anchorY: 1
});
self.addChild(leftEar);
self.addChild(rightEar);
self.addChild(leftEye);
self.addChild(rightEye);
leftEar.x = -30;
leftEar.y = -50;
rightEar.x = 30;
rightEar.y = -50;
leftEye.x = -25;
leftEye.y = -30;
rightEye.x = 25;
rightEye.y = -30;
self.lives = 3;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var rabbit = game.addChild(new Rabbit());
rabbit.x = 2048 / 2;
rabbit.y = 2200;
var buttons = [];
var confetti = [];
var score = 0;
var lives = 3;
var gameActive = true;
var buttonSpawnTimer = 0;
var buttonSpawnInterval = 800;
var difficultyMultiplier = 1;
var frameCount = 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 100,
fill: 0xFF6B6B
});
livesTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(livesTxt);
function spawnButton() {
var newButton = new GameButton();
newButton.x = Math.random() * 1800 + 124;
newButton.y = Math.random() * 1500 + 200;
newButton.maxLifetime = 2000 - difficultyMultiplier * 200;
if (newButton.maxLifetime < 600) newButton.maxLifetime = 600;
buttons.push(newButton);
game.addChild(newButton);
}
function updateDifficulty() {
difficultyMultiplier = 1 + score / 20 * 0.5;
if (difficultyMultiplier > 3) difficultyMultiplier = 3;
buttonSpawnInterval = 800 - difficultyMultiplier * 150;
if (buttonSpawnInterval < 300) buttonSpawnInterval = 300;
}
function emitConfetti() {
var confettiColors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
for (var i = 0; i < 30; i++) {
var newConfetti = new Confetti();
newConfetti.x = rabbit.x;
newConfetti.y = rabbit.y;
var colorIndex = Math.floor(Math.random() * confettiColors.length);
var confettiGraphics = newConfetti.children[0];
confettiGraphics.tint = confettiColors[colorIndex];
confetti.push(newConfetti);
game.addChild(newConfetti);
}
for (var j = 0; j < 20; j++) {
var newConfetti2 = new Confetti_2();
newConfetti2.x = rabbit.x;
newConfetti2.y = rabbit.y;
var colorIndex2 = Math.floor(Math.random() * confettiColors.length);
newConfetti2.children[0].tint = confettiColors[colorIndex2];
confetti.push(newConfetti2);
game.addChild(newConfetti2);
}
}
game.down = function (x, y, obj) {
if (!gameActive) return;
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.intersects(obj) || x > button.x - 60 && x < button.x + 60 && y > button.y - 60 && y < button.y + 60) {
if (!button.isPressed) {
button.press();
score++;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
updateDifficulty();
LK.getSound('buttonTap').play();
tween(button, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
button.destroy();
buttons.splice(a, 1);
}
});
}
return;
}
}
};
game.update = function () {
frameCount++;
if (!gameActive) return;
buttonSpawnTimer += 16;
if (buttonSpawnTimer >= buttonSpawnInterval) {
spawnButton();
buttonSpawnTimer = 0;
}
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.lifetime >= button.maxLifetime && !button.isPressed) {
LK.getSound('missButton').play();
lives--;
livesTxt.setText('Lives: ' + lives);
tween(button, {
tint: 0xff0000
}, {
duration: 100
});
button.destroy();
buttons.splice(a, 1);
if (lives <= 0) {
gameActive = false;
LK.getSound('explosion').play();
LK.effects.flashScreen(0xff6b6b, 500);
emitConfetti();
var explosionTint = {
tint: 0xffffff
};
tween(rabbit, {
tint: 0xff6b6b,
alpha: 0
}, {
duration: 300
});
LK.setTimeout(function () {
LK.showGameOver();
}, 1800);
}
}
for (var c = confetti.length - 1; c >= 0; c--) {
var conf = confetti[c];
if (conf.lifetime >= conf.maxLifetime) {
conf.destroy();
confetti.splice(c, 1);
}
}
}
};
LK.playMusic('gameMusic'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Confetti = Container.expand(function () {
var self = Container.call(this);
var confettiGraphics = self.attachAsset('confetti', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 8;
self.vy = (Math.random() - 0.5) * 8 - 2;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.lifetime = 0;
self.maxLifetime = 1500;
self.update = function () {
self.lifetime += 16;
self.x += self.vx;
self.y += self.vy;
self.vy += 0.15;
self.rotation += self.rotationSpeed;
var progress = self.lifetime / self.maxLifetime;
confettiGraphics.alpha = 1 - progress;
};
return self;
});
var Confetti_2 = Container.expand(function () {
var self = Container.call(this);
var confetti2Graphics = self.attachAsset('Confetti_2', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 10;
self.vy = (Math.random() - 0.5) * 10 - 3;
self.rotation = Math.random() * Math.PI * 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.3;
self.lifetime = 0;
self.maxLifetime = 1500;
self.update = function () {
self.lifetime += 16;
self.x += self.vx;
self.y += self.vy;
self.vy += 0.15;
self.rotation += self.rotationSpeed;
var progress = self.lifetime / self.maxLifetime;
confetti2Graphics.alpha = 1 - progress;
};
return self;
});
var GameButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
self.isPressed = false;
self.lifetime = 0;
self.maxLifetime = 2000;
self.colorIndex = Math.floor(Math.random() * 6);
var colors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
buttonGraphics.tint = colors[self.colorIndex];
self.update = function () {
self.lifetime += 16;
var progress = self.lifetime / self.maxLifetime;
var scale = 1 - progress * 0.3;
buttonGraphics.scale.x = scale;
buttonGraphics.scale.y = scale;
buttonGraphics.alpha = 1 - progress * 0.5;
};
self.press = function () {
self.isPressed = true;
};
return self;
});
var Rabbit = Container.expand(function () {
var self = Container.call(this);
var rabbitBody = self.attachAsset('rabbit', {
anchorX: 0.5,
anchorY: 0.5
});
var leftEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
var rightEye = LK.getAsset('rabbitEye', {
anchorX: 0.5,
anchorY: 0.5
});
var leftEar = LK.getAsset('rabbitEar', {
anchorX: 0.5,
anchorY: 1
});
var rightEar = LK.getAsset('rabbitEar', {
anchorX: 0.5,
anchorY: 1
});
self.addChild(leftEar);
self.addChild(rightEar);
self.addChild(leftEye);
self.addChild(rightEye);
leftEar.x = -30;
leftEar.y = -50;
rightEar.x = 30;
rightEar.y = -50;
leftEye.x = -25;
leftEye.y = -30;
rightEye.x = 25;
rightEye.y = -30;
self.lives = 3;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
var rabbit = game.addChild(new Rabbit());
rabbit.x = 2048 / 2;
rabbit.y = 2200;
var buttons = [];
var confetti = [];
var score = 0;
var lives = 3;
var gameActive = true;
var buttonSpawnTimer = 0;
var buttonSpawnInterval = 800;
var difficultyMultiplier = 1;
var frameCount = 0;
var scoreTxt = new Text2('Score: 0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 100,
fill: 0xFF6B6B
});
livesTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(livesTxt);
function spawnButton() {
var newButton = new GameButton();
newButton.x = Math.random() * 1800 + 124;
newButton.y = Math.random() * 1500 + 200;
newButton.maxLifetime = 2000 - difficultyMultiplier * 200;
if (newButton.maxLifetime < 600) newButton.maxLifetime = 600;
buttons.push(newButton);
game.addChild(newButton);
}
function updateDifficulty() {
difficultyMultiplier = 1 + score / 20 * 0.5;
if (difficultyMultiplier > 3) difficultyMultiplier = 3;
buttonSpawnInterval = 800 - difficultyMultiplier * 150;
if (buttonSpawnInterval < 300) buttonSpawnInterval = 300;
}
function emitConfetti() {
var confettiColors = [0xff6b9d, 0x00d4ff, 0xffed4e, 0x00ff88, 0xff6b6b, 0xb366ff];
for (var i = 0; i < 30; i++) {
var newConfetti = new Confetti();
newConfetti.x = rabbit.x;
newConfetti.y = rabbit.y;
var colorIndex = Math.floor(Math.random() * confettiColors.length);
var confettiGraphics = newConfetti.children[0];
confettiGraphics.tint = confettiColors[colorIndex];
confetti.push(newConfetti);
game.addChild(newConfetti);
}
for (var j = 0; j < 20; j++) {
var newConfetti2 = new Confetti_2();
newConfetti2.x = rabbit.x;
newConfetti2.y = rabbit.y;
var colorIndex2 = Math.floor(Math.random() * confettiColors.length);
newConfetti2.children[0].tint = confettiColors[colorIndex2];
confetti.push(newConfetti2);
game.addChild(newConfetti2);
}
}
game.down = function (x, y, obj) {
if (!gameActive) return;
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.intersects(obj) || x > button.x - 60 && x < button.x + 60 && y > button.y - 60 && y < button.y + 60) {
if (!button.isPressed) {
button.press();
score++;
LK.setScore(score);
scoreTxt.setText('Score: ' + score);
updateDifficulty();
LK.getSound('buttonTap').play();
tween(button, {
alpha: 0
}, {
duration: 200,
onFinish: function onFinish() {
button.destroy();
buttons.splice(a, 1);
}
});
}
return;
}
}
};
game.update = function () {
frameCount++;
if (!gameActive) return;
buttonSpawnTimer += 16;
if (buttonSpawnTimer >= buttonSpawnInterval) {
spawnButton();
buttonSpawnTimer = 0;
}
for (var a = buttons.length - 1; a >= 0; a--) {
var button = buttons[a];
if (button.lifetime >= button.maxLifetime && !button.isPressed) {
LK.getSound('missButton').play();
lives--;
livesTxt.setText('Lives: ' + lives);
tween(button, {
tint: 0xff0000
}, {
duration: 100
});
button.destroy();
buttons.splice(a, 1);
if (lives <= 0) {
gameActive = false;
LK.getSound('explosion').play();
LK.effects.flashScreen(0xff6b6b, 500);
emitConfetti();
var explosionTint = {
tint: 0xffffff
};
tween(rabbit, {
tint: 0xff6b6b,
alpha: 0
}, {
duration: 300
});
LK.setTimeout(function () {
LK.showGameOver();
}, 1800);
}
}
for (var c = confetti.length - 1; c >= 0; c--) {
var conf = confetti[c];
if (conf.lifetime >= conf.maxLifetime) {
conf.destroy();
confetti.splice(c, 1);
}
}
}
};
LK.playMusic('gameMusic');