/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var Animal = Container.expand(function (type, speed, points) { var self = Container.call(this); // Set properties self.type = type; self.speed = speed || 3; self.points = points || 1; self.isActive = true; // Define assets based on animal type var assetId, size; switch (type) { case 'elephant': assetId = 'elephant'; size = 200; self.points = 1; self.speed = 2; break; case 'monkey': assetId = 'monkey'; size = 150; self.points = 2; self.speed = 3; break; case 'rabbit': assetId = 'rabbit'; size = 120; self.points = 3; self.speed = 4; break; case 'fox': assetId = 'fox'; size = 100; self.points = 5; self.speed = 5; break; case 'mouse': assetId = 'mouse'; size = 80; self.points = 10; self.speed = 6; break; case 'golden': assetId = 'golden'; size = 100; self.points = 25; self.speed = 7; break; } // Create and attach the animal graphic self.graphic = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); // Initial position - will be set by the game self.velocity = { x: (Math.random() - 0.5) * self.speed, y: -self.speed - Math.random() * 2 }; // Assign interaction handlers self.down = function (x, y, obj) { if (!self.isActive) return; // Pop animation tween(self.graphic, { scaleX: 0.1, scaleY: 0.1, alpha: 0 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { // Play appropriate sound effect if (self.type === 'golden') { LK.getSound('goldenPop').play(); } else { LK.getSound('pop').play(); } // Update score and remove from game LK.setScore(LK.getScore() + self.points); self.isActive = false; // Signal to game that this animal was popped if (typeof self.onPopped === 'function') { self.onPopped(self); } } }); }; // Update method called by the game each frame self.update = function () { if (!self.isActive) return; // Update position self.x += self.velocity.x; self.y += self.velocity.y; // Simple boundary checking - bounce off walls if (self.x < self.graphic.width / 2) { self.x = self.graphic.width / 2; self.velocity.x *= -1; } else if (self.x > 2048 - self.graphic.width / 2) { self.x = 2048 - self.graphic.width / 2; self.velocity.x *= -1; } // Check if animal has gone off the top if (self.y < -self.graphic.height) { self.isActive = false; if (typeof self.onMissed === 'function') { self.onMissed(self); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game variables var animals = []; var gameTime = 60; // 60 seconds game time var timeRemaining = gameTime; var timer = null; var spawnInterval = null; var difficultyInterval = null; var spawnRate = 1500; // milliseconds between spawns var maxAnimalsOnScreen = 8; var gamePaused = false; var gameRunning = false; var highScore = storage.highScore || 0; // Create UI elements var scoreText = new Text2('Score: 0', { size: 70, fill: 0xFFFFFF }); scoreText.anchor.set(0, 0); LK.gui.topRight.addChild(scoreText); scoreText.x = -scoreText.width - 20; scoreText.y = 20; var timeText = new Text2('Time: 60', { size: 70, fill: 0xFFFFFF }); timeText.anchor.set(0, 0); LK.gui.topLeft.addChild(timeText); timeText.x = 120; // Keep away from the menu icon timeText.y = 20; var highScoreText = new Text2('High Score: ' + highScore, { size: 50, fill: 0xFFFFFF }); highScoreText.anchor.set(0.5, 0); LK.gui.top.addChild(highScoreText); highScoreText.y = 20; // Create timer bar var timerBarBackground = LK.getAsset('timerBg', { anchorX: 0, anchorY: 0 }); var timerBar = LK.getAsset('timerBar', { anchorX: 0, anchorY: 0 }); LK.gui.top.addChild(timerBarBackground); LK.gui.top.addChild(timerBar); timerBarBackground.x = (2048 - timerBarBackground.width) / 2; timerBarBackground.y = 100; timerBar.x = timerBarBackground.x; timerBar.y = timerBarBackground.y; // Start screen message var startText = new Text2('Tap to Start!', { size: 100, fill: 0xFFFFFF }); startText.anchor.set(0.5, 0.5); LK.gui.center.addChild(startText); // Game instructions var instructionsText = new Text2('Pop the animal balloons!\nSmaller animals = More points', { size: 60, fill: 0xFFFFFF }); instructionsText.anchor.set(0.5, 0.5); LK.gui.center.addChild(instructionsText); instructionsText.y = 150; // Function to update UI function updateUI() { scoreText.setText('Score: ' + LK.getScore()); timeText.setText('Time: ' + Math.ceil(timeRemaining)); // Update timer bar var ratio = timeRemaining / gameTime; timerBar.width = timerBarBackground.width * ratio; // Change color as time runs out if (ratio <= 0.2) { timerBar.tint = 0xFF0000; // Red when almost out of time } else if (ratio <= 0.5) { timerBar.tint = 0xFFFF00; // Yellow when half time } else { timerBar.tint = 0x00FF00; // Green otherwise } } // Function to spawn a new animal function spawnAnimal() { if (!gameRunning || animals.length >= maxAnimalsOnScreen) return; // Determine animal type based on random chance with weights var rand = Math.random(); var type; if (rand < 0.01) { // 1% chance for golden (special) type = 'golden'; } else if (rand < 0.1) { // 9% chance for mouse (smallest, fastest) type = 'mouse'; } else if (rand < 0.25) { // 15% chance for fox type = 'fox'; } else if (rand < 0.5) { // 25% chance for rabbit type = 'rabbit'; } else if (rand < 0.8) { // 30% chance for monkey type = 'monkey'; } else { // 20% chance for elephant (largest, slowest) type = 'elephant'; } var animal = new Animal(type); // Set position - start from bottom of screen animal.x = Math.random() * (2048 - animal.graphic.width) + animal.graphic.width / 2; animal.y = 2732 + animal.graphic.height / 2; // Event handlers animal.onPopped = function (sender) { // Find and remove from array var index = animals.indexOf(sender); if (index !== -1) { animals.splice(index, 1); } // Remove from display after a short delay LK.setTimeout(function () { game.removeChild(sender); }, 300); }; animal.onMissed = function (sender) { // Find and remove from array var index = animals.indexOf(sender); if (index !== -1) { animals.splice(index, 1); } // Remove from display game.removeChild(sender); }; // Add to game and array game.addChild(animal); animals.push(animal); } // Function to increase game difficulty function increaseDifficulty() { if (!gameRunning) return; // Increase spawn rate and max animals on screen as game progresses spawnRate = Math.max(500, spawnRate - 100); // Faster spawning maxAnimalsOnScreen = Math.min(15, maxAnimalsOnScreen + 1); // More animals // Update spawn interval with new rate if (spawnInterval) { LK.clearInterval(spawnInterval); } spawnInterval = LK.setInterval(spawnAnimal, spawnRate); } // Function to start the game function startGame() { // Hide start screen elements startText.visible = false; instructionsText.visible = false; // Reset game variables timeRemaining = gameTime; LK.setScore(0); animals = []; gameRunning = true; // Play game music LK.playMusic('gameMusic'); // Clear any existing intervals if (timer) LK.clearInterval(timer); if (spawnInterval) LK.clearInterval(spawnInterval); if (difficultyInterval) LK.clearInterval(difficultyInterval); // Set up timer timer = LK.setInterval(function () { timeRemaining -= 0.1; // Decrease time in tenths of a second for smoother timer updateUI(); if (timeRemaining <= 0) { endGame(); } }, 100); // Set up animal spawning spawnRate = 1500; maxAnimalsOnScreen = 8; spawnInterval = LK.setInterval(spawnAnimal, spawnRate); // Set up difficulty increase difficultyInterval = LK.setInterval(increaseDifficulty, 10000); // Increase difficulty every 10 seconds // Update UI updateUI(); } // Function to end the game function endGame() { gameRunning = false; // Clear intervals if (timer) LK.clearInterval(timer); if (spawnInterval) LK.clearInterval(spawnInterval); if (difficultyInterval) LK.clearInterval(difficultyInterval); // Play game over sound LK.getSound('gameover').play(); // Stop music LK.stopMusic(); // Update high score if needed if (LK.getScore() > highScore) { highScore = LK.getScore(); storage.highScore = highScore; } // Show game over screen LK.showGameOver(); } // Game update function (called every frame) game.update = function () { if (!gameRunning) return; // Update all animals for (var i = animals.length - 1; i >= 0; i--) { animals[i].update(); } }; // Game input events game.down = function (x, y, obj) { if (!gameRunning && startText.visible) { startGame(); } }; // Initialize the game updateUI();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Animal = Container.expand(function (type, speed, points) {
var self = Container.call(this);
// Set properties
self.type = type;
self.speed = speed || 3;
self.points = points || 1;
self.isActive = true;
// Define assets based on animal type
var assetId, size;
switch (type) {
case 'elephant':
assetId = 'elephant';
size = 200;
self.points = 1;
self.speed = 2;
break;
case 'monkey':
assetId = 'monkey';
size = 150;
self.points = 2;
self.speed = 3;
break;
case 'rabbit':
assetId = 'rabbit';
size = 120;
self.points = 3;
self.speed = 4;
break;
case 'fox':
assetId = 'fox';
size = 100;
self.points = 5;
self.speed = 5;
break;
case 'mouse':
assetId = 'mouse';
size = 80;
self.points = 10;
self.speed = 6;
break;
case 'golden':
assetId = 'golden';
size = 100;
self.points = 25;
self.speed = 7;
break;
}
// Create and attach the animal graphic
self.graphic = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
// Initial position - will be set by the game
self.velocity = {
x: (Math.random() - 0.5) * self.speed,
y: -self.speed - Math.random() * 2
};
// Assign interaction handlers
self.down = function (x, y, obj) {
if (!self.isActive) return;
// Pop animation
tween(self.graphic, {
scaleX: 0.1,
scaleY: 0.1,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Play appropriate sound effect
if (self.type === 'golden') {
LK.getSound('goldenPop').play();
} else {
LK.getSound('pop').play();
}
// Update score and remove from game
LK.setScore(LK.getScore() + self.points);
self.isActive = false;
// Signal to game that this animal was popped
if (typeof self.onPopped === 'function') {
self.onPopped(self);
}
}
});
};
// Update method called by the game each frame
self.update = function () {
if (!self.isActive) return;
// Update position
self.x += self.velocity.x;
self.y += self.velocity.y;
// Simple boundary checking - bounce off walls
if (self.x < self.graphic.width / 2) {
self.x = self.graphic.width / 2;
self.velocity.x *= -1;
} else if (self.x > 2048 - self.graphic.width / 2) {
self.x = 2048 - self.graphic.width / 2;
self.velocity.x *= -1;
}
// Check if animal has gone off the top
if (self.y < -self.graphic.height) {
self.isActive = false;
if (typeof self.onMissed === 'function') {
self.onMissed(self);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Game variables
var animals = [];
var gameTime = 60; // 60 seconds game time
var timeRemaining = gameTime;
var timer = null;
var spawnInterval = null;
var difficultyInterval = null;
var spawnRate = 1500; // milliseconds between spawns
var maxAnimalsOnScreen = 8;
var gamePaused = false;
var gameRunning = false;
var highScore = storage.highScore || 0;
// Create UI elements
var scoreText = new Text2('Score: 0', {
size: 70,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreText);
scoreText.x = -scoreText.width - 20;
scoreText.y = 20;
var timeText = new Text2('Time: 60', {
size: 70,
fill: 0xFFFFFF
});
timeText.anchor.set(0, 0);
LK.gui.topLeft.addChild(timeText);
timeText.x = 120; // Keep away from the menu icon
timeText.y = 20;
var highScoreText = new Text2('High Score: ' + highScore, {
size: 50,
fill: 0xFFFFFF
});
highScoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(highScoreText);
highScoreText.y = 20;
// Create timer bar
var timerBarBackground = LK.getAsset('timerBg', {
anchorX: 0,
anchorY: 0
});
var timerBar = LK.getAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
LK.gui.top.addChild(timerBarBackground);
LK.gui.top.addChild(timerBar);
timerBarBackground.x = (2048 - timerBarBackground.width) / 2;
timerBarBackground.y = 100;
timerBar.x = timerBarBackground.x;
timerBar.y = timerBarBackground.y;
// Start screen message
var startText = new Text2('Tap to Start!', {
size: 100,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(startText);
// Game instructions
var instructionsText = new Text2('Pop the animal balloons!\nSmaller animals = More points', {
size: 60,
fill: 0xFFFFFF
});
instructionsText.anchor.set(0.5, 0.5);
LK.gui.center.addChild(instructionsText);
instructionsText.y = 150;
// Function to update UI
function updateUI() {
scoreText.setText('Score: ' + LK.getScore());
timeText.setText('Time: ' + Math.ceil(timeRemaining));
// Update timer bar
var ratio = timeRemaining / gameTime;
timerBar.width = timerBarBackground.width * ratio;
// Change color as time runs out
if (ratio <= 0.2) {
timerBar.tint = 0xFF0000; // Red when almost out of time
} else if (ratio <= 0.5) {
timerBar.tint = 0xFFFF00; // Yellow when half time
} else {
timerBar.tint = 0x00FF00; // Green otherwise
}
}
// Function to spawn a new animal
function spawnAnimal() {
if (!gameRunning || animals.length >= maxAnimalsOnScreen) return;
// Determine animal type based on random chance with weights
var rand = Math.random();
var type;
if (rand < 0.01) {
// 1% chance for golden (special)
type = 'golden';
} else if (rand < 0.1) {
// 9% chance for mouse (smallest, fastest)
type = 'mouse';
} else if (rand < 0.25) {
// 15% chance for fox
type = 'fox';
} else if (rand < 0.5) {
// 25% chance for rabbit
type = 'rabbit';
} else if (rand < 0.8) {
// 30% chance for monkey
type = 'monkey';
} else {
// 20% chance for elephant (largest, slowest)
type = 'elephant';
}
var animal = new Animal(type);
// Set position - start from bottom of screen
animal.x = Math.random() * (2048 - animal.graphic.width) + animal.graphic.width / 2;
animal.y = 2732 + animal.graphic.height / 2;
// Event handlers
animal.onPopped = function (sender) {
// Find and remove from array
var index = animals.indexOf(sender);
if (index !== -1) {
animals.splice(index, 1);
}
// Remove from display after a short delay
LK.setTimeout(function () {
game.removeChild(sender);
}, 300);
};
animal.onMissed = function (sender) {
// Find and remove from array
var index = animals.indexOf(sender);
if (index !== -1) {
animals.splice(index, 1);
}
// Remove from display
game.removeChild(sender);
};
// Add to game and array
game.addChild(animal);
animals.push(animal);
}
// Function to increase game difficulty
function increaseDifficulty() {
if (!gameRunning) return;
// Increase spawn rate and max animals on screen as game progresses
spawnRate = Math.max(500, spawnRate - 100); // Faster spawning
maxAnimalsOnScreen = Math.min(15, maxAnimalsOnScreen + 1); // More animals
// Update spawn interval with new rate
if (spawnInterval) {
LK.clearInterval(spawnInterval);
}
spawnInterval = LK.setInterval(spawnAnimal, spawnRate);
}
// Function to start the game
function startGame() {
// Hide start screen elements
startText.visible = false;
instructionsText.visible = false;
// Reset game variables
timeRemaining = gameTime;
LK.setScore(0);
animals = [];
gameRunning = true;
// Play game music
LK.playMusic('gameMusic');
// Clear any existing intervals
if (timer) LK.clearInterval(timer);
if (spawnInterval) LK.clearInterval(spawnInterval);
if (difficultyInterval) LK.clearInterval(difficultyInterval);
// Set up timer
timer = LK.setInterval(function () {
timeRemaining -= 0.1; // Decrease time in tenths of a second for smoother timer
updateUI();
if (timeRemaining <= 0) {
endGame();
}
}, 100);
// Set up animal spawning
spawnRate = 1500;
maxAnimalsOnScreen = 8;
spawnInterval = LK.setInterval(spawnAnimal, spawnRate);
// Set up difficulty increase
difficultyInterval = LK.setInterval(increaseDifficulty, 10000); // Increase difficulty every 10 seconds
// Update UI
updateUI();
}
// Function to end the game
function endGame() {
gameRunning = false;
// Clear intervals
if (timer) LK.clearInterval(timer);
if (spawnInterval) LK.clearInterval(spawnInterval);
if (difficultyInterval) LK.clearInterval(difficultyInterval);
// Play game over sound
LK.getSound('gameover').play();
// Stop music
LK.stopMusic();
// Update high score if needed
if (LK.getScore() > highScore) {
highScore = LK.getScore();
storage.highScore = highScore;
}
// Show game over screen
LK.showGameOver();
}
// Game update function (called every frame)
game.update = function () {
if (!gameRunning) return;
// Update all animals
for (var i = animals.length - 1; i >= 0; i--) {
animals[i].update();
}
};
// Game input events
game.down = function (x, y, obj) {
if (!gameRunning && startText.visible) {
startGame();
}
};
// Initialize the game
updateUI();
rabbit . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
mouse. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
fox. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
golden. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
monkey. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
elephanth. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
timebar. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat