Code edit (7 edits merged)
Please save this source code
User prompt
create a graphic for the RevolvingPlanet
Code edit (2 edits merged)
Please save this source code
User prompt
fix the issue
User prompt
some planets have planets revolving around them
User prompt
show the UI score
User prompt
show the score on top
Code edit (1 edits merged)
Please save this source code
User prompt
add a speech bubble to the player when it is jumping
User prompt
20% of the planets have planets revolving around them
User prompt
20% of the planets have planets revolving around them
User prompt
make a background image
User prompt
make some planets move faster
Code edit (1 edits merged)
Please save this source code
User prompt
when planets respawn on top, make sure they have at least player's width margin to the game sides
User prompt
adjust the planet radius based on the scale
User prompt
scale the planet size randomly from 20 to 100%
User prompt
make the planets have different sizes
User prompt
every time the player collides with a planet and is onGround, the score should increase
User prompt
in the planet update method. If the planet moved out of the screen, it should appear on top again with a different x position - randomly
Code edit (2 edits merged)
Please save this source code
User prompt
if the player jumped, move it into the direction it jumped from
Code edit (2 edits merged)
Please save this source code
User prompt
only revolve the player around the planet if it is not currently jumping from it
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // Assets will be automatically created based on usage in the code. // Planet class for the planets the player will jump between var Planet = Container.expand(function () { var self = Container.call(this); var planetGraphics = self.attachAsset('planet', { anchorX: 0.5, anchorY: 0.5 }); // Scale the planet size randomly from 20 to 100% var scale = Math.random() * 0.8 + 0.2; // Generate a random scale between 0.2 (20%) and 1.0 (100%) planetGraphics.scale.set(scale, scale); // Apply the scale to the planet self.radius = planetGraphics.width / 2 * scale; // Adjust the planet radius based on the scale self.update = function () { self.y += self.speed; // Move the planet down each tick if (self.y > 2732 + self.height / 2) { // If the planet moved out of the screen self.y = -self.height / 2; // It should appear on top again self.x = Math.random() * (2048 - player.width * 2) + player.width; // With a different x position - randomly, ensuring at least player's width margin to the game sides } }; self.speed = Math.random() * 3 + 2; // Assign a random speed between 2 and 5 to each planet }); // PlanetWithMoon class for the planets with revolving planets var PlanetWithMoon = Planet.expand(function () { var self = Planet.call(this); // Create a smaller planet that will revolve around the main planet var moon = new Planet(); moon.scale.set(0.5, 0.5); // Make the moon half the size of the planet moon.speed = 0; // The moon doesn't move down self.addChild(moon); self.moon = moon; var originalUpdate = self.update; self.update = function () { originalUpdate.call(this); // Make the moon revolve around the planet var angle = LK.ticks / 60; // One full revolution every second self.moon.x = self.radius * Math.cos(angle); self.moon.y = self.radius * Math.sin(angle); }; }); // Player class for the main character var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.onGround = false; self.velocity = { x: 0, y: 0 }; self.jump = function (power, angle) { if (self.onGround) { self.velocity.x = power * Math.cos(angle); self.velocity.y = power * Math.sin(angle); self.onGround = false; } }; self.update = function () { self.x += self.velocity.x; self.y += self.velocity.y; self.velocity.y += 0.98; // Gravity effect }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var planets = []; var background = game.attachAsset('background', { anchorX: 0.0, anchorY: 0.0 }); var player; var jumpPower = 20; var currentPlanet; function setupGame() { // Create player player = new Player(); player.x = 1024; // Start in the middle of the screen horizontally player.y = 1366; // Start in the middle of the screen vertically game.addChild(player); // Create planets for (var i = 0; i < 8; i++) { var planet; // 20% of the planets have planets revolving around them if (Math.random() < 0.2) { planet = new PlanetWithMoon(); } else { planet = new Planet(); } planet.x = Math.random() * (2048 - player.width) + player.width / 2; // Ensure planet's x position leaves some margin of the player's width to the screens side planet.y = Math.random() * 2732; game.addChild(planet); planets.push(planet); // Check if any planets have moved off the bottom of the screen for (var j = planets.length - 1; j >= 0; j--) { if (planets[j].y > 2732 + planets[j].height / 2) { // Remove the planet from the game and the planets array game.removeChild(planets[j]); planets.splice(j, 1); // Spawn a new planet at the top of the screen var newPlanet = new Planet(); newPlanet.x = Math.random() * 2048; newPlanet.y = -newPlanet.height / 2; game.addChild(newPlanet); planets.push(newPlanet); } } } // Create player planets[0].x = 1024; // Start the first planet in the middle of the screen horizontally planets[0].y = 1366; // Start the first planet in the middle of the screen vertically currentPlanet = planets[0]; // Setup touch event to make the player jump game.on('down', function (obj) { var dx = player.x - currentPlanet.x; var dy = player.y - currentPlanet.y; var angle = Math.atan2(dy, dx); currentPlanet = null; player.jump(jumpPower, angle); }); } function checkCollisions() { planets.forEach(function (planet) { var dx = player.x - planet.x; var dy = player.y - planet.y; var distance = Math.sqrt(dx * dx + dy * dy); var collision = distance < player.width / 2 + planet.radius; if (planet instanceof PlanetWithMoon) { // Check collision with the moon dx = player.x - (planet.x + planet.moon.x); dy = player.y - (planet.y + planet.moon.y); distance = Math.sqrt(dx * dx + dy * dy); collision = collision || distance < player.width / 2 + planet.moon.radius; } if (collision) { if (!player.onGround) { // Increase score when player lands on a planet LK.setScore(LK.getScore() + 1); } player.onGround = true; player.velocity.y = 0; currentPlanet = planet; } }); } LK.on('tick', function () { if (!player.onGround) { player.x += player.velocity.x; player.y += player.velocity.y; } else { if (currentPlanet) { var dx = player.x - currentPlanet.x; var dy = player.y - currentPlanet.y; var distance = Math.sqrt(dx * dx + dy * dy); var angle = Math.atan2(dy, dx); player.x = currentPlanet.x + (currentPlanet.radius + player.width / 2) * Math.cos(angle + 0.1); player.y = currentPlanet.y + (currentPlanet.radius + player.width / 2) * Math.sin(angle + 0.1); } } planets.forEach(function (planet) { planet.update(); }); checkCollisions(); // Check if the player is out of the screen if (player.x < 0 || player.x > 2048 || player.y < 0 || player.y > 2732) { // End the game LK.showGameOver(); } }); setupGame();
===================================================================
--- original.js
+++ change.js
@@ -22,22 +22,24 @@
}
};
self.speed = Math.random() * 3 + 2; // Assign a random speed between 2 and 5 to each planet
});
-// RevolvingPlanet class for the planets that revolve around other planets
-var RevolvingPlanet = Planet.expand(function () {
+// PlanetWithMoon class for the planets with revolving planets
+var PlanetWithMoon = Planet.expand(function () {
var self = Planet.call(this);
- self.angle = Math.random() * Math.PI * 2; // Random initial angle
- self.speed = Math.random() * 0.02 + 0.01; // Random speed between 0.01 and 0.03
- self.distance = self.radius + Math.random() * self.radius + player.width; // Random distance from the center planet
- self.centerPlanet = null; // The planet this planet is revolving around
+ // Create a smaller planet that will revolve around the main planet
+ var moon = new Planet();
+ moon.scale.set(0.5, 0.5); // Make the moon half the size of the planet
+ moon.speed = 0; // The moon doesn't move down
+ self.addChild(moon);
+ self.moon = moon;
+ var originalUpdate = self.update;
self.update = function () {
- self.angle += self.speed; // Update the angle
- if (self.centerPlanet) {
- // Update the position based on the angle, distance and the position of the center planet
- self.x = self.centerPlanet.x + Math.cos(self.angle) * self.distance;
- self.y = self.centerPlanet.y + Math.sin(self.angle) * self.distance;
- }
+ originalUpdate.call(this);
+ // Make the moon revolve around the planet
+ var angle = LK.ticks / 60; // One full revolution every second
+ self.moon.x = self.radius * Math.cos(angle);
+ self.moon.y = self.radius * Math.sin(angle);
};
});
// Player class for the main character
var Player = Container.expand(function () {
@@ -91,33 +93,30 @@
game.addChild(player);
// Create planets
for (var i = 0; i < 8; i++) {
var planet;
+ // 20% of the planets have planets revolving around them
if (Math.random() < 0.2) {
- // 20% chance to create a revolving planet
- planet = new RevolvingPlanet();
- // Find a random planet to be the center planet
- var centerPlanet = planets[Math.floor(Math.random() * planets.length)];
- planet.centerPlanet = centerPlanet;
+ planet = new PlanetWithMoon();
} else {
planet = new Planet();
- // Check if any planets have moved off the bottom of the screen
- for (var j = planets.length - 1; j >= 0; j--) {
- if (planets[j].y > 2732 + planets[j].height / 2) {
- // Remove the planet from the game and the planets array
- game.removeChild(planets[j]);
- planets.splice(j, 1);
- // Spawn a new planet at the top of the screen
- var newPlanet = new Planet();
- newPlanet.x = Math.random() * 2048;
- newPlanet.y = -newPlanet.height / 2;
- game.addChild(newPlanet);
- planets.push(newPlanet);
- }
- planet.x = Math.random() * (2048 - player.width) + player.width / 2; // Ensure planet's x position leaves some margin of the player's width to the screens side
- planet.y = Math.random() * 2732;
- game.addChild(planet);
- planets.push(planet);
+ }
+ planet.x = Math.random() * (2048 - player.width) + player.width / 2; // Ensure planet's x position leaves some margin of the player's width to the screens side
+ planet.y = Math.random() * 2732;
+ game.addChild(planet);
+ planets.push(planet);
+ // Check if any planets have moved off the bottom of the screen
+ for (var j = planets.length - 1; j >= 0; j--) {
+ if (planets[j].y > 2732 + planets[j].height / 2) {
+ // Remove the planet from the game and the planets array
+ game.removeChild(planets[j]);
+ planets.splice(j, 1);
+ // Spawn a new planet at the top of the screen
+ var newPlanet = new Planet();
+ newPlanet.x = Math.random() * 2048;
+ newPlanet.y = -newPlanet.height / 2;
+ game.addChild(newPlanet);
+ planets.push(newPlanet);
}
}
}
// Create player
@@ -137,9 +136,17 @@
planets.forEach(function (planet) {
var dx = player.x - planet.x;
var dy = player.y - planet.y;
var distance = Math.sqrt(dx * dx + dy * dy);
- if (distance < player.width / 2 + planet.radius) {
+ var collision = distance < player.width / 2 + planet.radius;
+ if (planet instanceof PlanetWithMoon) {
+ // Check collision with the moon
+ dx = player.x - (planet.x + planet.moon.x);
+ dy = player.y - (planet.y + planet.moon.y);
+ distance = Math.sqrt(dx * dx + dy * dy);
+ collision = collision || distance < player.width / 2 + planet.moon.radius;
+ }
+ if (collision) {
if (!player.onGround) {
// Increase score when player lands on a planet
LK.setScore(LK.getScore() + 1);
}
planet. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. transparent background
monkey astronaut. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. transparent background
space background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. transparent background
speech bubble saying "wee". game asset. 2d. 8bit. no background. transparent background.
banana. game asset. 2d. 8bit. no background. transparent background.