User prompt
20% of the planets have planets revolving around them
User prompt
add a speech bubble to the player when it is jumping
Code edit (2 edits merged)
Please save this source code
User prompt
show the score on top
User prompt
show the UI score
User prompt
some planets have planets revolving around them
User prompt
fix the issue
Code edit (7 edits merged)
Please save this source code
User prompt
create a graphic for the RevolvingPlanet
Code edit (5 edits merged)
Please save this source code
User prompt
scale the revolvingplanet half to the size of the parentplanet
Code edit (2 edits merged)
Please save this source code
User prompt
make the player also collide with the revolvingplanet, just like the planet
User prompt
fix that the speechbubble is shown
User prompt
if the player hits a revolvingplanet, increase the score
User prompt
set the revolvingplanet to visible false, if the player collides with it
Code edit (4 edits merged)
Please save this source code
User prompt
Only check collision with planets which are visible
User prompt
if the revolvingplanet.parentPlanet respawns make sure to make it visible again
Code edit (1 edits merged)
Please save this source code
User prompt
Migrate to the latest version of LK
User prompt
play the jump sound whenver the player jumps
User prompt
add a sound "collect" and play it when the player collides with the revolvingplanet
User prompt
play a sound gameover when the game is over
User prompt
play a sound impact when the player collides lands on a planet
===================================================================
--- original.js
+++ change.js
@@ -22,26 +22,8 @@
}
};
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', {
@@ -52,8 +34,13 @@
self.velocity = {
x: 0,
y: 0
};
+ self.speechBubble = self.attachAsset('speechBubble', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ self.speechBubble.visible = false;
self.jump = function (power, angle) {
if (self.onGround) {
self.velocity.x = power * Math.cos(angle);
self.velocity.y = power * Math.sin(angle);
@@ -63,8 +50,9 @@
self.update = function () {
self.x += self.velocity.x;
self.y += self.velocity.y;
self.velocity.y += 0.98; // Gravity effect
+ self.speechBubble.visible = true;
};
});
/****
@@ -92,15 +80,9 @@
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();
- }
+ var 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);
@@ -136,24 +118,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);
- 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 (distance < player.width / 2 + planet.radius) {
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;
+ player.speechBubble.visible = false;
}
});
}
LK.on('tick', function () {
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.