/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Balloon class representing each balloon in the game
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() * 2 + 1; // Random speed for each balloon
// Update function to move the balloon upwards
self.update = function () {
self.y -= self.speed;
if (self.y < -balloonGraphics.height) {
self.destroy();
}
};
// Event handler for popping the balloon
self.down = function (x, y, obj) {
self.pop();
};
// Function to handle popping the balloon
self.pop = function () {
LK.setScore(LK.getScore() + 1);
self.destroy();
};
});
// Dart class representing the player's projectile
var Dart = Container.expand(function () {
var self = Container.call(this);
var dartGraphics = self.attachAsset('dart', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
// Update function to move the dart upwards
self.update = function () {
self.y -= self.speed;
if (self.y < -dartGraphics.height) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var balloons = [];
var darts = [];
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new balloon
function spawnBalloon() {
var newBalloon = new Balloon();
newBalloon.x = Math.random() * 2048;
newBalloon.y = 2732 + newBalloon.height;
balloons.push(newBalloon);
game.addChild(newBalloon);
}
// Function to shoot a dart
function shootDart(x, y) {
var newDart = new Dart();
newDart.x = x;
newDart.y = y;
darts.push(newDart);
game.addChild(newDart);
}
// Game update function
game.update = function () {
// Update balloons
for (var i = balloons.length - 1; i >= 0; i--) {
var balloon = balloons[i];
balloon.update();
if (balloon.y < -balloon.height) {
balloons.splice(i, 1);
}
}
// Update darts
for (var j = darts.length - 1; j >= 0; j--) {
var dart = darts[j];
dart.update();
if (dart.y < -dart.height) {
darts.splice(j, 1);
}
}
// Check for collisions between darts and balloons
for (var k = darts.length - 1; k >= 0; k--) {
var dart = darts[k];
for (var l = balloons.length - 1; l >= 0; l--) {
var balloon = balloons[l];
if (dart.intersects(balloon)) {
balloon.pop();
dart.destroy();
darts.splice(k, 1);
break;
}
}
}
// Update score display
scoreTxt.setText(LK.getScore());
// Spawn new balloons periodically
if (LK.ticks % 60 === 0) {
spawnBalloon();
}
};
// Event listener for shooting darts
game.down = function (x, y, obj) {
shootDart(x, y);
}; /****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Balloon class representing each balloon in the game
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() * 2 + 1; // Random speed for each balloon
// Update function to move the balloon upwards
self.update = function () {
self.y -= self.speed;
if (self.y < -balloonGraphics.height) {
self.destroy();
}
};
// Event handler for popping the balloon
self.down = function (x, y, obj) {
self.pop();
};
// Function to handle popping the balloon
self.pop = function () {
LK.setScore(LK.getScore() + 1);
self.destroy();
};
});
// Dart class representing the player's projectile
var Dart = Container.expand(function () {
var self = Container.call(this);
var dartGraphics = self.attachAsset('dart', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 10;
// Update function to move the dart upwards
self.update = function () {
self.y -= self.speed;
if (self.y < -dartGraphics.height) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
var balloons = [];
var darts = [];
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to spawn a new balloon
function spawnBalloon() {
var newBalloon = new Balloon();
newBalloon.x = Math.random() * 2048;
newBalloon.y = 2732 + newBalloon.height;
balloons.push(newBalloon);
game.addChild(newBalloon);
}
// Function to shoot a dart
function shootDart(x, y) {
var newDart = new Dart();
newDart.x = x;
newDart.y = y;
darts.push(newDart);
game.addChild(newDart);
}
// Game update function
game.update = function () {
// Update balloons
for (var i = balloons.length - 1; i >= 0; i--) {
var balloon = balloons[i];
balloon.update();
if (balloon.y < -balloon.height) {
balloons.splice(i, 1);
}
}
// Update darts
for (var j = darts.length - 1; j >= 0; j--) {
var dart = darts[j];
dart.update();
if (dart.y < -dart.height) {
darts.splice(j, 1);
}
}
// Check for collisions between darts and balloons
for (var k = darts.length - 1; k >= 0; k--) {
var dart = darts[k];
for (var l = balloons.length - 1; l >= 0; l--) {
var balloon = balloons[l];
if (dart.intersects(balloon)) {
balloon.pop();
dart.destroy();
darts.splice(k, 1);
break;
}
}
}
// Update score display
scoreTxt.setText(LK.getScore());
// Spawn new balloons periodically
if (LK.ticks % 60 === 0) {
spawnBalloon();
}
};
// Event listener for shooting darts
game.down = function (x, y, obj) {
shootDart(x, y);
};