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
}
ySpeedTxt.setText('Y Speed: ' + self.speedY.toFixed(2)); // Update Y Speed display
}
};
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) {
if (lander.intersects(self)) {
if (lander.speedY < 1) {
return 'success';
} else {
return 'crash';
}
}
return 'none';
};
});
/****
* 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: 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);
// 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 or crash
var landingStatus = platform.checkLanding(lander);
if (landingStatus === 'success') {
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;
} else if (landingStatus === 'crash') {
// Show crash asset
var crashAsset = game.addChild(LK.getAsset('crash', 'Crash Asset', 0.5, 0.5));
crashAsset.x = lander.x;
crashAsset.y = lander.y;
// Trigger game over after 1 second
LK.setTimeout(function () {
isGameOver = true;
LK.showGameOver();
}, 1000);
}
// Check for game over conditions
if (lander.y > 2732 || lander.fuel <= 0) {
isGameOver = true;
LK.showGameOver();
}
}
}); ===================================================================
--- original.js
+++ change.js
@@ -36,9 +36,16 @@
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;
+ if (lander.intersects(self)) {
+ if (lander.speedY < 1) {
+ return 'success';
+ } else {
+ return 'crash';
+ }
+ }
+ return 'none';
};
});
/****
@@ -100,10 +107,11 @@
LK.on('tick', function () {
if (!isGameOver) {
lander.update();
- // Check for landing
- if (platform.checkLanding(lander)) {
+ // Check for landing or crash
+ var landingStatus = platform.checkLanding(lander);
+ if (landingStatus === 'success') {
lander.land();
score += 1;
scoreTxt.setText(score.toString());
lander.refuel();
@@ -111,8 +119,18 @@
lander.x = 1024;
lander.y = 100;
lander.speedY = 0;
lander.isLanding = false;
+ } else if (landingStatus === 'crash') {
+ // Show crash asset
+ var crashAsset = game.addChild(LK.getAsset('crash', 'Crash Asset', 0.5, 0.5));
+ crashAsset.x = lander.x;
+ crashAsset.y = lander.y;
+ // Trigger game over after 1 second
+ LK.setTimeout(function () {
+ isGameOver = true;
+ LK.showGameOver();
+ }, 1000);
}
// Check for game over conditions
if (lander.y > 2732 || lander.fuel <= 0) {