User prompt
Suggestions
User prompt
Save source code
User prompt
Update the score text gui in the Centre of the screen once game over
User prompt
Display game score as final score at the game over screen after game finishes
User prompt
Display final score at game over screen
User prompt
Save final score at game ends ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Deduct 2 points every time you hit a predator
User prompt
Fix scoring system
User prompt
Deduct 5 points when hit by predators
User prompt
Fix final score tally to show correct score when game ends
User prompt
Why is final score showing 0 after game ends?
User prompt
Show final score at game over screen
User prompt
Make sure score is reflected in final score at games end
User prompt
Make title disappear when game starts
User prompt
Add game title at start of game
User prompt
Make score text larger
User prompt
Make text bolder and thicker
User prompt
Create title screen with instructions
User prompt
Fix errors, clean up code
User prompt
Add title screen
User prompt
Show instructions before game please
User prompt
Centre instructions to fit screen
User prompt
Make text bold and larger
User prompt
Change text colour to black
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScores: [] }); /**** * Classes ****/ var Food = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'insect'; self.value = self.type === 'insect' ? 5 : 10; // Shrimp gives more energy var graphic = self.attachAsset(self.type, { anchorX: 0.5, anchorY: 0.5 }); // Random movement self.speedX = (Math.random() - 0.5) * 2; self.speedY = (Math.random() - 0.5) * 2; self.update = function () { self.x += self.speedX; self.y += self.speedY; // Bounce off edges if (self.x < 50 || self.x > 2048 - 50) { self.speedX *= -1; } if (self.y < 50 || self.y > 2732 - 50) { self.speedY *= -1; } }; return self; }); var HideSpot = Container.expand(function () { var self = Container.call(this); var graphic = self.attachAsset('hideSpot', { anchorX: 0.5, anchorY: 0.5, alpha: 0.7 }); return self; }); var Platypus = Container.expand(function () { var self = Container.call(this); // Create platypus body var body = self.attachAsset('platypus', { anchorX: 0.5, anchorY: 0.5 }); // Platypus properties self.speed = 8; self.energy = 100; self.maxEnergy = 100; self.hidden = false; self.invulnerable = false; // Movement target for smooth motion self.targetX = 0; self.targetY = 0; self.update = function () { // Move towards target position smoothly if (Math.abs(self.x - self.targetX) > 5 || Math.abs(self.y - self.targetY) > 5) { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * self.speed; self.y += Math.sin(angle) * self.speed; // Rotate platypus to face movement direction self.rotation = angle; } // Decrease energy over time if (LK.ticks % 60 === 0 && !self.hidden) { self.energy -= 1; if (self.energy <= 0) { self.energy = 0; // Update high score list var highScores = storage.highScores; highScores.push(score); highScores.sort(function (a, b) { return b - a; }); if (highScores.length > 5) { highScores.pop(); // Keep only top 5 scores } storage.highScores = highScores; // Update high score list var highScores = storage.highScores; highScores.push(score); highScores.sort(function (a, b) { return b - a; }); if (highScores.length > 5) { highScores.pop(); // Keep only top 5 scores } storage.highScores = highScores; scoreTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(scoreTxt); scoreTxt.y = 0; // Update high score list var highScores = storage.highScores; highScores.push(score); highScores.sort(function (a, b) { return b - a; }); if (highScores.length > 5) { highScores.pop(); // Keep only top 5 scores } storage.highScores = highScores; LK.showGameOver(); } } }; self.hide = function () { if (!self.hidden) { self.hidden = true; LK.getSound('hide').play(); tween(self, { alpha: 0.3 }, { duration: 300 }); } }; self.unhide = function () { if (self.hidden) { self.hidden = true; tween(self, { alpha: 1 }, { duration: 300, onFinish: function onFinish() { self.hidden = false; } }); } }; self.makeInvulnerable = function (duration) { self.invulnerable = true; // Flash effect to show invulnerability var flashCount = 0; var flashInterval = LK.setInterval(function () { body.alpha = body.alpha === 1 ? 0.3 : 1; // Removed reference to undefined 'bill' flashCount++; if (flashCount >= 10) { LK.clearInterval(flashInterval); body.alpha = 1; self.invulnerable = false; } }, 150); }; self.takeDamage = function (amount) { if (!self.invulnerable && !self.hidden) { self.energy -= amount; LK.getSound('damage').play(); LK.effects.flashScreen(0xFF0000, 300); if (self.energy <= 0) { self.energy = 0; // Update high score list var highScores = storage.highScores; highScores.push(score); highScores.sort(function (a, b) { return b - a; }); if (highScores.length > 5) { highScores.pop(); // Keep only top 5 scores } storage.highScores = highScores; scoreTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(scoreTxt); scoreTxt.y = 0; LK.showGameOver(); } else { self.makeInvulnerable(1500); } } }; return self; }); var Predator = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'snake'; // Different predators have different damage and speed switch (self.type) { case 'snake': self.damage = 20; self.moveSpeed = 3; break; case 'waterRat': self.damage = 15; self.moveSpeed = 4; break; case 'goanna': self.damage = 25; self.moveSpeed = 2.5; break; default: self.damage = 15; self.moveSpeed = 3; } var graphic = self.attachAsset(self.type, { anchorX: 0.5, anchorY: 0.5 }); // Target positions for movement self.targetX = 0; self.targetY = 0; self.active = true; self.update = function () { if (self.active) { // Move towards target var dx = self.targetX - self.x; var dy = self.targetY - self.y; var angle = Math.atan2(dy, dx); self.x += Math.cos(angle) * self.moveSpeed; self.y += Math.sin(angle) * self.moveSpeed; // Rotate to face movement direction self.rotation = angle; // Change direction occasionally or if close to target if (LK.ticks % 120 === 0 || Math.abs(dx) < 20 && Math.abs(dy) < 20) { self.pickNewTarget(); } } }; self.pickNewTarget = function () { self.targetX = 100 + Math.random() * (2048 - 200); self.targetY = 100 + Math.random() * (2732 - 200); }; // Initial target self.pickNewTarget(); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x4DA6FF }); /**** * Game Code ****/ var background = LK.getAsset('waterBackground', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); game.addChild(background); // Create game title var gameTitle = new Text2('Platypus Adventure', { size: 100, fill: 0x000000, fontWeight: 'bold' }); gameTitle.anchor.set(0.5, 0.5); LK.gui.center.addChild(gameTitle); gameTitle.y = -200; // Create UI var score = 0; var level = 1; var foodEaten = 0; var foodItems = []; var predators = []; var hideSpots = []; var gameStarted = false; var spawnInterval = null; var predatorInterval = null; var dragNode = null; // Create platypus var platypus = new Platypus(); platypus.x = 2048 / 2; platypus.y = 2732 / 2; game.addChild(platypus); // Create hide spots function createHideSpots() { // Create 5 hide spots around the pond for (var i = 0; i < 5; i++) { var hideSpot = new HideSpot(); hideSpot.x = 300 + Math.random() * (2048 - 600); hideSpot.y = 300 + Math.random() * (2732 - 600); game.addChild(hideSpot); hideSpots.push(hideSpot); } } // Create UI var scoreTxt = new Text2('Score: 0', { size: 80, // Increased size to make the text larger fill: 0x000000, fontWeight: 'bold' // Make text bolder and thicker }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 60; // Energy bar background var energyBarBg = LK.getAsset('energyBarBg', { anchorX: 0.5, anchorY: 0.5 }); LK.gui.bottom.addChild(energyBarBg); energyBarBg.y = -100; // Energy bar var energyBar = LK.getAsset('energyBar', { anchorX: 0, anchorY: 0.5, x: -250, y: 0 }); energyBarBg.addChild(energyBar); // Instructions text var instructionsTxt = new Text2('Tap to guide your platypus. Catch food and avoid predators!', { size: 40, fill: 0x000000, fontWeight: 'bold' // Make text bolder and thicker }); instructionsTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(instructionsTxt); // Start game function function startGame() { if (!gameStarted) { // Remove game title gameTitle.destroy(); gameStarted = true; createHideSpots(); // Remove instructions instructionsTxt.destroy(); // Schedule food spawning spawnInterval = LK.setInterval(function () { spawnFood(); }, 2000); // Schedule predator spawning predatorInterval = LK.setInterval(function () { spawnPredator(); }, 5000); // Play background music LK.playMusic('gameMusic'); } } // Spawn food function spawnFood() { var foodType = Math.random() < 0.7 ? 'insect' : 'shrimp'; var food = new Food(foodType); // Spawn food at random positions, but not too close to the edges food.x = 100 + Math.random() * (2048 - 200); food.y = 100 + Math.random() * (2732 - 200); game.addChild(food); foodItems.push(food); // Food automatically disappears after some time LK.setTimeout(function () { if (foodItems.indexOf(food) !== -1) { foodItems.splice(foodItems.indexOf(food), 1); food.destroy(); } }, 10000); } // Spawn predator function spawnPredator() { // Don't spawn too many predators if (predators.length >= 5) { return; } // Choose predator type based on the current level var types = []; if (level >= 1) { types.push('waterRat'); } if (level >= 2) { types.push('snake'); } if (level >= 3) { types.push('goanna'); } var randomType = types[Math.floor(Math.random() * types.length)]; var predator = new Predator(randomType); // Spawn predator at edge of screen var side = Math.floor(Math.random() * 4); switch (side) { case 0: // Top predator.x = Math.random() * 2048; predator.y = -50; break; case 1: // Right predator.x = 2048 + 50; predator.y = Math.random() * 2732; break; case 2: // Bottom predator.x = Math.random() * 2048; predator.y = 2732 + 50; break; case 3: // Left predator.x = -50; predator.y = Math.random() * 2732; break; } game.addChild(predator); predators.push(predator); // Predator leaves after some time LK.setTimeout(function () { if (predators.indexOf(predator) !== -1) { predators.splice(predators.indexOf(predator), 1); predator.destroy(); } }, 15000 + Math.random() * 10000); } // Check if platypus is in a hide spot function checkHideSpots() { var inHideSpot = false; for (var i = 0; i < hideSpots.length; i++) { if (platypus.intersects(hideSpots[i])) { inHideSpot = true; if (!platypus.hidden) { platypus.hide(); } break; } } if (!inHideSpot && platypus.hidden) { platypus.unhide(); } } // Handle game input function handleMove(x, y, obj) { if (dragNode) { dragNode.targetX = x; dragNode.targetY = y; } } game.move = handleMove; game.down = function (x, y, obj) { if (!gameStarted) { startGame(); } dragNode = platypus; platypus.targetX = x; platypus.targetY = y; handleMove(x, y, obj); }; game.up = function (x, y, obj) { dragNode = null; }; // Main game update game.update = function () { // Update energy bar energyBar.width = platypus.energy / platypus.maxEnergy * 500; // Check if platypus is in a hide spot checkHideSpots(); // Check for food collisions for (var i = foodItems.length - 1; i >= 0; i--) { if (platypus.intersects(foodItems[i])) { // Eat food var food = foodItems[i]; platypus.energy = Math.min(platypus.maxEnergy, platypus.energy + food.value); score += food.value; scoreTxt.setText("Score: " + score + " | Level: " + level); foodEaten += 1; if (score >= level * 100) { level += 1; console.log("Level Up! Current Level: " + level); // Increase predator speed with each level up predators.forEach(function (predator) { predator.moveSpeed += 0.5; // Increase speed by 0.5 for each level }); // Remove one hiding spot every level up if (hideSpots.length > 0) { var removedHideSpot = hideSpots.pop(); removedHideSpot.destroy(); } } scoreTxt.setText("Score: " + score + " | Level: " + level); // Remove food foodItems.splice(i, 1); food.destroy(); // Create splash effect var splash = LK.getAsset('splash', { anchorX: 0.5, anchorY: 0.5, x: food.x, y: food.y, alpha: 0.7 }); game.addChild(splash); tween(splash, { alpha: 0 }, { duration: 800, onFinish: function onFinish() { splash.destroy(); } }); // Play eat sound LK.getSound('eat').play(); } } // Check for predator collisions for (var j = 0; j < predators.length; j++) { var predator = predators[j]; // Predator follows platypus if not hidden if (!platypus.hidden && LK.ticks % 60 === 0) { var chaseChance = 0.7; if (Math.random() < chaseChance) { predator.targetX = platypus.x; predator.targetY = platypus.y; } } // Check collision with platypus if (platypus.intersects(predator) && !platypus.hidden) { platypus.takeDamage(predator.damage); score = Math.max(0, score - 2); // Deduct 2 points, ensuring score doesn't go below 0 scoreTxt.setText("Score: " + score + " | Level: " + level); // Push predator away from platypus var pushAngle = Math.atan2(predator.y - platypus.y, predator.x - platypus.x); predator.x += Math.cos(pushAngle) * 150; predator.y += Math.sin(pushAngle) * 150; predator.pickNewTarget(); } } // Spawn initial food if game has started if (gameStarted && foodItems.length === 0 && LK.ticks === 10) { for (var k = 0; k < 3; k++) { spawnFood(); } } };
===================================================================
--- original.js
+++ change.js
@@ -156,8 +156,21 @@
LK.getSound('damage').play();
LK.effects.flashScreen(0xFF0000, 300);
if (self.energy <= 0) {
self.energy = 0;
+ // Update high score list
+ var highScores = storage.highScores;
+ highScores.push(score);
+ highScores.sort(function (a, b) {
+ return b - a;
+ });
+ if (highScores.length > 5) {
+ highScores.pop(); // Keep only top 5 scores
+ }
+ storage.highScores = highScores;
+ scoreTxt.anchor.set(0.5, 0.5);
+ LK.gui.center.addChild(scoreTxt);
+ scoreTxt.y = 0;
LK.showGameOver();
} else {
self.makeInvulnerable(1500);
}
Cute Platypus swimming. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. In game asset main character 2d
Dragonfly, small but detailed. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Green reeds with Lilly pad. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Light Brown moving snake top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Goanna swimming top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pink shrimp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Water rat swimming top down view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Small splash in water. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Green water energy bar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows