/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Fruit class to represent each fruit coming from the right side var Fruit = Container.expand(function () { var self = Container.call(this); // Attach a fruit asset, assuming a generic fruit shape is available var fruitGraphics = self.attachAsset('fruit', { anchorX: 0.5, anchorY: 0.5 }); // Set initial speed for the fruit self.speed = -3; // Update function to move the fruit leftwards self.update = function () { self.x += self.speed; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize variables var fruits = []; var fruitCount = 0; var maxFruits = 10000; // Function to handle game updates game.update = function () { // Create new fruits at regular intervals if (LK.ticks % 30 == 0 && fruitCount < maxFruits) { var newFruit = new Fruit(); newFruit.x = 2048; // Start from the right side newFruit.y = Math.random() * 2732; // Random y position fruits.push(newFruit); game.addChild(newFruit); fruitCount++; } // Update each fruit's position for (var i = fruits.length - 1; i >= 0; i--) { fruits[i].update(); // Remove fruits that have moved off the left side of the screen if (fruits[i].x < -50) { fruits[i].destroy(); fruits.splice(i, 1); } } // End the game after 10000 fruits have appeared if (fruitCount >= maxFruits && fruits.length === 0) { LK.showGameOver(); } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Fruit class to represent each fruit coming from the right side
var Fruit = Container.expand(function () {
var self = Container.call(this);
// Attach a fruit asset, assuming a generic fruit shape is available
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial speed for the fruit
self.speed = -3;
// Update function to move the fruit leftwards
self.update = function () {
self.x += self.speed;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Initialize variables
var fruits = [];
var fruitCount = 0;
var maxFruits = 10000;
// Function to handle game updates
game.update = function () {
// Create new fruits at regular intervals
if (LK.ticks % 30 == 0 && fruitCount < maxFruits) {
var newFruit = new Fruit();
newFruit.x = 2048; // Start from the right side
newFruit.y = Math.random() * 2732; // Random y position
fruits.push(newFruit);
game.addChild(newFruit);
fruitCount++;
}
// Update each fruit's position
for (var i = fruits.length - 1; i >= 0; i--) {
fruits[i].update();
// Remove fruits that have moved off the left side of the screen
if (fruits[i].x < -50) {
fruits[i].destroy();
fruits.splice(i, 1);
}
}
// End the game after 10000 fruits have appeared
if (fruitCount >= maxFruits && fruits.length === 0) {
LK.showGameOver();
}
};