/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Balloon class var Balloon = Container.expand(function () { var self = Container.call(this); var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff]; var color = colors[Math.floor(Math.random() * colors.length)]; var balloonGraphics = self.attachAsset('balloon', { width: 100, height: 150, color: color, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; self.update = function () { self.y -= self.speed; if (self.y < -100) { self.destroy(); } }; self.down = function (x, y, obj) { if (color === 0xff0000) { // Red balloon explodes explode(self.x, self.y); } else { // Other balloons just pop self.destroy(); score++; scoreTxt.setText(score); } }; }); // Explosion class var Explosion = Container.expand(function () { var self = Container.call(this); var explosionGraphics = self.attachAsset('explosion', { width: 200, height: 200, color: 0xffa500, shape: 'ellipse', anchorX: 0.5, anchorY: 0.5 }); self.update = function () { explosionGraphics.alpha -= 0.05; if (explosionGraphics.alpha <= 0) { self.destroy(); } }; }); var Spike = Container.expand(function () { var self = Container.call(this); var spikeGraphics = self.attachAsset('spike', { width: 20, height: 20, color: 0x000000, shape: 'box', anchorX: 0.5, anchorY: 0.5 }); self.speedX = Math.random() * 10 - 5; self.speedY = Math.random() * 10 - 5; self.update = function () { self.x += self.speedX; self.y += self.speedY; if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Init game with sky blue background }); /**** * Game Code ****/ var balloons = []; var score = 0; var missedBalloons = 0; // Initialize missed balloons counter var balloonSpawnInterval = 30; // Initial balloon spawn interval in ticks var balloonSpawnCounter = 0; // Counter to track time for increasing balloon spawn rate var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); var missedTxt = new Text2('Missed: 0', { size: 100, fill: "#ff0000" }); missedTxt.anchor.set(0.5, 0); missedTxt.y = 200; // Position below the score text LK.gui.top.addChild(missedTxt); LK.gui.top.addChild(scoreTxt); function spawnBalloon() { var balloon = new Balloon(); balloon.x = Math.random() * 2048; balloon.y = 2732 + 100; balloons.push(balloon); game.addChild(balloon); } function explode(x, y) { var explosion = new Explosion(); explosion.x = x; explosion.y = y; game.addChild(explosion); // Launch spikes in random directions for (var i = 0; i < 10; i++) { var spike = new Spike(); spike.x = x; spike.y = y; game.addChild(spike); } // Destroy nearby balloons for (var i = balloons.length - 1; i >= 0; i--) { if (Math.abs(balloons[i].x - x) < 200 && Math.abs(balloons[i].y - y) < 200) { balloons[i].destroy(); balloons.splice(i, 1); score++; scoreTxt.setText(score); } } } game.update = function () { for (var i = balloons.length - 1; i >= 0; i--) { balloons[i].update(); if (balloons[i].y < -100) { balloons[i].destroy(); balloons.splice(i, 1); missedBalloons++; // Increment missed balloons counter score--; // Decrement score when a balloon is missed scoreTxt.setText(score); // Update score text missedTxt.setText('Missed: ' + missedBalloons); // Update missed balloons text } } // Update spikes var spikes = game.children.filter(function (child) { return child instanceof Spike; }); for (var i = spikes.length - 1; i >= 0; i--) { spikes[i].update(); // Check for collision with balloons for (var j = balloons.length - 1; j >= 0; j--) { if (spikes[i].intersects(balloons[j])) { balloons[j].destroy(); balloons.splice(j, 1); score++; scoreTxt.setText(score); score++; scoreTxt.setText(score); } } } if (LK.ticks % balloonSpawnInterval == 0) { spawnBalloon(); balloonSpawnCounter++; if (balloonSpawnCounter >= 30) { // Every 30 seconds balloonSpawnInterval = Math.max(10, balloonSpawnInterval - 1); // Decrease interval, minimum 10 ticks balloonSpawnCounter = 0; } } }; game.down = function (x, y, obj) { for (var i = balloons.length - 1; i >= 0; i--) { if (balloons[i].intersects({ x: x, y: y })) { balloons[i].down(x, y, obj); balloons.splice(i, 1); score++; scoreTxt.setText(score); break; } } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Balloon class
var Balloon = Container.expand(function () {
var self = Container.call(this);
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff];
var color = colors[Math.floor(Math.random() * colors.length)];
var balloonGraphics = self.attachAsset('balloon', {
width: 100,
height: 150,
color: color,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1;
self.update = function () {
self.y -= self.speed;
if (self.y < -100) {
self.destroy();
}
};
self.down = function (x, y, obj) {
if (color === 0xff0000) {
// Red balloon explodes
explode(self.x, self.y);
} else {
// Other balloons just pop
self.destroy();
score++;
scoreTxt.setText(score);
}
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
width: 200,
height: 200,
color: 0xffa500,
shape: 'ellipse',
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
explosionGraphics.alpha -= 0.05;
if (explosionGraphics.alpha <= 0) {
self.destroy();
}
};
});
var Spike = Container.expand(function () {
var self = Container.call(this);
var spikeGraphics = self.attachAsset('spike', {
width: 20,
height: 20,
color: 0x000000,
shape: 'box',
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = Math.random() * 10 - 5;
self.speedY = Math.random() * 10 - 5;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
if (self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Init game with sky blue background
});
/****
* Game Code
****/
var balloons = [];
var score = 0;
var missedBalloons = 0; // Initialize missed balloons counter
var balloonSpawnInterval = 30; // Initial balloon spawn interval in ticks
var balloonSpawnCounter = 0; // Counter to track time for increasing balloon spawn rate
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
var missedTxt = new Text2('Missed: 0', {
size: 100,
fill: "#ff0000"
});
missedTxt.anchor.set(0.5, 0);
missedTxt.y = 200; // Position below the score text
LK.gui.top.addChild(missedTxt);
LK.gui.top.addChild(scoreTxt);
function spawnBalloon() {
var balloon = new Balloon();
balloon.x = Math.random() * 2048;
balloon.y = 2732 + 100;
balloons.push(balloon);
game.addChild(balloon);
}
function explode(x, y) {
var explosion = new Explosion();
explosion.x = x;
explosion.y = y;
game.addChild(explosion);
// Launch spikes in random directions
for (var i = 0; i < 10; i++) {
var spike = new Spike();
spike.x = x;
spike.y = y;
game.addChild(spike);
}
// Destroy nearby balloons
for (var i = balloons.length - 1; i >= 0; i--) {
if (Math.abs(balloons[i].x - x) < 200 && Math.abs(balloons[i].y - y) < 200) {
balloons[i].destroy();
balloons.splice(i, 1);
score++;
scoreTxt.setText(score);
}
}
}
game.update = function () {
for (var i = balloons.length - 1; i >= 0; i--) {
balloons[i].update();
if (balloons[i].y < -100) {
balloons[i].destroy();
balloons.splice(i, 1);
missedBalloons++; // Increment missed balloons counter
score--; // Decrement score when a balloon is missed
scoreTxt.setText(score); // Update score text
missedTxt.setText('Missed: ' + missedBalloons); // Update missed balloons text
}
}
// Update spikes
var spikes = game.children.filter(function (child) {
return child instanceof Spike;
});
for (var i = spikes.length - 1; i >= 0; i--) {
spikes[i].update();
// Check for collision with balloons
for (var j = balloons.length - 1; j >= 0; j--) {
if (spikes[i].intersects(balloons[j])) {
balloons[j].destroy();
balloons.splice(j, 1);
score++;
scoreTxt.setText(score);
score++;
scoreTxt.setText(score);
}
}
}
if (LK.ticks % balloonSpawnInterval == 0) {
spawnBalloon();
balloonSpawnCounter++;
if (balloonSpawnCounter >= 30) {
// Every 30 seconds
balloonSpawnInterval = Math.max(10, balloonSpawnInterval - 1); // Decrease interval, minimum 10 ticks
balloonSpawnCounter = 0;
}
}
};
game.down = function (x, y, obj) {
for (var i = balloons.length - 1; i >= 0; i--) {
if (balloons[i].intersects({
x: x,
y: y
})) {
balloons[i].down(x, y, obj);
balloons.splice(i, 1);
score++;
scoreTxt.setText(score);
break;
}
}
};