User prompt
If lander intersects platform and speed y is bigger than 1 then its game over
User prompt
If lander interscets with platfor and y speed is more than one then show crash asset and game over after 1 second
User prompt
Reduce fuel and y speed font size in half
User prompt
Move y speed text 50 pixels below fuel
User prompt
Below fuel show the y speed of the lander
User prompt
Show fuel quantity in the top right corner
User prompt
On click, lander will burst its thruster reduce its descensce speed
Initial prompt
Lander 1990
/**** * Classes ****/ // 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 = 100; self.isThrusting = false; self.isLanding = false; self.update = function () { if (self.fuel > 0 && !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 } } }; self.land = function () { self.isLanding = true; }; self.refuel = function () { self.fuel = 100; fuelTxt.setText(self.fuel.toString() + ' Fuel'); // Update fuel display }; }); // Platform class var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.createAsset('platform', 'Landing Platform', 0.5, 0.5); self.checkLanding = function (lander) { return lander.intersects(self) && lander.speedY < 1; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ // Initialize lander var lander = game.addChild(new Lander()); lander.x = 1024; // Start in the middle of the screen horizontally lander.y = 100; // Start from the top // Initialize platform var platform = game.addChild(new Platform()); platform.x = 1024; // Center horizontally platform.y = 2632; // Place at the bottom // Game variables var isGameOver = false; var score = 0; var scoreTxt = new Text2(score.toString(), { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Fuel display text var fuelTxt = new Text2(lander.fuel.toString() + ' Fuel', { size: 100, fill: "#ffffff" }); fuelTxt.anchor.set(1, 0); LK.gui.topRight.addChild(fuelTxt); // 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 (!isGameOver) { lander.update(); // Check for landing if (platform.checkLanding(lander)) { lander.land(); score += 1; scoreTxt.setText(score.toString()); lander.refuel(); // Reset lander position lander.x = 1024; lander.y = 100; lander.speedY = 0; lander.isLanding = false; } // Check for game over conditions if (lander.y > 2732 || lander.fuel <= 0) { isGameOver = true; LK.showGameOver(); } } });
===================================================================
--- original.js
+++ change.js
@@ -16,8 +16,9 @@
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
}
}
@@ -26,8 +27,9 @@
self.isLanding = true;
};
self.refuel = function () {
self.fuel = 100;
+ fuelTxt.setText(self.fuel.toString() + ' Fuel'); // Update fuel display
};
});
// Platform class
var Platform = Container.expand(function () {
@@ -67,8 +69,16 @@
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
+// Fuel display text
+var fuelTxt = new Text2(lander.fuel.toString() + ' Fuel', {
+ size: 100,
+ fill: "#ffffff"
+});
+fuelTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(fuelTxt);
+
// Event listeners
game.on('down', function (obj) {
lander.isThrusting = true;
});