/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Randomly select one of 4 obstacle types
var obstacleTypes = ['obstacle', 'obstacle2', 'obstacle3', 'obstacle4'];
var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
var obstacleGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.originalX = 0;
self.originalY = 0;
// Start continuous slow rotation
function startRotation() {
tween(self, {
rotation: self.rotation + Math.PI * 2
}, {
duration: 8000,
easing: tween.linear,
onFinish: startRotation
});
}
startRotation();
self.startMoving = function () {
if (self.isMoving) return;
self.isMoving = true;
self.originalX = self.x;
self.originalY = self.y;
// Random movement pattern
var movementType = Math.floor(Math.random() * 3);
if (movementType === 0) {
// Horizontal movement
var moveLeft = function moveLeft() {
tween(self, {
x: self.originalX - 200
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: moveRight
});
};
var moveRight = function moveRight() {
tween(self, {
x: self.originalX + 200
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: moveLeft
});
};
moveLeft();
} else if (movementType === 1) {
// Vertical movement
var moveUp = function moveUp() {
tween(self, {
y: self.originalY - 150
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: moveDown
});
};
var moveDown = function moveDown() {
tween(self, {
y: self.originalY + 150
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: moveUp
});
};
moveUp();
} else {
var _circularMove = function circularMove() {
angle += 0.02;
var newX = self.originalX + Math.cos(angle) * radius;
var newY = self.originalY + Math.sin(angle) * radius;
tween(self, {
x: newX,
y: newY
}, {
duration: 100,
easing: tween.linear,
onFinish: _circularMove
});
};
// Circular movement
var angle = 0;
var radius = 100;
_circularMove();
}
};
return self;
});
var Planet = Container.expand(function () {
var self = Container.call(this);
// Randomly select one of 9 planet types
var planetTypes = ['planet1', 'planet2', 'planet3', 'planet4', 'planet5', 'planet6', 'planet7', 'planet8', 'planet9'];
var randomType = planetTypes[Math.floor(Math.random() * planetTypes.length)];
var planetGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
// Set 25% opacity
planetGraphics.alpha = 0.25;
self.planetType = randomType; // Store the planet type for tracking
self.speed = Math.random() * 0.3 + 0.1; // Very slow movement
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for left-to-right, -1 for right-to-left
self.update = function () {
self.x += self.speed * 2 * self.direction; // Move in random direction
// Reset planet when it goes off screen
if (self.direction === 1 && self.x > 2248) {
// Moving left-to-right, reset to left side
self.x = -200;
self.y = Math.random() * 2732; // Random Y position across screen height
} else if (self.direction === -1 && self.x < -200) {
// Moving right-to-left, reset to right side
self.x = 2248;
self.y = Math.random() * 2732; // Random Y position across screen height
}
};
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.landingZone = 180; // Safe landing zone width
self.isMoving = false;
self.startMoving = function () {
if (self.isMoving) return;
self.isMoving = true;
// Calculate speed based on current level (3% faster each level)
var speedMultiplier = Math.pow(1.03, currentLevel - 3); // Start from level 3
var baseDuration = 6000;
var moveDuration = baseDuration / speedMultiplier;
// Create continuous horizontal movement
function moveLeft() {
tween(self, {
x: 300
}, {
duration: moveDuration,
easing: tween.linear,
onFinish: moveRight
});
}
function moveRight() {
tween(self, {
x: 1748
}, {
duration: moveDuration,
easing: tween.linear,
onFinish: moveLeft
});
}
// Start movement cycle
if (self.x < 1024) {
moveRight();
} else {
moveLeft();
}
};
self.checkLanding = function (spacecraft) {
var dx = Math.abs(spacecraft.x - self.x);
var dy = Math.abs(spacecraft.y - self.y);
if (dx < self.landingZone / 2 && dy < 80) {
// Check if landing speed is safe
if (spacecraft.velocityY < 4 && Math.abs(spacecraft.velocityX) < 3) {
spacecraft.land();
return true;
} else {
spacecraft.crash();
return false;
}
}
return false;
};
return self;
});
var Quote = Container.expand(function () {
var self = Container.call(this);
// Array of existential quotes about space and humanity
var quotes = ["We are made of star stuff", "The universe is not only stranger than we imagine, it is stranger than we can imagine", "Two things are infinite: the universe and human stupidity", "We are all in the gutter, but some of us are looking at the stars", "The cosmos is within us. We are made of star-stuff", "Space is big. Really big. You just won't believe how vastly, hugely, mind-bogglingly big it is", "We are a way for the cosmos to know itself", "The Earth is the only world known so far to harbor life", "We are alone in the universe or we are not. Both are equally terrifying", "Look again at that dot. That's here. That's home. That's us", "The universe is under no obligation to make sense to you", "We came from nothing and we'll return to nothing", "In the vastness of space and the immensity of time, it is my joy to share a planet and an epoch with you"];
var randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
var quoteText = new Text2(randomQuote, {
size: 80,
fill: 0xFFFFFF
});
quoteText.alpha = 0.5; // 50% opacity
quoteText.anchor.set(0.5, 0.5);
self.addChild(quoteText);
self.speed = 0.3; // Slow movement speed
self.fadeDirection = 1;
self.update = function () {
self.y += self.speed;
// Subtle fade in and out effect
self.alpha += self.fadeDirection * 0.002;
if (self.alpha >= 0.5) {
self.fadeDirection = -1;
} else if (self.alpha <= 0.2) {
self.fadeDirection = 1;
}
// Remove when off screen
if (self.y > 2832) {
self.destroy();
}
};
return self;
});
var Spacecraft = Container.expand(function () {
var self = Container.call(this);
var body = self.attachAsset('spacecraft', {
anchorX: 0.5,
anchorY: 0.5
});
var flame = self.attachAsset('flame', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: 60
});
self.velocityX = 0;
self.velocityY = 0; // Start with no initial descent speed
self.thrust = 0;
self.maxThrust = 6;
self.thrustDecay = 0.9;
self.horizontalDamping = 0.95;
self.isLanded = false;
self.lastLanded = false;
flame.visible = false;
self.update = function () {
if (self.isLanded) return;
// Apply thrust and movement
self.velocityY -= self.thrust;
self.velocityX *= self.horizontalDamping;
self.thrust *= self.thrustDecay;
// Apply gravity (free fall) - reduce by 75% when mouse pressed
var gravityForce = mousePressed ? 0.0125 : 0.05;
self.velocityY += gravityForce;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Keep spacecraft in bounds horizontally
if (self.x < 40) {
self.x = 40;
self.velocityX = 0;
}
if (self.x > 2008) {
self.x = 2008;
self.velocityX = 0;
}
// Show flame when thrusting
flame.visible = self.thrust > 0.5;
// Check if crashed (hit bottom without landing)
if (self.y > 2650) {
self.crash();
}
// Check if rocket falls outside platform area
if (self.y > 2550 && currentPlatform) {
var platformLeft = currentPlatform.x - currentPlatform.landingZone / 2;
var platformRight = currentPlatform.x + currentPlatform.landingZone / 2;
if (self.x < platformLeft || self.x > platformRight) {
self.crash();
}
}
};
self.applyThrust = function (direction) {
self.thrust = Math.min(self.maxThrust, self.thrust + 0.03);
if (direction !== 0) {
self.velocityX += direction * 0.4;
}
LK.getSound('thrust').play();
};
self.crash = function () {
LK.effects.flashScreen(0xFF0000, 1000);
LK.getSound('crash').play();
LK.showGameOver();
};
self.land = function () {
if (!self.lastLanded && !self.isLanded) {
self.isLanded = true;
self.velocityX = 0;
self.velocityY = 0;
self.thrust = 0;
flame.visible = false;
LK.getSound('landing').play();
LK.effects.flashObject(self, 0x00FF00, 500);
// Increase score when landing on platform
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Show level complete effect and progress to next level
LK.effects.flashScreen(0x00FF00, 500);
// Reset for next level after delay
LK.setTimeout(function () {
currentLevel++;
self.reset();
spawnNewPlatform();
spawnObstacles();
}, 1500);
}
self.lastLanded = true;
};
self.reset = function () {
self.x = 1024;
self.y = 100;
self.velocityX = 0;
self.velocityY = 0; // Start with no velocity for free fall
self.thrust = 0;
self.isLanded = false;
self.lastLanded = false;
flame.visible = false;
};
return self;
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('stars', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 1 + 0.5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -10;
self.x = Math.random() * 2048;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0A0A0A
});
/****
* Game Code
****/
var spacecraft;
var currentPlatform;
var stars = [];
var planets = [];
var obstacles = [];
var quotes = []; // Track active quotes
var currentLevel = 1;
var mousePressed = false;
var lastMouseX = 1024;
var activePlanetTypes = {}; // Track which planet types are currently visible
// Create score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create instruction text
var instructionTxt = new Text2('Hold mouse to slow descent', {
size: 60,
fill: 0x888888
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 150;
LK.gui.top.addChild(instructionTxt);
// Initialize spacecraft
spacecraft = game.addChild(new Spacecraft());
spacecraft.x = 1024;
spacecraft.y = 100;
// Create background stars
for (var i = 0; i < 30; i++) {
var star = game.addChild(new Star());
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
}
// Create background planets
for (var i = 0; i < 3; i++) {
var planet = game.addChild(new Planet());
// Set initial position based on direction
if (planet.direction === 1) {
planet.x = Math.random() * 2048; // Left-to-right planets start anywhere
} else {
planet.x = Math.random() * 2048; // Right-to-left planets start anywhere
}
planet.y = Math.random() * 2732;
planets.push(planet);
activePlanetTypes[planet.planetType] = true; // Mark this planet type as active
}
function spawnObstacles() {
// Clear existing obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
// Spawn obstacles based on current level (more obstacles in higher levels)
var numObstacles = Math.min(currentLevel - 1, 5); // Start spawning from level 2
for (var i = 0; i < numObstacles; i++) {
var obstacle = game.addChild(new Obstacle());
obstacle.x = Math.random() * 1600 + 224;
obstacle.y = 1500 + Math.random() * 800; // Place between spacecraft start and platform
obstacles.push(obstacle);
// Start moving obstacles for levels 4 and above
if (currentLevel >= 4) {
obstacle.startMoving();
}
}
}
function spawnNewPlatform() {
if (currentPlatform) {
tween.stop(currentPlatform);
currentPlatform.destroy();
}
currentPlatform = game.addChild(new Platform());
currentPlatform.x = Math.random() * 1600 + 224; // Keep platforms away from edges
currentPlatform.y = 2600;
// Start moving platform for levels 3 and above
if (currentLevel >= 3) {
currentPlatform.startMoving();
}
}
// Spawn initial platform
spawnNewPlatform();
// Initialize obstacles
spawnObstacles();
// Create timer for random planet spawning
LK.setInterval(function () {
// 20% chance to spawn a new planet every 2 seconds
if (Math.random() < 0.2) {
var planet = game.addChild(new Planet());
// Only spawn if this planet type is not already active
if (!activePlanetTypes[planet.planetType]) {
// Set spawn position based on direction
if (planet.direction === 1) {
planet.x = -200; // Start from left side for left-to-right movement
} else {
planet.x = 2248; // Start from right side for right-to-left movement
}
planet.y = Math.random() * 2732; // Random Y position
planets.push(planet);
activePlanetTypes[planet.planetType] = true; // Mark this planet type as active
} else {
// Destroy the planet if its type is already active
planet.destroy();
}
}
}, 2000);
// Create timer for spawning existential quotes occasionally
LK.setInterval(function () {
// 15% chance to spawn a quote every 8 seconds
if (Math.random() < 0.15) {
var quote = game.addChild(new Quote());
quote.x = Math.random() * 1600 + 224; // Keep quotes centered in screen
quote.y = -100; // Start above screen
quotes.push(quote);
}
}, 8000);
// Mouse controls
game.down = function (x, y, obj) {
mousePressed = true;
lastMouseX = x;
};
game.up = function (x, y, obj) {
mousePressed = false;
};
game.move = function (x, y, obj) {
lastMouseX = x;
};
game.update = function () {
if (mousePressed && !spacecraft.isLanded) {
// Calculate thrust direction based on mouse position
var direction = 0;
if (lastMouseX < spacecraft.x - 50) {
direction = -1;
} else if (lastMouseX > spacecraft.x + 50) {
direction = 1;
}
spacecraft.applyThrust(direction);
}
// Check for collision with obstacles
for (var i = 0; i < obstacles.length; i++) {
if (spacecraft.intersects(obstacles[i]) && !spacecraft.isLanded) {
spacecraft.crash();
break;
}
}
// Check for landing
if (currentPlatform && !spacecraft.isLanded) {
spacecraft.lastLanded = false;
currentPlatform.checkLanding(spacecraft);
}
// Clean up planets that are too far off screen
for (var i = planets.length - 1; i >= 0; i--) {
if (planets[i].x > 2448 || planets[i].x < -400) {
// Clean up when they go off either edge
activePlanetTypes[planets[i].planetType] = false; // Mark planet type as inactive
planets[i].destroy();
planets.splice(i, 1);
}
}
// Clean up quotes that have moved off screen
for (var i = quotes.length - 1; i >= 0; i--) {
if (quotes[i].y > 2832) {
quotes[i].destroy();
quotes.splice(i, 1);
}
}
// Update score display
scoreTxt.setText(LK.getScore());
};
// Play background music when game starts
LK.playMusic('spacecords11'); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Randomly select one of 4 obstacle types
var obstacleTypes = ['obstacle', 'obstacle2', 'obstacle3', 'obstacle4'];
var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
var obstacleGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.originalX = 0;
self.originalY = 0;
// Start continuous slow rotation
function startRotation() {
tween(self, {
rotation: self.rotation + Math.PI * 2
}, {
duration: 8000,
easing: tween.linear,
onFinish: startRotation
});
}
startRotation();
self.startMoving = function () {
if (self.isMoving) return;
self.isMoving = true;
self.originalX = self.x;
self.originalY = self.y;
// Random movement pattern
var movementType = Math.floor(Math.random() * 3);
if (movementType === 0) {
// Horizontal movement
var moveLeft = function moveLeft() {
tween(self, {
x: self.originalX - 200
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: moveRight
});
};
var moveRight = function moveRight() {
tween(self, {
x: self.originalX + 200
}, {
duration: 3000,
easing: tween.easeInOut,
onFinish: moveLeft
});
};
moveLeft();
} else if (movementType === 1) {
// Vertical movement
var moveUp = function moveUp() {
tween(self, {
y: self.originalY - 150
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: moveDown
});
};
var moveDown = function moveDown() {
tween(self, {
y: self.originalY + 150
}, {
duration: 2500,
easing: tween.easeInOut,
onFinish: moveUp
});
};
moveUp();
} else {
var _circularMove = function circularMove() {
angle += 0.02;
var newX = self.originalX + Math.cos(angle) * radius;
var newY = self.originalY + Math.sin(angle) * radius;
tween(self, {
x: newX,
y: newY
}, {
duration: 100,
easing: tween.linear,
onFinish: _circularMove
});
};
// Circular movement
var angle = 0;
var radius = 100;
_circularMove();
}
};
return self;
});
var Planet = Container.expand(function () {
var self = Container.call(this);
// Randomly select one of 9 planet types
var planetTypes = ['planet1', 'planet2', 'planet3', 'planet4', 'planet5', 'planet6', 'planet7', 'planet8', 'planet9'];
var randomType = planetTypes[Math.floor(Math.random() * planetTypes.length)];
var planetGraphics = self.attachAsset(randomType, {
anchorX: 0.5,
anchorY: 0.5
});
// Set 25% opacity
planetGraphics.alpha = 0.25;
self.planetType = randomType; // Store the planet type for tracking
self.speed = Math.random() * 0.3 + 0.1; // Very slow movement
self.direction = Math.random() < 0.5 ? 1 : -1; // Random direction: 1 for left-to-right, -1 for right-to-left
self.update = function () {
self.x += self.speed * 2 * self.direction; // Move in random direction
// Reset planet when it goes off screen
if (self.direction === 1 && self.x > 2248) {
// Moving left-to-right, reset to left side
self.x = -200;
self.y = Math.random() * 2732; // Random Y position across screen height
} else if (self.direction === -1 && self.x < -200) {
// Moving right-to-left, reset to right side
self.x = 2248;
self.y = Math.random() * 2732; // Random Y position across screen height
}
};
return self;
});
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.landingZone = 180; // Safe landing zone width
self.isMoving = false;
self.startMoving = function () {
if (self.isMoving) return;
self.isMoving = true;
// Calculate speed based on current level (3% faster each level)
var speedMultiplier = Math.pow(1.03, currentLevel - 3); // Start from level 3
var baseDuration = 6000;
var moveDuration = baseDuration / speedMultiplier;
// Create continuous horizontal movement
function moveLeft() {
tween(self, {
x: 300
}, {
duration: moveDuration,
easing: tween.linear,
onFinish: moveRight
});
}
function moveRight() {
tween(self, {
x: 1748
}, {
duration: moveDuration,
easing: tween.linear,
onFinish: moveLeft
});
}
// Start movement cycle
if (self.x < 1024) {
moveRight();
} else {
moveLeft();
}
};
self.checkLanding = function (spacecraft) {
var dx = Math.abs(spacecraft.x - self.x);
var dy = Math.abs(spacecraft.y - self.y);
if (dx < self.landingZone / 2 && dy < 80) {
// Check if landing speed is safe
if (spacecraft.velocityY < 4 && Math.abs(spacecraft.velocityX) < 3) {
spacecraft.land();
return true;
} else {
spacecraft.crash();
return false;
}
}
return false;
};
return self;
});
var Quote = Container.expand(function () {
var self = Container.call(this);
// Array of existential quotes about space and humanity
var quotes = ["We are made of star stuff", "The universe is not only stranger than we imagine, it is stranger than we can imagine", "Two things are infinite: the universe and human stupidity", "We are all in the gutter, but some of us are looking at the stars", "The cosmos is within us. We are made of star-stuff", "Space is big. Really big. You just won't believe how vastly, hugely, mind-bogglingly big it is", "We are a way for the cosmos to know itself", "The Earth is the only world known so far to harbor life", "We are alone in the universe or we are not. Both are equally terrifying", "Look again at that dot. That's here. That's home. That's us", "The universe is under no obligation to make sense to you", "We came from nothing and we'll return to nothing", "In the vastness of space and the immensity of time, it is my joy to share a planet and an epoch with you"];
var randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
var quoteText = new Text2(randomQuote, {
size: 80,
fill: 0xFFFFFF
});
quoteText.alpha = 0.5; // 50% opacity
quoteText.anchor.set(0.5, 0.5);
self.addChild(quoteText);
self.speed = 0.3; // Slow movement speed
self.fadeDirection = 1;
self.update = function () {
self.y += self.speed;
// Subtle fade in and out effect
self.alpha += self.fadeDirection * 0.002;
if (self.alpha >= 0.5) {
self.fadeDirection = -1;
} else if (self.alpha <= 0.2) {
self.fadeDirection = 1;
}
// Remove when off screen
if (self.y > 2832) {
self.destroy();
}
};
return self;
});
var Spacecraft = Container.expand(function () {
var self = Container.call(this);
var body = self.attachAsset('spacecraft', {
anchorX: 0.5,
anchorY: 0.5
});
var flame = self.attachAsset('flame', {
anchorX: 0.5,
anchorY: 0,
x: 0,
y: 60
});
self.velocityX = 0;
self.velocityY = 0; // Start with no initial descent speed
self.thrust = 0;
self.maxThrust = 6;
self.thrustDecay = 0.9;
self.horizontalDamping = 0.95;
self.isLanded = false;
self.lastLanded = false;
flame.visible = false;
self.update = function () {
if (self.isLanded) return;
// Apply thrust and movement
self.velocityY -= self.thrust;
self.velocityX *= self.horizontalDamping;
self.thrust *= self.thrustDecay;
// Apply gravity (free fall) - reduce by 75% when mouse pressed
var gravityForce = mousePressed ? 0.0125 : 0.05;
self.velocityY += gravityForce;
// Update position
self.x += self.velocityX;
self.y += self.velocityY;
// Keep spacecraft in bounds horizontally
if (self.x < 40) {
self.x = 40;
self.velocityX = 0;
}
if (self.x > 2008) {
self.x = 2008;
self.velocityX = 0;
}
// Show flame when thrusting
flame.visible = self.thrust > 0.5;
// Check if crashed (hit bottom without landing)
if (self.y > 2650) {
self.crash();
}
// Check if rocket falls outside platform area
if (self.y > 2550 && currentPlatform) {
var platformLeft = currentPlatform.x - currentPlatform.landingZone / 2;
var platformRight = currentPlatform.x + currentPlatform.landingZone / 2;
if (self.x < platformLeft || self.x > platformRight) {
self.crash();
}
}
};
self.applyThrust = function (direction) {
self.thrust = Math.min(self.maxThrust, self.thrust + 0.03);
if (direction !== 0) {
self.velocityX += direction * 0.4;
}
LK.getSound('thrust').play();
};
self.crash = function () {
LK.effects.flashScreen(0xFF0000, 1000);
LK.getSound('crash').play();
LK.showGameOver();
};
self.land = function () {
if (!self.lastLanded && !self.isLanded) {
self.isLanded = true;
self.velocityX = 0;
self.velocityY = 0;
self.thrust = 0;
flame.visible = false;
LK.getSound('landing').play();
LK.effects.flashObject(self, 0x00FF00, 500);
// Increase score when landing on platform
LK.setScore(LK.getScore() + 10);
scoreTxt.setText(LK.getScore());
// Show level complete effect and progress to next level
LK.effects.flashScreen(0x00FF00, 500);
// Reset for next level after delay
LK.setTimeout(function () {
currentLevel++;
self.reset();
spawnNewPlatform();
spawnObstacles();
}, 1500);
}
self.lastLanded = true;
};
self.reset = function () {
self.x = 1024;
self.y = 100;
self.velocityX = 0;
self.velocityY = 0; // Start with no velocity for free fall
self.thrust = 0;
self.isLanded = false;
self.lastLanded = false;
flame.visible = false;
};
return self;
});
var Star = Container.expand(function () {
var self = Container.call(this);
var starGraphics = self.attachAsset('stars', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 1 + 0.5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.y = -10;
self.x = Math.random() * 2048;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x0A0A0A
});
/****
* Game Code
****/
var spacecraft;
var currentPlatform;
var stars = [];
var planets = [];
var obstacles = [];
var quotes = []; // Track active quotes
var currentLevel = 1;
var mousePressed = false;
var lastMouseX = 1024;
var activePlanetTypes = {}; // Track which planet types are currently visible
// Create score display
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create instruction text
var instructionTxt = new Text2('Hold mouse to slow descent', {
size: 60,
fill: 0x888888
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 150;
LK.gui.top.addChild(instructionTxt);
// Initialize spacecraft
spacecraft = game.addChild(new Spacecraft());
spacecraft.x = 1024;
spacecraft.y = 100;
// Create background stars
for (var i = 0; i < 30; i++) {
var star = game.addChild(new Star());
star.x = Math.random() * 2048;
star.y = Math.random() * 2732;
stars.push(star);
}
// Create background planets
for (var i = 0; i < 3; i++) {
var planet = game.addChild(new Planet());
// Set initial position based on direction
if (planet.direction === 1) {
planet.x = Math.random() * 2048; // Left-to-right planets start anywhere
} else {
planet.x = Math.random() * 2048; // Right-to-left planets start anywhere
}
planet.y = Math.random() * 2732;
planets.push(planet);
activePlanetTypes[planet.planetType] = true; // Mark this planet type as active
}
function spawnObstacles() {
// Clear existing obstacles
for (var i = 0; i < obstacles.length; i++) {
obstacles[i].destroy();
}
obstacles = [];
// Spawn obstacles based on current level (more obstacles in higher levels)
var numObstacles = Math.min(currentLevel - 1, 5); // Start spawning from level 2
for (var i = 0; i < numObstacles; i++) {
var obstacle = game.addChild(new Obstacle());
obstacle.x = Math.random() * 1600 + 224;
obstacle.y = 1500 + Math.random() * 800; // Place between spacecraft start and platform
obstacles.push(obstacle);
// Start moving obstacles for levels 4 and above
if (currentLevel >= 4) {
obstacle.startMoving();
}
}
}
function spawnNewPlatform() {
if (currentPlatform) {
tween.stop(currentPlatform);
currentPlatform.destroy();
}
currentPlatform = game.addChild(new Platform());
currentPlatform.x = Math.random() * 1600 + 224; // Keep platforms away from edges
currentPlatform.y = 2600;
// Start moving platform for levels 3 and above
if (currentLevel >= 3) {
currentPlatform.startMoving();
}
}
// Spawn initial platform
spawnNewPlatform();
// Initialize obstacles
spawnObstacles();
// Create timer for random planet spawning
LK.setInterval(function () {
// 20% chance to spawn a new planet every 2 seconds
if (Math.random() < 0.2) {
var planet = game.addChild(new Planet());
// Only spawn if this planet type is not already active
if (!activePlanetTypes[planet.planetType]) {
// Set spawn position based on direction
if (planet.direction === 1) {
planet.x = -200; // Start from left side for left-to-right movement
} else {
planet.x = 2248; // Start from right side for right-to-left movement
}
planet.y = Math.random() * 2732; // Random Y position
planets.push(planet);
activePlanetTypes[planet.planetType] = true; // Mark this planet type as active
} else {
// Destroy the planet if its type is already active
planet.destroy();
}
}
}, 2000);
// Create timer for spawning existential quotes occasionally
LK.setInterval(function () {
// 15% chance to spawn a quote every 8 seconds
if (Math.random() < 0.15) {
var quote = game.addChild(new Quote());
quote.x = Math.random() * 1600 + 224; // Keep quotes centered in screen
quote.y = -100; // Start above screen
quotes.push(quote);
}
}, 8000);
// Mouse controls
game.down = function (x, y, obj) {
mousePressed = true;
lastMouseX = x;
};
game.up = function (x, y, obj) {
mousePressed = false;
};
game.move = function (x, y, obj) {
lastMouseX = x;
};
game.update = function () {
if (mousePressed && !spacecraft.isLanded) {
// Calculate thrust direction based on mouse position
var direction = 0;
if (lastMouseX < spacecraft.x - 50) {
direction = -1;
} else if (lastMouseX > spacecraft.x + 50) {
direction = 1;
}
spacecraft.applyThrust(direction);
}
// Check for collision with obstacles
for (var i = 0; i < obstacles.length; i++) {
if (spacecraft.intersects(obstacles[i]) && !spacecraft.isLanded) {
spacecraft.crash();
break;
}
}
// Check for landing
if (currentPlatform && !spacecraft.isLanded) {
spacecraft.lastLanded = false;
currentPlatform.checkLanding(spacecraft);
}
// Clean up planets that are too far off screen
for (var i = planets.length - 1; i >= 0; i--) {
if (planets[i].x > 2448 || planets[i].x < -400) {
// Clean up when they go off either edge
activePlanetTypes[planets[i].planetType] = false; // Mark planet type as inactive
planets[i].destroy();
planets.splice(i, 1);
}
}
// Clean up quotes that have moved off screen
for (var i = quotes.length - 1; i >= 0; i--) {
if (quotes[i].y > 2832) {
quotes[i].destroy();
quotes.splice(i, 1);
}
}
// Update score display
scoreTxt.setText(LK.getScore());
};
// Play background music when game starts
LK.playMusic('spacecords11');
one windowed red and white space ship with 4 legs with flame under it. In-Game asset. 2d. High contrast. No shadows
random asteroid stone. In-Game asset. 2d. High contrast. No shadows
star shaped random asteroid stone. In-Game asset. 2d. High contrast. No shadows
rocket landing platform. In-Game asset. 2d. High contrast. No shadows
rocket flame but only flame. In-Game asset. 2d. High contrast. No shadows
white shiny star. In-Game asset. 2d. High contrast. No shadows
realistic saturn. In-Game asset. 2d. High contrast. No shadows
realistic milky way. In-Game asset. 2d. High contrast. No shadows
realistic milky way. In-Game asset. 2d. High contrast. No shadows
mercury realistic. In-Game asset. 2d. High contrast. No shadows
earth realistic. In-Game asset. 2d. High contrast. No shadows
random galaxies realistic. In-Game asset. 2d. High contrast. No shadows
realistic sun. In-Game asset. 2d. High contrast. No shadows
realistic pluton. In-Game asset. 2d. High contrast. No shadows