User prompt
Add objects background effects ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add the music
User prompt
Too laggy
User prompt
Please fix the bug: 'TypeError: statusText.setFill is not a function' in or related to this line: 'statusText.style.fill = "#33ff33";' Line Number: 303
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'statusText.setFill("#33ff33");' Line Number: 303
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'statusText.style.fill = "#33ff33";' Line Number: 305
User prompt
then play the game
User prompt
In Correct Orbit
Initial prompt
In correct orbit
/****
* Classes
****/
// Orbit trail visualization
var OrbitTrail = Container.expand(function () {
var self = Container.call(this);
// Draw the satellite's trail
self.drawTrail = function (points) {
self.removeChildren();
if (points.length < 2) return;
for (var i = 1; i < points.length; i++) {
var p1 = points[i - 1];
var p2 = points[i];
// Create a small dot for each trail point
var dot = LK.getAsset('TrailDot', {
anchorX: 0.5,
anchorY: 0.5,
x: p2.x,
y: p2.y,
alpha: i / points.length * 0.7
});
dot.scaleX = 0.1;
dot.scaleY = 0.1;
self.addChild(dot);
}
};
return self;
});
// Initialize game variables
// Planet class for the gravitational body
var Planet = Container.expand(function () {
var self = Container.call(this);
// Create planet graphics
var planetGraphics = self.attachAsset('Planet', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
// Orbit zones
self.safeOrbitMin = 200; // Minimum safe orbit distance
self.safeOrbitMax = 500; // Maximum safe orbit distance
self.gravity = 0.15; // Gravity strength
// Visual indicators for orbit zones
var orbitZone = self.addChild(new Container());
// Initialize orbit visualization
self.initOrbitZones = function () {
// Create outer safe orbit zone
var outerZone = LK.getAsset('OrbitZone', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
alpha: 0.1
});
outerZone.scaleX = self.safeOrbitMax * 2 / 100;
outerZone.scaleY = self.safeOrbitMax * 2 / 100;
orbitZone.addChild(outerZone);
// Create inner safe orbit zone
var innerZone = LK.getAsset('OrbitZone', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 0,
alpha: 0.1
});
innerZone.scaleX = self.safeOrbitMin * 2 / 100;
innerZone.scaleY = self.safeOrbitMin * 2 / 100;
orbitZone.addChild(innerZone);
};
// Apply gravity to a satellite
self.applyGravityTo = function (satellite) {
// Calculate direction from satellite to planet
var dx = self.x - satellite.x;
var dy = self.y - satellite.y;
// Calculate distance (squared for efficiency)
var distSquared = dx * dx + dy * dy;
var distance = Math.sqrt(distSquared);
// Only apply gravity if not too close
if (distance > 10) {
// Calculate gravity force (inverse square law)
var force = self.gravity / distance;
// Apply force to satellite velocity
satellite.velocity.x += dx / distance * force;
satellite.velocity.y += dy / distance * force;
}
return distance;
};
return self;
});
// Satellite class for the player-controlled object
var Satellite = Container.expand(function () {
var self = Container.call(this);
// Create satellite graphics
var satelliteGraphics = self.attachAsset('Planet2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
// Physics properties
self.velocity = {
x: 0,
y: 0
};
self.lastX = 0;
self.lastY = 0;
self.isDragging = false;
self.thrustDirection = {
x: 0,
y: 0
};
self.thrustPower = 0;
self.maxThrust = 0.5;
// Trail effect
self.trailPoints = [];
self.maxTrailPoints = 50;
// Show thrust line when dragging
self.thrustLine = self.addChild(new Container());
// Initialize with a small orbit velocity
self.initOrbit = function (planetX, planetY) {
// Set initial position
self.x = planetX;
self.y = planetY - 300;
self.lastX = self.x;
self.lastY = self.y;
// Set initial velocity for orbit (perpendicular to planet)
self.velocity.x = 2;
self.velocity.y = 0;
};
// Update satellite position based on physics
self.update = function () {
// Store last position
self.lastX = self.x;
self.lastY = self.y;
// Add thrust if dragging
if (self.isDragging && self.thrustPower > 0) {
self.velocity.x += self.thrustDirection.x * self.thrustPower;
self.velocity.y += self.thrustDirection.y * self.thrustPower;
}
// Update position based on velocity
self.x += self.velocity.x;
self.y += self.velocity.y;
// Update trail
self.updateTrail();
// Update thrust visualization
self.updateThrustLine();
};
// Add a point to the trail
self.updateTrail = function () {
if (LK.ticks % 3 === 0) {
self.trailPoints.push({
x: self.x,
y: self.y
});
if (self.trailPoints.length > self.maxTrailPoints) {
self.trailPoints.shift();
}
}
};
// Update the thrust line visualization
self.updateThrustLine = function () {
self.thrustLine.removeChildren();
if (self.isDragging && self.thrustPower > 0) {
// Create a line showing thrust direction
var line = LK.getAsset('ThrustLine', {
anchorX: 0,
anchorY: 0.5,
x: 0,
y: 0
});
line.rotation = Math.atan2(-self.thrustDirection.y, -self.thrustDirection.x);
line.scaleX = self.thrustPower * 50;
self.thrustLine.addChild(line);
}
};
// Start applying thrust
self.startThrust = function (x, y) {
self.isDragging = true;
self.updateThrustVector(x, y);
};
// Update thrust direction and power while dragging
self.updateThrustVector = function (x, y) {
if (self.isDragging) {
// Calculate thrust direction from satellite to touch point
var dx = self.x - x;
var dy = self.y - y;
// Calculate distance
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > 0) {
// Normalize direction vector
self.thrustDirection.x = dx / distance;
self.thrustDirection.y = dy / distance;
// Scale thrust power by distance, capped at maxThrust
self.thrustPower = Math.min(distance / 100, self.maxThrust);
}
}
};
// Stop applying thrust
self.endThrust = function () {
self.isDragging = false;
self.thrustPower = 0;
self.thrustDirection.x = 0;
self.thrustDirection.y = 0;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Initialize game variables
var planet;
var satellite;
var orbitTrail;
var gameStarted = false;
var gameOver = false;
var timeInOrbit = 0;
var scoreText;
var statusText;
var dragStartPos = {
x: 0,
y: 0
};
// Set up the game environment
function setupGame() {
// Set space background
game.setBackgroundColor(0x000022);
// Create and position the planet in center
planet = new Planet();
planet.x = 2048 / 2;
planet.y = 2732 / 2;
planet.initOrbitZones();
game.addChild(planet);
// Create satellite
satellite = new Satellite();
satellite.initOrbit(planet.x, planet.y);
game.addChild(satellite);
// Create orbit trail
orbitTrail = new OrbitTrail();
game.addChild(orbitTrail);
// Create score display
scoreText = new Text2('Time in orbit: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
scoreText.y = 50;
LK.gui.top.addChild(scoreText);
// Create status text
statusText = new Text2('Tap and drag to apply thrust', {
size: 50,
fill: 0xFFFFFF
});
statusText.anchor.set(0.5, 1);
statusText.y = -50;
LK.gui.bottom.addChild(statusText);
// Start the game
gameStarted = true;
}
// Update game state each frame
game.update = function () {
if (!gameStarted) {
setupGame();
return;
}
if (gameOver) return;
// Update satellite physics
satellite.update();
// Apply planet's gravity to the satellite
var distance = planet.applyGravityTo(satellite);
// Check if satellite is in safe orbit
var inSafeOrbit = distance >= planet.safeOrbitMin && distance <= planet.safeOrbitMax;
// Update time in orbit if in safe zone
if (inSafeOrbit) {
if (LK.ticks % 60 === 0) {
// Increase score every second
timeInOrbit++;
scoreText.setText('Time in orbit: ' + timeInOrbit);
LK.setScore(timeInOrbit);
}
statusText.setText('Stable orbit: ' + Math.round(distance));
statusText.setFill("#33ff33");
} else if (distance < planet.safeOrbitMin) {
statusText.setText('Warning: Orbit too close!');
statusText.setFill("#ff3333");
} else if (distance > planet.safeOrbitMax) {
statusText.setText('Warning: Orbit too far!');
statusText.setFill("#ff9933");
}
// Check for crash into planet
if (distance < 70) {
// Planet radius is approximately 75px
endGame("Crash landing!");
}
// Check if satellite has gone too far from the planet
if (distance > 1500) {
endGame("Satellite lost in space");
}
// Draw orbit trail
orbitTrail.drawTrail(satellite.trailPoints);
};
// Handle touch/mouse down on game
game.down = function (x, y, obj) {
if (gameOver) return;
dragStartPos.x = x;
dragStartPos.y = y;
// Start applying thrust
satellite.startThrust(x, y);
};
// Handle touch/mouse move on game
game.move = function (x, y, obj) {
if (gameOver) return;
// Update thrust vector
satellite.updateThrustVector(x, y);
};
// Handle touch/mouse up on game
game.up = function (x, y, obj) {
if (gameOver) return;
// Stop applying thrust
satellite.endThrust();
};
// End the game with a specific message
function endGame(message) {
gameOver = true;
statusText.setText(message);
statusText.setFill("#ff0000");
// Flash screen and show game over
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
}
// Setup game
setupGame(); ===================================================================
--- original.js
+++ change.js
@@ -286,15 +286,15 @@
scoreText.setText('Time in orbit: ' + timeInOrbit);
LK.setScore(timeInOrbit);
}
statusText.setText('Stable orbit: ' + Math.round(distance));
- statusText.style.fill = "#33ff33";
+ statusText.setFill("#33ff33");
} else if (distance < planet.safeOrbitMin) {
statusText.setText('Warning: Orbit too close!');
- statusText.style.fill = "#ff3333";
+ statusText.setFill("#ff3333");
} else if (distance > planet.safeOrbitMax) {
statusText.setText('Warning: Orbit too far!');
- statusText.style.fill = "#ff9933";
+ statusText.setFill("#ff9933");
}
// Check for crash into planet
if (distance < 70) {
// Planet radius is approximately 75px
@@ -330,9 +330,9 @@
// End the game with a specific message
function endGame(message) {
gameOver = true;
statusText.setText(message);
- statusText.style.fill = "#ff0000";
+ statusText.setFill("#ff0000");
// Flash screen and show game over
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();