/**** * Classes ****/ // 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 var balloonGraphics = self.attachAsset('balloon', { tint: color, // Changed from color to tint anchorX: 0.5, anchorY: 0.5 }); // Set initial speed and direction self.speed = Math.random() * 2 + 1; self.direction = (Math.random() - 0.5) * 2; self.update = function () { self.y -= self.speed; self.x += self.direction; if (self.x < 100 || self.x > 1948) { self.direction *= -1; } if (self.y < -100) { LK.setScore(LK.getScore() - 1); scoreTxt.setText(LK.getScore()); if (LK.getScore() <= 0) { game.end(); return; } self.y = 2732 + 100; self.x = Math.random() * 2048; } }; self.down = function (x, y, obj) { LK.getSound('pop').play(); LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); var index = balloons.indexOf(self); if (index > -1) { balloons.splice(index, 1); } self.destroy(); }; }); // Balloon2 class for new balloon type var Balloon2 = Container.expand(function () { var self = Container.call(this); // Randomly choose a color for the balloon var colors = [0xff5555, 0x55ff55, 0x5555ff, 0xffff55, 0xff55ff, 0x55ffff]; var color = colors[Math.floor(Math.random() * colors.length)]; self.attachAsset('balloon2', { tint: color, anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 3 + 2; self.direction = (Math.random() - 0.5) * 2; self.update = function () { self.y -= self.speed; self.x += self.direction; if (self.x < 100 || self.x > 1948) { self.direction *= -1; } if (self.y < -100) { LK.setScore(LK.getScore() - 2); scoreTxt.setText(LK.getScore()); if (LK.getScore() <= 0) { game.end(); return; } self.y = 2732 + 100; self.x = Math.random() * 2048; } }; self.down = function (x, y, obj) { LK.getSound('pop').play(); LK.setScore(LK.getScore() + 2); scoreTxt.setText(LK.getScore()); var index = balloons.indexOf(self); if (index > -1) { balloons.splice(index, 1); } self.destroy(); }; }); // Cloud class var Cloud = Container.expand(function () { var self = Container.call(this); self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); self.x = Math.random() * 2048; self.y = Math.random() * 2732; self.speed = Math.random() * 0.5 + 0.2; self.update = function () { self.x -= self.speed; if (self.x < -300) { self.x = 2048 + 300; self.y = Math.random() * 2732; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Arrays and counters var balloons = []; var clouds = []; var balloon2Counter = 0; // Create functions function createCloud() { var newCloud = new Cloud(); clouds.push(newCloud); game.addChild(newCloud); } function createBalloon() { var newBalloon; if (balloon2Counter >= 10) { newBalloon = new Balloon2(); balloon2Counter = 0; } else { newBalloon = new Balloon(); balloon2Counter++; } newBalloon.x = Math.random() * 2048; newBalloon.y = 2732 + 100; balloons.push(newBalloon); game.addChild(newBalloon); } // Create initial objects for (var i = 0; i < 5; i++) { createCloud(); } for (var i = 0; i < 10; i++) { createBalloon(); } // Game update function game.update = function () { for (var i = clouds.length - 1; i >= 0; i--) { clouds[i].update(); } for (var i = balloons.length - 1; i >= 0; i--) { balloons[i].update(); } if (LK.ticks % 60 == 0) { createBalloon(); } }; // Game input handler game.down = function (x, y, obj) { for (var i = balloons.length - 1; i >= 0; i--) { if (balloons[i].intersects(obj)) { balloons[i].down(x, y, obj); break; } } }; // Difficulty scaling var difficulty = 1; LK.setInterval(function () { difficulty += 0.5; balloons.forEach(function (balloon) { balloon.speed += 0.1; }); }, 10000); // Game over handling game.end = function () { // Remove all balloons for (var i = balloons.length - 1; i >= 0; i--) { balloons[i].destroy(); } balloons = []; // Remove all clouds for (var i = clouds.length - 1; i >= 0; i--) { clouds[i].destroy(); } clouds = []; // Clear score text if (scoreTxt && scoreTxt.parent) { scoreTxt.parent.removeChild(scoreTxt); } // Create game over text var gameOverTxt = new Text2('Game Over! Score: ' + LK.getScore(), { size: 150, fill: 0xFFFFFF }); gameOverTxt.anchor.set(0.5, 0.5); game.addChild(gameOverTxt); };
/****
* Classes
****/
// 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
var balloonGraphics = self.attachAsset('balloon', {
tint: color,
// Changed from color to tint
anchorX: 0.5,
anchorY: 0.5
});
// Set initial speed and direction
self.speed = Math.random() * 2 + 1;
self.direction = (Math.random() - 0.5) * 2;
self.update = function () {
self.y -= self.speed;
self.x += self.direction;
if (self.x < 100 || self.x > 1948) {
self.direction *= -1;
}
if (self.y < -100) {
LK.setScore(LK.getScore() - 1);
scoreTxt.setText(LK.getScore());
if (LK.getScore() <= 0) {
game.end();
return;
}
self.y = 2732 + 100;
self.x = Math.random() * 2048;
}
};
self.down = function (x, y, obj) {
LK.getSound('pop').play();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
var index = balloons.indexOf(self);
if (index > -1) {
balloons.splice(index, 1);
}
self.destroy();
};
});
// Balloon2 class for new balloon type
var Balloon2 = Container.expand(function () {
var self = Container.call(this);
// Randomly choose a color for the balloon
var colors = [0xff5555, 0x55ff55, 0x5555ff, 0xffff55, 0xff55ff, 0x55ffff];
var color = colors[Math.floor(Math.random() * colors.length)];
self.attachAsset('balloon2', {
tint: color,
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 2;
self.direction = (Math.random() - 0.5) * 2;
self.update = function () {
self.y -= self.speed;
self.x += self.direction;
if (self.x < 100 || self.x > 1948) {
self.direction *= -1;
}
if (self.y < -100) {
LK.setScore(LK.getScore() - 2);
scoreTxt.setText(LK.getScore());
if (LK.getScore() <= 0) {
game.end();
return;
}
self.y = 2732 + 100;
self.x = Math.random() * 2048;
}
};
self.down = function (x, y, obj) {
LK.getSound('pop').play();
LK.setScore(LK.getScore() + 2);
scoreTxt.setText(LK.getScore());
var index = balloons.indexOf(self);
if (index > -1) {
balloons.splice(index, 1);
}
self.destroy();
};
});
// Cloud class
var Cloud = Container.expand(function () {
var self = Container.call(this);
self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
self.speed = Math.random() * 0.5 + 0.2;
self.update = function () {
self.x -= self.speed;
if (self.x < -300) {
self.x = 2048 + 300;
self.y = Math.random() * 2732;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Arrays and counters
var balloons = [];
var clouds = [];
var balloon2Counter = 0;
// Create functions
function createCloud() {
var newCloud = new Cloud();
clouds.push(newCloud);
game.addChild(newCloud);
}
function createBalloon() {
var newBalloon;
if (balloon2Counter >= 10) {
newBalloon = new Balloon2();
balloon2Counter = 0;
} else {
newBalloon = new Balloon();
balloon2Counter++;
}
newBalloon.x = Math.random() * 2048;
newBalloon.y = 2732 + 100;
balloons.push(newBalloon);
game.addChild(newBalloon);
}
// Create initial objects
for (var i = 0; i < 5; i++) {
createCloud();
}
for (var i = 0; i < 10; i++) {
createBalloon();
}
// Game update function
game.update = function () {
for (var i = clouds.length - 1; i >= 0; i--) {
clouds[i].update();
}
for (var i = balloons.length - 1; i >= 0; i--) {
balloons[i].update();
}
if (LK.ticks % 60 == 0) {
createBalloon();
}
};
// Game input handler
game.down = function (x, y, obj) {
for (var i = balloons.length - 1; i >= 0; i--) {
if (balloons[i].intersects(obj)) {
balloons[i].down(x, y, obj);
break;
}
}
};
// Difficulty scaling
var difficulty = 1;
LK.setInterval(function () {
difficulty += 0.5;
balloons.forEach(function (balloon) {
balloon.speed += 0.1;
});
}, 10000);
// Game over handling
game.end = function () {
// Remove all balloons
for (var i = balloons.length - 1; i >= 0; i--) {
balloons[i].destroy();
}
balloons = [];
// Remove all clouds
for (var i = clouds.length - 1; i >= 0; i--) {
clouds[i].destroy();
}
clouds = [];
// Clear score text
if (scoreTxt && scoreTxt.parent) {
scoreTxt.parent.removeChild(scoreTxt);
}
// Create game over text
var gameOverTxt = new Text2('Game Over! Score: ' + LK.getScore(), {
size: 150,
fill: 0xFFFFFF
});
gameOverTxt.anchor.set(0.5, 0.5);
game.addChild(gameOverTxt);
};