/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Balloon class
var Balloon = Container.expand(function () {
var self = Container.call(this);
var balloonGraphics = self.attachAsset('balloon', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 5 + 2; // Random speed between 2 and 7
self.update = function () {
self.y -= self.speed;
if (self.y < -50) {
self.destroy();
}
};
self.down = function (x, y, obj) {
self.destroy();
game.setBackgroundColor(0xffffff); // Change background to white
LK.setTimeout(function () {
game.setBackgroundColor(0x000000); // Change background back to black after 100ms
}, 100);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
var balloons = [];
var spawnBalloon = function () {
var newBalloon = new Balloon();
newBalloon.x = Math.random() * 2048;
newBalloon.y = 2732 + 50; // Start just below the screen
balloons.push(newBalloon);
game.addChild(newBalloon);
};
// Create balloons at intervals
var balloonInterval = LK.setInterval(spawnBalloon, 500); // Spawn a balloon every 500ms
// Update game logic
game.update = function () {
for (var i = balloons.length - 1; i >= 0; i--) {
if (balloons[i].y < -50) {
balloons[i].destroy();
balloons.splice(i, 1);
}
}
};