/**** * Classes ****/ // Assets will be automatically created and loaded by the LK engine based on their usage in the code. // Planet class representing a planet that can be tapped to explode var Planet = Container.expand(function () { var self = Container.call(this); var planetGraphics = self.attachAsset('planet', { anchorX: 0.5, anchorY: 0.5 }); // Randomize initial position self.x = Math.random() * 2048; self.y = Math.random() * 2732; // Event handler for when the planet is tapped self.down = function (x, y, obj) { // Trigger explosion effect LK.effects.flashObject(self, 0xff0000, 500); // Increase score LK.setScore(LK.getScore() + 1); // Update score text scoreTxt.setText(LK.getScore()); // Destroy the planet self.destroy(); }; // Update function called every game tick self.update = function () { // Move the planet downwards self.y += 2; // Reset position if it goes off screen if (self.y > 2732) { self.y = -self.height; self.x = Math.random() * 2048; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize score text var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Array to keep track of planets var planets = []; // Function to create a new planet function createPlanet() { var newPlanet = new Planet(); planets.push(newPlanet); game.addChild(newPlanet); } // Create initial planets for (var i = 0; i < 5; i++) { createPlanet(); } // Game update function game.update = function () { // Update all planets for (var i = planets.length - 1; i >= 0; i--) { planets[i].update(); } // Add new planet every 60 ticks if (LK.ticks % 60 == 0) { createPlanet(); } }; // Handle game over when score reaches a certain threshold function checkGameOver() { if (LK.getScore() >= 50) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Set interval to check for game over condition LK.setInterval(checkGameOver, 1000);
/****
* Classes
****/
// Assets will be automatically created and loaded by the LK engine based on their usage in the code.
// Planet class representing a planet that can be tapped to explode
var Planet = Container.expand(function () {
var self = Container.call(this);
var planetGraphics = self.attachAsset('planet', {
anchorX: 0.5,
anchorY: 0.5
});
// Randomize initial position
self.x = Math.random() * 2048;
self.y = Math.random() * 2732;
// Event handler for when the planet is tapped
self.down = function (x, y, obj) {
// Trigger explosion effect
LK.effects.flashObject(self, 0xff0000, 500);
// Increase score
LK.setScore(LK.getScore() + 1);
// Update score text
scoreTxt.setText(LK.getScore());
// Destroy the planet
self.destroy();
};
// Update function called every game tick
self.update = function () {
// Move the planet downwards
self.y += 2;
// Reset position if it goes off screen
if (self.y > 2732) {
self.y = -self.height;
self.x = Math.random() * 2048;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to keep track of planets
var planets = [];
// Function to create a new planet
function createPlanet() {
var newPlanet = new Planet();
planets.push(newPlanet);
game.addChild(newPlanet);
}
// Create initial planets
for (var i = 0; i < 5; i++) {
createPlanet();
}
// Game update function
game.update = function () {
// Update all planets
for (var i = planets.length - 1; i >= 0; i--) {
planets[i].update();
}
// Add new planet every 60 ticks
if (LK.ticks % 60 == 0) {
createPlanet();
}
};
// Handle game over when score reaches a certain threshold
function checkGameOver() {
if (LK.getScore() >= 50) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
}
}
// Set interval to check for game over condition
LK.setInterval(checkGameOver, 1000);