User prompt
use crash sound when lander crashes
User prompt
whne lander lands succesfully play hooray
User prompt
every time the player touches the screen and the trhuster is active play thruster sound
User prompt
Migrate to the latest version of LK
User prompt
Remove dotted line and thruater message after lander goes out of bounds
User prompt
When missed platform wait 2 seconda before game over and remove dottes line and thruater text if first level
User prompt
If lander goes out of boundries in the bottom, show message that reads: "Did you just miss the platform? Try again Cap!"
User prompt
If lander goes of limits on level 1 remove dotted lines and thruater text
User prompt
Befor game over message in level one, remove dotted line and text
User prompt
If lander game over is because lander goes off screen on the top or to the sides, add a message befor game over that reads: "You got Lost in Space! Try again!"
User prompt
Allow lander to go 300 pixels up and to the sides before game over
User prompt
If lander leaves the screens on the side or the top its also game over
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: crashMessage is not defined' in this line: 'crashMessage.destroy();' Line Number: 159
User prompt
separate crashmessage in two lines
User prompt
make lines 2 and 3 of crash message a little smaller font size
Code edit (2 edits merged)
Please save this source code
User prompt
platformm should move sideways from level 5 onwards
User prompt
platform shoud move from level 5 on
Code edit (1 edits merged)
Please save this source code
User prompt
show success message on every level if success
===================================================================
--- original.js
+++ change.js
@@ -1,50 +1,89 @@
/****
* Classes
-****/
-var CrashedLander = Container.expand(function () {
+****/
+// Asteroid class
+var Asteroid = Container.expand(function () {
var self = Container.call(this);
- var crashedLanderGraphics = self.createAsset('crashedlander', 'Crashed Lander', 0.5, 0.5);
- self.destroyAfterOneSecond = function () {
- LK.setTimeout(function () {
+ var asteroidGraphics = self.attachAsset('asteroid', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = Math.random() * 2 - 1; // Random horizontal speed
+ self.speedY = Math.random() * 3 + 1; // Random vertical speed
+ self._update_migrated = 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();
- }, 1000);
+ }
};
});
-var LandedLander = Container.expand(function () {
+var CrashedLander = Container.expand(function () {
var self = Container.call(this);
- var landedLanderGraphics = self.createAsset('landedlander', 'Landed Lander', 0.5, 0.5);
+ var crashedLanderGraphics = self.attachAsset('crashedlander', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.destroyAfterOneSecond = function () {
LK.setTimeout(function () {
self.destroy();
}, 1000);
};
});
-// Left Thruster class
-var LeftThruster = Container.expand(function () {
+var DottedLine = Container.expand(function () {
var self = Container.call(this);
- var leftThrusterGraphics = self.createAsset('leftThruster', 'Left Thruster', 0.5, 0.5);
+ self.createDottedLine = function (startX, startY, endX, endY, color, dotSize, gapSize) {
+ var distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
+ var dotCount = Math.floor(distance / (dotSize + gapSize * 2));
+ for (var i = 0; i < dotCount; i++) {
+ var dot = self.addChild(LK.getAsset('dot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ dot.alpha = 0.5;
+ dot.x = startX + (endX - startX) * (i / dotCount);
+ dot.y = startY + (endY - startY) * (i / dotCount);
+ dot.width = dotSize;
+ dot.height = dotSize;
+ dot.tint = color;
+ }
+ };
});
-// Right Thruster class
-var RightThruster = Container.expand(function () {
- var self = Container.call(this);
- var rightThrusterGraphics = self.createAsset('rightThruster', 'Right Thruster', 0.5, 0.5);
-});
// Down Thruster class
var DownThruster = Container.expand(function () {
var self = Container.call(this);
- var downThrusterGraphics = self.createAsset('thruster', 'Down Thruster', 0.5, 0.5);
+ var downThrusterGraphics = self.attachAsset('thruster', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
});
+var LandedLander = Container.expand(function () {
+ var self = Container.call(this);
+ var landedLanderGraphics = self.attachAsset('landedlander', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.destroyAfterOneSecond = function () {
+ LK.setTimeout(function () {
+ self.destroy();
+ }, 1000);
+ };
+});
// Lander class
var Lander = Container.expand(function () {
var self = Container.call(this);
- var landerGraphics = self.createAsset('lander', 'Player Lander', 0.5, 0.5);
+ var landerGraphics = self.attachAsset('lander', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.speedX = 0;
self.speedY = 0;
self.fuel = 500;
self.isThrusting = false;
self.isLanding = false;
- self.update = function () {
+ self._update_migrated = function () {
if (!self.isLanding) {
self.x += self.speedX;
self.y += self.speedY;
if (self.isThrusting && self.fuel > 0) {
@@ -99,12 +138,61 @@
self.fuel = 500;
fuelTxt.setText('100% Fuel'); // Show fuel as a percentage when refueled
};
});
+// Left Thruster class
+var LeftThruster = Container.expand(function () {
+ var self = Container.call(this);
+ var leftThrusterGraphics = self.attachAsset('leftThruster', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+});
+// Level class
+var Level = Container.expand(function () {
+ var self = Container.call(this);
+ self.currentLevel = 1;
+ var levelTxt = new Text2('Level: ' + self.currentLevel, {
+ size: 100,
+ // Double the size
+ 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);
+ leftDottedLine.visible = false;
+ rightDottedLine.visible = false;
+ leftMessage.visible = false;
+ centerMessage.visible = false;
+ rightMessage.visible = false;
+ var successMessages = ['Smooth landing Captain!', 'Perfect touchdown!', 'Another successful landing!', 'You nailed it!', 'Flawless descent!'];
+ var randomIndex = Math.floor(Math.random() * successMessages.length);
+ var successMessage = new Text2(successMessages[randomIndex], {
+ size: 100,
+ fill: '#ffffff',
+ align: 'center'
+ });
+ successMessage.anchor.set(0.5, 0.5);
+ successMessage.x = 1024;
+ successMessage.y = 1066;
+ game.addChild(successMessage);
+ LK.setTimeout(function () {
+ successMessage.destroy();
+ }, 1000);
+ isPaused = true;
+ pauseTimer = 60;
+ };
+});
// Platform class
var MovingPlatform = Container.expand(function () {
var self = Container.call(this);
- var platformGraphics = self.createAsset('platform', 'Landing Platform', 0.5, 0.5);
+ var platformGraphics = self.attachAsset('platform', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.speedX = 0;
self.startMoving = function (level) {
LK.setTimeout(function () {
if (level >= 2) {
@@ -114,9 +202,9 @@
self.speedX = 2.8 + (level - 5) * 0.2; // Increase sideways speed by 0.2 for each level above 5
}
}, 1000); // Add a 1 second pause before repositioning the platform
};
- self.update = function () {
+ self._update_migrated = function () {
self.x += self.speedX;
if (self.x > 1524 || self.x < 524) {
self.speedX *= -1; // Change direction when hitting screen bounds
}
@@ -172,82 +260,20 @@
}
return false;
};
});
-// Level class
-var Level = Container.expand(function () {
+// Right Thruster class
+var RightThruster = Container.expand(function () {
var self = Container.call(this);
- self.currentLevel = 1;
- var levelTxt = new Text2('Level: ' + self.currentLevel, {
- size: 100,
- // Double the size
- fill: "#ffffff"
+ var rightThrusterGraphics = self.attachAsset('rightThruster', {
+ anchorX: 0.5,
+ anchorY: 0.5
});
- 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);
- leftDottedLine.visible = false;
- rightDottedLine.visible = false;
- leftMessage.visible = false;
- centerMessage.visible = false;
- rightMessage.visible = false;
- var successMessages = ['Smooth landing Captain!', 'Perfect touchdown!', 'Another successful landing!', 'You nailed it!', 'Flawless descent!'];
- var randomIndex = Math.floor(Math.random() * successMessages.length);
- var successMessage = new Text2(successMessages[randomIndex], {
- size: 100,
- fill: '#ffffff',
- align: 'center'
- });
- successMessage.anchor.set(0.5, 0.5);
- successMessage.x = 1024;
- successMessage.y = 1066;
- game.addChild(successMessage);
- LK.setTimeout(function () {
- successMessage.destroy();
- }, 1000);
- 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();
- }
- };
-});
-var DottedLine = Container.expand(function () {
- var self = Container.call(this);
- self.createDottedLine = function (startX, startY, endX, endY, color, dotSize, gapSize) {
- var distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
- var dotCount = Math.floor(distance / (dotSize + gapSize * 2));
- for (var i = 0; i < dotCount; i++) {
- var dot = self.addChild(LK.getAsset('dot', 'Dotted Line Dot', 0.5, 0.5));
- dot.alpha = 0.5;
- dot.x = startX + (endX - startX) * (i / dotCount);
- dot.y = startY + (endY - startY) * (i / dotCount);
- dot.width = dotSize;
- dot.height = dotSize;
- dot.tint = color;
- }
- };
-});
-
/****
* Initialize Game
-****/
+****/
// Stars class
// Center vertically
// Initialize lander
var game = new LK.Game({
@@ -255,14 +281,13 @@
});
/****
* Game Code
-****/
+****/
// Initialize lander
// Stars class
function _typeof(o) {
"@babel/helpers - typeof";
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
@@ -403,9 +428,12 @@
_createClass(Stars, [{
key: "createStars",
value: function createStars() {
for (var i = 0; i < 100; i++) {
- var star = this.addChild(LK.getAsset('star', 'Star', 0.5, 0.5));
+ var star = this.addChild(LK.getAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
star.alpha = Math.random() * 0.5 + 0.5; // Random transparency for twinkling effect
var randomScale = Math.random() * 0.3 + 0.2; // Random scale for different sizes
@@ -415,16 +443,18 @@
}
}]);
return Stars;
}(Container);
-var background = game.addChild(LK.getAsset('background', 'Game Background', 0, 0));
+var background = game.addChild(LK.getAsset('background', {}));
background.x = 1024; // Center horizontally
background.y = 1366;
// Add stars behind the main background
var stars = game.addChild(new Stars());
-
// Add second background
-var secondBackground = game.addChildAt(LK.getAsset('secondBackground', 'Second Game Background', 0.5, 0.5), 0);
+var secondBackground = game.addChildAt(LK.getAsset('secondBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5
+}), 0);
secondBackground.width = 2048;
secondBackground.height = 2732;
secondBackground.x = 2048 / 2; // Center horizontally
secondBackground.y = 2732 / 2; // Center vertically
@@ -433,9 +463,8 @@
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
//LK.gui.top.addChild(scoreTxt);
-
// Initialize thrusters
var downThruster = game.addChild(new DownThruster()); // Position down thruster at the bottom center of the lander
var leftThruster = game.addChild(new LeftThruster());
leftThruster.visible = false;
@@ -485,24 +514,21 @@
lander.x = 1024; // Start in the middle of the screen horizontally
lander.y = 250; // Start 250 pixels down from the top
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('100% 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"
@@ -517,21 +543,19 @@
});
xSpeedTxt.anchor.set(1, 0);
xSpeedTxt.y = 100;
LK.gui.topRight.addChild(xSpeedTxt);
-
// Gravity display text
var gravityTxt = new Text2('Gravity: 1.62', {
size: 50,
fill: "#ffffff"
});
gravityTxt.anchor.set(1, 0);
gravityTxt.y = 150;
LK.gui.topRight.addChild(gravityTxt);
-
// Event listeners
-game.on('down', function (obj) {
- var touchPos = obj.event.getLocalPosition(game);
+game.on('down', function (x, y, obj) {
+ var touchPos = game.toLocal(obj.global);
if (touchPos.x < 2048 / 3) {
lander.thrustDirection = 'left';
} else if (touchPos.x > 2048 * 2 / 3) {
lander.thrustDirection = 'right';
@@ -539,13 +563,12 @@
lander.thrustDirection = 'down';
}
lander.isThrusting = true;
});
-game.on('up', function (obj) {
+game.on('up', function (x, y, obj) {
lander.isThrusting = false;
lander.thrustDirection = null;
});
-
// Game tick update
LK.on('tick', function () {
if (isPaused) {
lander.visible = false;
@@ -560,14 +583,12 @@
// Update all asteroids
asteroids = game.children.filter(function (child) {
return child instanceof Asteroid;
});
- lander.update();
- platform.update(); // Update platform position
-
+ lander._update_migrated();
+ platform._update_migrated(); // Update platform position
// Update X Speed display
xSpeedTxt.setText('X Speed: ' + lander.speedX.toFixed(2));
-
// Check for landing
if (platform.checkLanding(lander)) {
lander.land();
score += 1;
@@ -594,9 +615,8 @@
if (lander.y > 2732) {
isGameOver = true;
LK.showGameOver();
}
-
// Asteroid spawning
if (levelManager.currentLevel >= 3 && LK.ticks % (240 - Math.floor((levelManager.currentLevel - 1) / 2) * 20) == 0) {
// Spawn an asteroid less frequently as levels progress
// Adjusted the rate of increase for asteroid spawn frequency
@@ -610,17 +630,15 @@
} 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();
+ asteroids[i]._update_migrated();
}
-
// Check for game over conditions
if (lander.y > 3000 || lander.x < -300 || lander.x > 2348 || lander.y < -300) {
isGameOver = true;
leftDottedLine.visible = false;