Initial prompt
Planet jumper
User prompt
make the player revolve around the first planet
User prompt
on click, the player jumps away from the planet
User prompt
make all planets move down. Spawn new planets from the top
User prompt
if the player is out of the screen, then the game is over
User prompt
the first planet should start in the center of the screen
User prompt
planets x position should leave some margin of the player's width to the screens side
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'width')' in or related to this line: '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' Line Number: 68
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 (2 edits merged)
Please save this source code
User prompt
if the player jumped, move it into the direction it jumped from
Code edit (1 edits merged)
Please save this source code
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
User prompt
every time the player collides with a planet and is onGround, the score should increase
User prompt
make the planets have different sizes
User prompt
scale the planet size randomly from 20 to 100%
User prompt
adjust the planet radius based on the scale
User prompt
when planets respawn on top, make sure they have at least player's width margin to the game sides
Code edit (1 edits merged)
Please save this source code
User prompt
make some planets move faster
User prompt
make a background image
User prompt
20% of the planets have planets revolving around them
User prompt
20% of the planets have planets revolving around them
User prompt
add a speech bubble to the player when it is jumping
===================================================================
--- original.js
+++ change.js
@@ -1,90 +1,97 @@
-/****
+/****
* 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
- });
- self.radius = planetGraphics.width / 2; // Assuming the planet is a circle and asset is its visual representation
+ var self = Container.call(this);
+ var planetGraphics = self.attachAsset('planet', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.radius = planetGraphics.width / 2; // Assuming the planet is a circle and asset is its visual representation
});
// 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) {
- if (self.onGround) {
- self.velocity.y = -power;
- self.onGround = false;
- }
- };
- self.update = function () {
- self.x += self.velocity.x;
- self.y += self.velocity.y;
- self.velocity.y += 0.98; // Gravity effect
- };
+ 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) {
+ if (self.onGround) {
+ self.velocity.y = -power;
+ 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
+ backgroundColor: 0x000000 // Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
var planets = [];
var player;
var jumpPower = 20;
+var currentPlanet;
function setupGame() {
- // Create planets
- for (var i = 0; i < 5; i++) {
- var planet = new Planet();
- planet.x = Math.random() * 2048;
- planet.y = Math.random() * 2732;
- game.addChild(planet);
- planets.push(planet);
- }
- // 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);
- // Setup touch event to make the player jump
- game.on('down', function (obj) {
- var event = obj.event;
- var pos = event.getLocalPosition(game);
- var angle = Math.atan2(pos.y - player.y, pos.x - player.x);
- player.velocity.x = jumpPower * Math.cos(angle);
- player.velocity.y = jumpPower * Math.sin(angle);
- });
+ // Create planets
+ for (var i = 0; i < 5; i++) {
+ var planet = new Planet();
+ planet.x = Math.random() * 2048;
+ planet.y = Math.random() * 2732;
+ game.addChild(planet);
+ planets.push(planet);
+ }
+ // 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);
+ currentPlanet = planets[0];
+ // Setup touch event to make the player jump
+ game.on('down', function (obj) {
+ var event = obj.event;
+ var pos = event.getLocalPosition(game);
+ var angle = Math.atan2(pos.y - player.y, pos.x - player.x);
+ player.velocity.x = jumpPower * Math.cos(angle);
+ player.velocity.y = jumpPower * Math.sin(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);
- if (distance < player.width / 2 + planet.radius) {
- player.onGround = true;
- player.velocity.y = 0;
- }
- });
+ 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) {
+ player.onGround = true;
+ player.velocity.y = 0;
+ }
+ });
}
LK.on('tick', function () {
- player.update();
- checkCollisions();
+ 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.01);
+ player.y = currentPlanet.y + (currentPlanet.radius + player.width / 2) * Math.sin(angle + 0.01);
+ checkCollisions();
});
setupGame();
\ No newline at end of file
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.