/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Balloon = Container.expand(function (isBlack) { var self = Container.call(this); // Choose balloon type var balloonType = isBlack ? 'blackBalloon' : 'colorBalloon'; var balloonGraphics = self.attachAsset(balloonType, { anchorX: 0.5, anchorY: 0.5 }); // Set random color for regular balloons if (!isBlack) { var colors = [0xff6b6b, 0x4ecdc4, 0x45b7d1, 0x96ceb4, 0xfeca57, 0xff9ff3, 0x54a0ff]; balloonGraphics.tint = colors[Math.floor(Math.random() * colors.length)]; } self.isBlack = isBlack; self.popped = false; // Float upward animation self.floatSpeed = 1 + Math.random() * 2; self.update = function () { if (!self.popped) { self.y -= self.floatSpeed; } }; self.pop = function () { if (self.popped) return; self.popped = true; // Pop animation tween(balloonGraphics, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); // Play sound if (self.isBlack) { LK.getSound('gameOver').play(); } else { LK.getSound('pop').play(); } }; self.down = function (x, y, obj) { if (self.popped) return; if (self.isBlack) { // Game over LK.showGameOver(); } else { // Score point and pop LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); self.pop(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game variables var balloons = []; var spawnTimer = 0; var spawnInterval = 120; // 2 seconds at 60fps var difficultyTimer = 0; var difficultyInterval = 600; // 10 seconds at 60fps // Score display var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 100; // Move down from very top // Initialize score scoreTxt.setText(LK.getScore()); game.update = function () { // Update all balloons for (var i = balloons.length - 1; i >= 0; i--) { var balloon = balloons[i]; // Remove balloons that floated off screen if (balloon.y < -100) { balloon.destroy(); balloons.splice(i, 1); } } // Spawn new balloons spawnTimer++; if (spawnTimer >= spawnInterval) { spawnTimer = 0; spawnBalloon(); } // Increase difficulty every 10 seconds difficultyTimer++; if (difficultyTimer >= difficultyInterval) { difficultyTimer = 0; if (spawnInterval > 30) { // Minimum spawn rate spawnInterval -= 10; } } }; function spawnBalloon() { // 15% chance for black balloon var isBlack = Math.random() < 0.15; var balloon = new Balloon(isBlack); // Random position across screen width, spawn below screen balloon.x = 100 + Math.random() * (2048 - 200); balloon.y = 2732 + 60; // Start below screen balloons.push(balloon); game.addChild(balloon); } // Spawn initial balloons for (var i = 0; i < 3; i++) { LK.setTimeout(function () { spawnBalloon(); }, i * 1000); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Balloon = Container.expand(function (isBlack) {
var self = Container.call(this);
// Choose balloon type
var balloonType = isBlack ? 'blackBalloon' : 'colorBalloon';
var balloonGraphics = self.attachAsset(balloonType, {
anchorX: 0.5,
anchorY: 0.5
});
// Set random color for regular balloons
if (!isBlack) {
var colors = [0xff6b6b, 0x4ecdc4, 0x45b7d1, 0x96ceb4, 0xfeca57, 0xff9ff3, 0x54a0ff];
balloonGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
}
self.isBlack = isBlack;
self.popped = false;
// Float upward animation
self.floatSpeed = 1 + Math.random() * 2;
self.update = function () {
if (!self.popped) {
self.y -= self.floatSpeed;
}
};
self.pop = function () {
if (self.popped) return;
self.popped = true;
// Pop animation
tween(balloonGraphics, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
// Play sound
if (self.isBlack) {
LK.getSound('gameOver').play();
} else {
LK.getSound('pop').play();
}
};
self.down = function (x, y, obj) {
if (self.popped) return;
if (self.isBlack) {
// Game over
LK.showGameOver();
} else {
// Score point and pop
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
self.pop();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var balloons = [];
var spawnTimer = 0;
var spawnInterval = 120; // 2 seconds at 60fps
var difficultyTimer = 0;
var difficultyInterval = 600; // 10 seconds at 60fps
// Score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 100; // Move down from very top
// Initialize score
scoreTxt.setText(LK.getScore());
game.update = function () {
// Update all balloons
for (var i = balloons.length - 1; i >= 0; i--) {
var balloon = balloons[i];
// Remove balloons that floated off screen
if (balloon.y < -100) {
balloon.destroy();
balloons.splice(i, 1);
}
}
// Spawn new balloons
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnTimer = 0;
spawnBalloon();
}
// Increase difficulty every 10 seconds
difficultyTimer++;
if (difficultyTimer >= difficultyInterval) {
difficultyTimer = 0;
if (spawnInterval > 30) {
// Minimum spawn rate
spawnInterval -= 10;
}
}
};
function spawnBalloon() {
// 15% chance for black balloon
var isBlack = Math.random() < 0.15;
var balloon = new Balloon(isBlack);
// Random position across screen width, spawn below screen
balloon.x = 100 + Math.random() * (2048 - 200);
balloon.y = 2732 + 60; // Start below screen
balloons.push(balloon);
game.addChild(balloon);
}
// Spawn initial balloons
for (var i = 0; i < 3; i++) {
LK.setTimeout(function () {
spawnBalloon();
}, i * 1000);
}