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.isLanding = false;
self.update = function () {
if (self.fuel > 0 && !self.isLanding) {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += 0.05; // Gravity effect
}
};
self.land = function () {
self.isLanding = true;
};
self.refuel = function () {
self.fuel = 100;
};
});
// 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);
// Event listeners
game.on('down', function (obj) {
var touchPos = obj.event.getLocalPosition(game);
if (touchPos.x < 1024) {
lander.speedX = -1;
} else {
lander.speedX = 1;
}
});
game.on('up', function (obj) {
lander.speedX = 0;
});
// 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();
}
}
});