User prompt
if lander intersects with either side of the platform, then its game over
User prompt
lander can only land on the top of the platform. if it touches the side of the platform, its game over
User prompt
game should get more difficult as levels progress
User prompt
when lander is destroyed by coisioning with the platform, show a new asset called, CrashedLander on top of the lander. this asset should be destroyed after one second.
User prompt
create a class called crashedlander. this asset will be displayed for one second on top of the lander, when the lander crasehs with the platform.
User prompt
when lander crashes with platform, wait one second before game ovevr
User prompt
when lander crashes, wait 1 second before showing game over message
Code edit (1 edits merged)
Please save this source code
User prompt
increase gravity 10%
User prompt
asteroids should start spawning on level 4
User prompt
hide score display
User prompt
Fix Bug: 'ReferenceError: scoreTxt is not defined' in this line: 'scoreTxt.setText(score.toString());' Line Number: 220
User prompt
move level txt to the top center of the screen
User prompt
remove score from the top of the screen
User prompt
when lander lands show a new asset called, landedlander on top of the lander. this asset should be destroyed after one second.
User prompt
when game is paused hide lander asset
User prompt
after level number is increased, pause all assets movement for 1 second.
User prompt
add a 1 second pause of the game, including all assets after a level is finished
User prompt
lander has to intersect 100% of its width with the platform to be successful landing
User prompt
pause all assets from moving for one second after landing is succesfull
User prompt
after lander respawns in the top of the screen pause the game for 1 second
User prompt
After lander respawns, pause it for 1 second before it moves again. Also hide it for that second.
User prompt
Lander should dissapear from one second before it ia respawned
User prompt
Use LK.setTimeout to wait for a second before the next lander spawns after a landing
User prompt
Reduce platform speed in 30%
/**** * Classes ****/ var LandedLander = Container.expand(function () { var self = Container.call(this); var landedLanderGraphics = self.createAsset('landedlander', 'Landed Lander', 0.5, 0.5); self.destroyAfterOneSecond = function () { LK.setTimeout(function () { self.destroy(); }, 1000); }; }); // Thruster class var Thruster = Container.expand(function () { var self = Container.call(this); var thrusterGraphics = self.createAsset('thruster', 'Thruster', 0.5, 0.5); self.update = function () { // Thruster update code here }; }); // Lander class var Lander = Container.expand(function () { var self = Container.call(this); var landerGraphics = self.createAsset('lander', 'Player Lander', 0.5, 0.5); self.speedX = 0; self.speedY = 0; self.fuel = 1000; self.isThrusting = false; self.isLanding = false; self.update = function () { if (!self.isLanding) { self.x += self.speedX; self.y += self.speedY; if (self.isThrusting && self.fuel > 0) { self.speedY -= 0.2; // Thruster effect self.fuel -= 1; fuelTxt.setText(self.fuel.toString() + ' Fuel'); // Update fuel display } else { self.speedY += 0.05; // Gravity effect } ySpeedTxt.setText('Y Speed: ' + self.speedY.toFixed(2)); // Update Y Speed display } // Update thruster position and visibility thruster.x = self.x; thruster.y = self.y + self.height - 15; // Position thruster 20 pixels closer to the lander thruster.visible = self.isThrusting; }; self.land = function () { self.isLanding = true; var landedLander = game.addChild(new LandedLander()); landedLander.x = self.x; landedLander.y = self.y; landedLander.destroyAfterOneSecond(); levelManager.incrementLevel(); }; self.refuel = function () { self.fuel = 1000; fuelTxt.setText(self.fuel.toString() + ' Fuel'); // Update fuel display }; }); // Platform class var MovingPlatform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.createAsset('platform', 'Landing Platform', 0.5, 0.5); self.speedX = 0; self.startMoving = function (level) { if (level >= 3) { self.speedX = 2.8; // Reduced sideways speed by 30% for level 3 } }; self.update = function () { self.x += self.speedX; if (self.x > 1524 || self.x < 524) { self.speedX *= -1; // Change direction when hitting screen bounds } }; self.checkLanding = function (lander) { if (lander.intersects(self)) { if (lander.speedY < 2) { return true; } else { isGameOver = true; LK.showGameOver(); return false; } } return false; }; }); // Level class var Level = Container.expand(function () { var self = Container.call(this); self.currentLevel = 1; var levelTxt = new Text2('Level: ' + self.currentLevel, { size: 50, fill: "#ffffff" }); levelTxt.anchor.set(0.5, 0); LK.gui.top.addChild(levelTxt); self.incrementLevel = function () { self.currentLevel += 1; levelTxt.setText('Level: ' + self.currentLevel); platform.startMoving(self.currentLevel); isPaused = true; pauseTimer = 60; }; }); // Asteroid class var Asteroid = Container.expand(function () { var self = Container.call(this); var asteroidGraphics = self.createAsset('asteroid', 'Asteroid', 0.5, 0.5); self.speedX = Math.random() * 2 - 1; // Random horizontal speed self.speedY = Math.random() * 3 + 1; // Random vertical speed self.update = function () { self.x += self.speedX; self.y += self.speedY; // Destroy asteroid if it goes off-screen if (self.y > 2732 || self.x < 0 || self.x > 2048) { self.destroy(); } }; }); /**** * Initialize Game ****/ // Initialize lander var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize lander var scoreTxt = new Text2('0', { size: 50, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var lander = game.addChild(new Lander()); lander.x = 1024; // Start in the middle of the screen horizontally lander.y = 100; // Start 100 pixels down from the top // Initialize thruster var thruster = game.addChild(new Thruster()); thruster.x = lander.x; thruster.y = lander.y + lander.height + 5; // Position thruster 5 pixels below the lander // Initialize level manager var levelManager = game.addChild(new Level()); // Initialize moving platform var platform = game.addChild(new MovingPlatform()); platform.x = 1024; // Center horizontally platform.y = 2632; // Place at the bottom // Game variables var isGameOver = false; var isPaused = false; var pauseTimer = 0; var score = 0; var asteroids = []; // Fuel display text var fuelTxt = new Text2('1000 Fuel', { size: 50, fill: "#ffffff" }); fuelTxt.anchor.set(1, 0); LK.gui.topRight.addChild(fuelTxt); // Y Speed display text var ySpeedTxt = new Text2('Y Speed: ' + lander.speedY.toFixed(2), { size: 50, fill: "#ffffff" }); ySpeedTxt.anchor.set(1, 0); ySpeedTxt.y = 50; LK.gui.topRight.addChild(ySpeedTxt); // Gravity display text var gravityTxt = new Text2('Gravity: 0.05', { size: 50, fill: "#ffffff" }); gravityTxt.anchor.set(1, 0); gravityTxt.y = 100; LK.gui.topRight.addChild(gravityTxt); // Event listeners game.on('down', function (obj) { lander.isThrusting = true; }); game.on('up', function (obj) { lander.isThrusting = false; }); // Game tick update LK.on('tick', function () { if (isPaused) { lander.visible = false; pauseTimer--; if (pauseTimer <= 0) { isPaused = false; lander.visible = true; } return; } if (!isGameOver) { // Update all asteroids asteroids = game.children.filter(function (child) { return child instanceof Asteroid; }); lander.update(); platform.update(); // Update platform position // Check for landing if (platform.checkLanding(lander)) { lander.land(); score += 1; scoreTxt.setText(score.toString()); lander.refuel(); lander.x = 1024; lander.y = 100; lander.speedY = 0; lander.isLanding = false; } // Check for collision with asteroids and game over conditions for (var i = 0; i < asteroids.length; i++) { if (lander.intersects(asteroids[i])) { isGameOver = true; LK.showGameOver(); break; } } // Check if lander is off-screen for game over if (lander.y > 2732) { isGameOver = true; LK.showGameOver(); } // Asteroid spawning if (LK.ticks % 120 == 0) { // Spawn an asteroid every 2 seconds var newAsteroid = new Asteroid(); var safeZoneRadius = 200; var landerSpawnX = 1024; var minDistanceFromLander; do { newAsteroid.x = Math.random() * 2048; // Random horizontal start position minDistanceFromLander = Math.abs(newAsteroid.x - landerSpawnX); } while (minDistanceFromLander <= safeZoneRadius); newAsteroid.y = -50; // Start just above the screen game.addChild(newAsteroid); } // Update all asteroids asteroids = game.children.filter(function (child) { return child instanceof Asteroid; }); for (var i = 0; i < asteroids.length; i++) { asteroids[i].update(); } // Check for game over conditions if (lander.y > 2732) { isGameOver = true; LK.showGameOver(); } } });
===================================================================
--- original.js
+++ change.js
@@ -134,8 +134,14 @@
/****
* Game Code
****/
// Initialize lander
+var scoreTxt = new Text2('0', {
+ size: 50,
+ fill: "#ffffff"
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
var lander = game.addChild(new Lander());
lander.x = 1024; // Start in the middle of the screen horizontally
lander.y = 100; // Start 100 pixels down from the top