/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Basket = Container.expand(function () { var self = Container.call(this); var basketGraphics = self.attachAsset('basket', { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 1.5 }); self.width = basketGraphics.width * 2; self.height = basketGraphics.height * 1.5; self.down = function (x, y, obj) { self.dragging = true; }; self.up = function (x, y, obj) { self.dragging = false; }; return self; }); var Fruit = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'apple'; self.speed = 3 + Math.random() * 2; self.value = 10; if (self.type === 'banana') { self.value = 15; self.speed += 1; } else if (self.type === 'orange') { self.value = 20; self.speed += 2; } else if (self.type === 'goldenApple') { self.value = 50; self.speed += 3; } else if (self.type === 'rottenFruit') { self.value = -20; self.speed += 1; } else if (self.type === 'bomb') { self.value = -1; // Special value for bomb self.speed += 2; } else if (self.type === 'lemon') { self.value = 25; self.speed += 1.5; } var fruitGraphics = self.attachAsset(self.type, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y += self.speed * gameSpeed; // Add some swinging motion for realistic falling self.x += Math.sin(LK.ticks / 20 + self.y / 100) * 1; // Add slight rotation fruitGraphics.rotation += 0.01; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ var basket; var fruits = []; var score = 0; var lives = 3; var gameSpeed = 1; var fruitTypes = ['apple', 'banana', 'orange', 'rottenFruit', 'goldenApple', 'bomb', 'lemon']; var fruitSpawnRate = 60; // Frames between fruit spawns var lastFruitSpawn = 0; var speedIncreaseInterval = 1000; // Frames between speed increases var isPaused = false; var isGameOver = false; var dragNode = null; var rottenFruitHits = 0; // Counter for rotten fruit hits var isHallucinating = false; // Flag to track hallucination state var hallucinationEndTime = 0; // Time when hallucination effect should end // UI elements var scoreTxt, livesTxt, gameSpeedTxt; // Initialize game function initGame() { // Create basket basket = new Basket(); basket.x = 2048 / 2; basket.y = 2732 - 200; game.addChild(basket); // Initialize score display scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); // Initialize lives display livesTxt = new Text2('Lives: ' + lives, { size: 80, fill: 0xFFFFFF }); livesTxt.anchor.set(0, 0); LK.gui.top.addChild(livesTxt); // Initialize game speed display gameSpeedTxt = new Text2('Speed: 1.0x', { size: 60, fill: 0xFFFFFF }); gameSpeedTxt.anchor.set(1, 0); LK.gui.bottomRight.addChild(gameSpeedTxt); // Play background music LK.playMusic('gameMusic', { fade: { start: 0, end: 0.4, duration: 1000 } }); // Initialize stored high score if needed if (!storage.highScore) { storage.highScore = 0; } } // Spawn a new fruit function spawnFruit() { var randomType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)]; // Adjust probabilities for special items if (randomType === 'goldenApple' && Math.random() < 0.8) { randomType = fruitTypes[Math.floor(Math.random() * 3)]; // More likely to be a common fruit } if (randomType === 'bomb' && Math.random() < 0.7) { randomType = fruitTypes[Math.floor(Math.random() * 3)]; // More likely to be a common fruit } var fruit = new Fruit(randomType); fruit.x = Math.random() * (2048 - 100) + 50; // Random position fruit.y = -50; // Start above the screen game.addChild(fruit); fruits.push(fruit); } // Update score display function updateScore(points) { score += points; LK.setScore(score); scoreTxt.setText('Score: ' + score); // Check if we have a new high score if (score > storage.highScore) { storage.highScore = score; } } // Handle fruit catching and collisions function checkCollisions() { for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; // Check if fruit is below the screen (missed) if (fruit.y > 2732 + 50) { fruit.destroy(); fruits.splice(i, 1); continue; } // Check collision with basket if (fruit.intersects(basket)) { // Handle different fruit types if (fruit.type === 'bomb') { // Bomb - lose a life lives--; livesTxt.setText('Lives: ' + lives); LK.getSound('explosion').play(); LK.effects.flashScreen(0xFF0000, 500); if (lives <= 0) { gameOver(); } } else if (fruit.type === 'goldenApple') { // Golden apple - bonus points and speed boost updateScore(fruit.value); gameSpeed += 0.1; gameSpeedTxt.setText('Speed: ' + gameSpeed.toFixed(1) + 'x'); LK.getSound('powerup').play(); } else if (fruit.type === 'rottenFruit') { // Rotten fruit - lose points and 0.5 lives updateScore(fruit.value); lives -= 0.5; livesTxt.setText('Lives: ' + lives); LK.getSound('loseLife').play(); // Increment rotten fruit hit counter rottenFruitHits++; // If player has been hit by rotten fruit twice, trigger hallucination if (rottenFruitHits >= 2 && !isHallucinating) { startHallucination(); } // Check if player has lost all lives if (lives <= 0) { gameOver(); } } else { // Regular fruit - add points updateScore(fruit.value); LK.getSound('catch').play(); } // Remove caught fruit fruit.destroy(); fruits.splice(i, 1); // Visual feedback if (fruit.type !== 'bomb') { LK.effects.flashObject(basket, 0x00FF00, 200); } } } } // Start hallucination effect function startHallucination() { isHallucinating = true; hallucinationEndTime = LK.ticks + 300; // Hallucination lasts for 5 seconds (300 frames at 60fps) // Apply visual effects to show hallucination LK.effects.flashScreen(0xFF00FF, 500); // Flash purple // Inform player var hallucinationText = new Text2('HALLUCINATING!', { size: 120, fill: 0xFF00FF }); hallucinationText.anchor.set(0.5, 0.5); hallucinationText.x = 2048 / 2; hallucinationText.y = 2732 / 2; game.addChild(hallucinationText); // Remove the text after a delay LK.setTimeout(function () { hallucinationText.destroy(); }, 2000); // Reset counter after triggering rottenFruitHits = 0; } // Game over function function gameOver() { isGameOver = true; LK.showGameOver(); } // Handle dragging the basket function handleMove(x, y, obj) { if (dragNode === basket) { basket.x = x; // Keep basket within screen bounds if (basket.x < basket.width / 2) { basket.x = basket.width / 2; } else if (basket.x > 2048 - basket.width / 2) { basket.x = 2048 - basket.width / 2; } } } // Set up event handlers game.down = function (x, y, obj) { dragNode = basket; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; game.move = handleMove; // Main game update function game.update = function () { if (isGameOver) return; // Handle hallucination effect if (isHallucinating) { // Apply visual distortion effects during hallucination if (LK.ticks % 5 === 0) { // Every few frames // Make the basket move slightly in random directions basket.x += (Math.random() - 0.5) * 20; // Keep basket within screen bounds if (basket.x < basket.width / 2) { basket.x = basket.width / 2; } else if (basket.x > 2048 - basket.width / 2) { basket.x = 2048 - basket.width / 2; } // Make fruits appear to wobble more for (var i = 0; i < fruits.length; i++) { fruits[i].x += (Math.random() - 0.5) * 15; } } // End hallucination after the duration if (LK.ticks >= hallucinationEndTime) { isHallucinating = false; LK.effects.flashScreen(0x00FF00, 300); // Flash green to indicate end of hallucination } } // Spawn new fruits if (LK.ticks - lastFruitSpawn > fruitSpawnRate) { spawnFruit(); lastFruitSpawn = LK.ticks; // Gradually decrease spawn rate for increasing difficulty if (fruitSpawnRate > 20) { fruitSpawnRate -= 0.1; } } // Increase game speed over time if (LK.ticks % speedIncreaseInterval === 0) { gameSpeed += 0.005; gameSpeedTxt.setText('Speed: ' + gameSpeed.toFixed(1) + 'x'); } // Update all fruits for (var i = 0; i < fruits.length; i++) { fruits[i].update(); } // Check for catches and misses checkCollisions(); }; // Initialize the game initGame();
===================================================================
--- original.js
+++ change.js
@@ -44,8 +44,11 @@
self.speed += 1;
} else if (self.type === 'bomb') {
self.value = -1; // Special value for bomb
self.speed += 2;
+ } else if (self.type === 'lemon') {
+ self.value = 25;
+ self.speed += 1.5;
}
var fruitGraphics = self.attachAsset(self.type, {
anchorX: 0.5,
anchorY: 0.5
@@ -74,9 +77,9 @@
var fruits = [];
var score = 0;
var lives = 3;
var gameSpeed = 1;
-var fruitTypes = ['apple', 'banana', 'orange', 'rottenFruit', 'goldenApple', 'bomb'];
+var fruitTypes = ['apple', 'banana', 'orange', 'rottenFruit', 'goldenApple', 'bomb', 'lemon'];
var fruitSpawnRate = 60; // Frames between fruit spawns
var lastFruitSpawn = 0;
var speedIncreaseInterval = 1000; // Frames between speed increases
var isPaused = false;
a pixel art of a basket. In-Game asset. 2d. High contrast. No shadows
pixel art of a rotten apple. In-Game asset. 2d. High contrast. No shadows
pixel art of an apple. In-Game asset. 2d. High contrast. No shadows
pixel art of a apple but golden. In-Game asset. 2d. High contrast. No shadows
pixel art of a lemon. In-Game asset. 2d. High contrast. No shadows
pixel art of a orange. In-Game asset. 2d. High contrast. No shadows
a pixel art of a banana. In-Game asset. 2d. High contrast. No shadows
a pixel art of a bomb. In-Game asset. 2d. High contrast. No shadows