User prompt
Truster should be 1 pixel below the lander asset
User prompt
Add a thruster asset that will be attached below the lander
User prompt
Asteroids should spawn from the top half of the screen from the side or the top, and end on the oposite aide
User prompt
If asteroid intersects with lander then its game over
User prompt
Asteroda should spawn on game start
User prompt
Create a new class for asteroids. Asteroids will fly acroolss the screen from top to bottom randomly
User prompt
Platform sideways movement should be 500 pixels to each side max
User prompt
Level 3 platform speed should be 4 times as fast
User prompt
On level 3 platform should start moving sidewatlys at a normal speed
User prompt
Add levels structure to the game. Show current level on the top left of the screen
User prompt
After lander lands pause the game for half a second
User prompt
Dont wait for a second after the lander lands and the next spawbs
User prompt
After two succesful landings start moving the platform sideways from side to side of the screen
User prompt
Increase fuel to 1000
User prompt
Start lander 100 pixela down
User prompt
Lander shoud start 100 pixels down
User prompt
Show gravity below the y speed text
User prompt
When fuel is 0 lander should continue its vertical descent
User prompt
When fuel reaches 0, lander should continue its descent and not game over
User prompt
Lander will continue its descent when fuel is 0
User prompt
When fuel is 0 instead of game over, lander should continue dropping
User prompt
Take back starting fuel to 100
User prompt
If lander lands succesfully whait for one second before next ones spawns
User prompt
Lander speed for succesful landing need to be lower than 2
User prompt
Double ammount of starting fuel
/**** * 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 = 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 } }; self.land = function () { self.isLanding = true; }; self.refuel = function () { self.fuel = 1000; 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.moving = false; self.direction = 1; // 1 for right, -1 for left self.moveSpeed = 2; self.startMoving = function () { self.moving = true; }; self.update = function () { if (self.moving) { self.x += self.direction * self.moveSpeed; // Reverse direction when reaching screen bounds if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) { self.direction *= -1; } } }; self.checkLanding = function (lander) { if (lander.intersects(self)) { if (lander.speedY < 2) { return true; } else { isGameOver = true; LK.showGameOver(); return false; } } return false; }; }); /**** * 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 100 pixels down 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 successfulLandings = 0; // Track successful landings to initiate platform movement 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('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 (!isGameOver) { lander.update(); platform.update(); // Update platform position // Check for landing if (platform.checkLanding(lander)) { lander.land(); score += 1; successfulLandings += 1; // Increment successful landings scoreTxt.setText(score.toString()); lander.refuel(); // Check if platform should start moving if (successfulLandings >= 2) { platform.startMoving(); } // Delay before resetting lander position LK.setTimeout(function () { lander.x = 1024; lander.y = 100; lander.speedY = 0; lander.isLanding = false; }, 1000); } // Check for game over conditions if (lander.y > 2732) { isGameOver = true; LK.showGameOver(); } } });
===================================================================
--- original.js
+++ change.js
@@ -35,8 +35,23 @@
// Platform class
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.createAsset('platform', 'Landing Platform', 0.5, 0.5);
+ self.moving = false;
+ self.direction = 1; // 1 for right, -1 for left
+ self.moveSpeed = 2;
+ self.startMoving = function () {
+ self.moving = true;
+ };
+ self.update = function () {
+ if (self.moving) {
+ self.x += self.direction * self.moveSpeed;
+ // Reverse direction when reaching screen bounds
+ if (self.x > 2048 - self.width / 2 || self.x < self.width / 2) {
+ self.direction *= -1;
+ }
+ }
+ };
self.checkLanding = function (lander) {
if (lander.intersects(self)) {
if (lander.speedY < 2) {
return true;
@@ -72,8 +87,9 @@
// Game variables
var isGameOver = false;
var score = 0;
+var successfulLandings = 0; // Track successful landings to initiate platform movement
var scoreTxt = new Text2(score.toString(), {
size: 150,
fill: "#ffffff"
});
@@ -117,15 +133,21 @@
// Game tick update
LK.on('tick', function () {
if (!isGameOver) {
lander.update();
+ platform.update(); // Update platform position
// Check for landing
if (platform.checkLanding(lander)) {
lander.land();
score += 1;
+ successfulLandings += 1; // Increment successful landings
scoreTxt.setText(score.toString());
lander.refuel();
+ // Check if platform should start moving
+ if (successfulLandings >= 2) {
+ platform.startMoving();
+ }
// Delay before resetting lander position
LK.setTimeout(function () {
lander.x = 1024;
lander.y = 100;