/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Balloon class to represent each balloon in the game var Balloon = Container.expand(function () { var self = Container.call(this); // Randomly choose a color for the balloon var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff]; var color = colors[Math.floor(Math.random() * colors.length)]; // Create and attach balloon asset // Randomly choose a size for the balloon var sizes = [75, 100, 125, 150, 175, 200]; var size = sizes[Math.floor(Math.random() * sizes.length)]; var balloonGraphics = self.attachAsset('balloon', { color: color, shape: 'ellipse', width: size, height: size, anchorX: 0.5, anchorY: 0.5 }); // Set initial speed and direction self.speed = Math.random() * 4 + 1; // Increase the range of speed to make balloons appear with different speeds self.direction = Math.random() > 0.5 ? 1 : -1; // Update function to move the balloon self.update = function () { if (!self.popped) { self.y -= self.speed; self.x += self.direction * 0.5; // Prevent balloon from leaving the screen horizontally if (self.x < 0) { self.x = 0; self.direction = 1; } else if (self.x > 2048) { self.x = 2048; self.direction = -1; } // Destroy balloon if it goes off screen if (self.y < -100) { self.destroy(); } } }; // Event handler for popping the balloon self.down = function (x, y, obj) { // Increase score LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Play the PopSound sound LK.getSound('PopSound').play(); // Replace the balloon asset with the PoppedBalloon asset self.removeChild(balloonGraphics); var poppedBalloonGraphics = self.attachAsset('PoppedBalloon', { color: color, shape: 'ellipse', width: size, height: size, anchorX: 0.5, anchorY: 0.5 }); // Remove the down event handler to make the popped balloon unclickable self.down = null; // Set popped flag self.popped = true; // Destroy the balloon after a short delay LK.setTimeout(function () { self.destroy(); }, 500); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Light blue background }); /**** * Game Code ****/ var background = game.attachAsset('background', { anchorX: 0, anchorY: 0 }); var line = game.attachAsset('line', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Initialize lives images var lives = []; for (var i = 0; i < 3; i++) { var life = game.attachAsset('Life', { anchorX: 0.5, anchorY: 0.5, x: 200 + i * 200, // Increase the distance between each life indicator y: 200, // Move the life indicator further away from the figure scaleX: 1.5, // Increase the size of the life indicator scaleY: 1.5 // Increase the size of the life indicator }); lives.push(life); } // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF, font: "'Comic Sans MS', cursive, sans-serif" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Array to keep track of balloons var balloons = []; // Function to spawn a new balloon function spawnBalloon() { var newBalloon = new Balloon(); newBalloon.x = Math.random() * 2048; newBalloon.y = 2732 + 100; // Start below the screen balloons.push(newBalloon); game.addChild(newBalloon); } // Set interval to spawn balloons var spawnInterval; var spawnTime = 1000; function spawnBalloons() { spawnBalloon(); // Decrease spawn time by 1% each time but not less than 100ms spawnTime = Math.max(spawnTime * 0.99, 100); spawnInterval = LK.setTimeout(spawnBalloons, spawnTime); } spawnBalloons(); // Update function for the game game.update = function () { // Update each balloon for (var i = balloons.length - 1; i >= 0; i--) { var balloon = balloons[i]; balloon.update(); // Check if balloon intersects with line if (balloon.intersects(line) && !balloon.hit) { balloon.hit = true; balloon.destroy(); // Destroy a life var life = lives.pop(); life.destroy(); // Play the LoseLife sound LK.getSound('LoseLife').play(); // Check if all lives are lost if (lives.length === 0) { LK.showGameOver(); } } // Remove balloon from array if destroyed if (balloon.destroyed) { balloons.splice(i, 1); } } }; // Start the game with an initial balloon spawnBalloon();
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Balloon class to represent each balloon in the game
var Balloon = Container.expand(function () {
var self = Container.call(this);
// Randomly choose a color for the balloon
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff];
var color = colors[Math.floor(Math.random() * colors.length)];
// Create and attach balloon asset
// Randomly choose a size for the balloon
var sizes = [75, 100, 125, 150, 175, 200];
var size = sizes[Math.floor(Math.random() * sizes.length)];
var balloonGraphics = self.attachAsset('balloon', {
color: color,
shape: 'ellipse',
width: size,
height: size,
anchorX: 0.5,
anchorY: 0.5
});
// Set initial speed and direction
self.speed = Math.random() * 4 + 1; // Increase the range of speed to make balloons appear with different speeds
self.direction = Math.random() > 0.5 ? 1 : -1;
// Update function to move the balloon
self.update = function () {
if (!self.popped) {
self.y -= self.speed;
self.x += self.direction * 0.5;
// Prevent balloon from leaving the screen horizontally
if (self.x < 0) {
self.x = 0;
self.direction = 1;
} else if (self.x > 2048) {
self.x = 2048;
self.direction = -1;
}
// Destroy balloon if it goes off screen
if (self.y < -100) {
self.destroy();
}
}
};
// Event handler for popping the balloon
self.down = function (x, y, obj) {
// Increase score
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
// Play the PopSound sound
LK.getSound('PopSound').play();
// Replace the balloon asset with the PoppedBalloon asset
self.removeChild(balloonGraphics);
var poppedBalloonGraphics = self.attachAsset('PoppedBalloon', {
color: color,
shape: 'ellipse',
width: size,
height: size,
anchorX: 0.5,
anchorY: 0.5
});
// Remove the down event handler to make the popped balloon unclickable
self.down = null;
// Set popped flag
self.popped = true;
// Destroy the balloon after a short delay
LK.setTimeout(function () {
self.destroy();
}, 500);
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb // Light blue background
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0
});
var line = game.attachAsset('line', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Initialize lives images
var lives = [];
for (var i = 0; i < 3; i++) {
var life = game.attachAsset('Life', {
anchorX: 0.5,
anchorY: 0.5,
x: 200 + i * 200,
// Increase the distance between each life indicator
y: 200,
// Move the life indicator further away from the figure
scaleX: 1.5,
// Increase the size of the life indicator
scaleY: 1.5 // Increase the size of the life indicator
});
lives.push(life);
}
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF,
font: "'Comic Sans MS', cursive, sans-serif"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to keep track of balloons
var balloons = [];
// Function to spawn a new balloon
function spawnBalloon() {
var newBalloon = new Balloon();
newBalloon.x = Math.random() * 2048;
newBalloon.y = 2732 + 100; // Start below the screen
balloons.push(newBalloon);
game.addChild(newBalloon);
}
// Set interval to spawn balloons
var spawnInterval;
var spawnTime = 1000;
function spawnBalloons() {
spawnBalloon();
// Decrease spawn time by 1% each time but not less than 100ms
spawnTime = Math.max(spawnTime * 0.99, 100);
spawnInterval = LK.setTimeout(spawnBalloons, spawnTime);
}
spawnBalloons();
// Update function for the game
game.update = function () {
// Update each balloon
for (var i = balloons.length - 1; i >= 0; i--) {
var balloon = balloons[i];
balloon.update();
// Check if balloon intersects with line
if (balloon.intersects(line) && !balloon.hit) {
balloon.hit = true;
balloon.destroy();
// Destroy a life
var life = lives.pop();
life.destroy();
// Play the LoseLife sound
LK.getSound('LoseLife').play();
// Check if all lives are lost
if (lives.length === 0) {
LK.showGameOver();
}
}
// Remove balloon from array if destroyed
if (balloon.destroyed) {
balloons.splice(i, 1);
}
}
};
// Start the game with an initial balloon
spawnBalloon();
Colorful balloon without background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Daytime sky. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Red heart shaped balloon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows