Code edit (6 edits merged)
Please save this source code
User prompt
accelerate the run animation
Code edit (3 edits merged)
Please save this source code
User prompt
use ninjaRun, ninjaRun2 and ninjaRun3 to animate ninja running
User prompt
add ninjaRun2 and ninjaRun3 in Ninja class
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: clouds is not defined' in or related to this line: 'clouds.children.forEach(function (cloud) {' Line Number: 475
User prompt
add the paralax movement to the clouds too
Code edit (1 edits merged)
Please save this source code
User prompt
make clouds move slowly to the left the re-appear from the right
Code edit (3 edits merged)
Please save this source code
User prompt
add clouds at init time
User prompt
add a class clouds to the game
Code edit (4 edits merged)
Please save this source code
User prompt
extract the code of update when isReturningToBase to a separate method
Code edit (1 edits merged)
Please save this source code
User prompt
midground1 and foreground2 should only move when platforms move
User prompt
use NINJA_MOVEMENT_SPEED in handleBackgroundMovement
Code edit (2 edits merged)
Please save this source code
User prompt
when ninja runs, apply the same ratios to foreground and midground movement as when returning to base
Code edit (2 edits merged)
Please save this source code
User prompt
Loop: true doesnβt work. Use lk.setinterval with value 500
User prompt
Repeat the run sound while running, stop it when stops running
User prompt
Play stick grow sound when stick grows and stop it when stops
User prompt
Foreground and midground should also move when returning to base
===================================================================
--- original.js
+++ change.js
@@ -86,8 +86,39 @@
/****
* Game Code
****/
+function handleReturningToBase() {
+ var distanceToMove = basePlatformX - platformCurrent.x;
+ var moveSpeed = 10; // Adjust the speed as needed
+ if (Math.abs(distanceToMove) <= moveSpeed) {
+ // If the distance to move is less than or equal to the move speed, snap to position
+ platformCurrent.x = basePlatformX;
+ platformTarget.x += distanceToMove;
+ //platformNext.x += distanceToMove;
+ ninja.x += distanceToMove;
+ stick.x += distanceToMove;
+ foreground1.x += distanceToMove * 1.5;
+ foreground2.x += distanceToMove * 1.5;
+ midground1.x += distanceToMove * 0.5;
+ midground2.x += distanceToMove * 0.5;
+ isReturningToBase = false; // Stop moving objects
+ } else {
+ // Move objects towards the base position
+ platformCurrent.x += moveSpeed * Math.sign(distanceToMove);
+ platformTarget.x += moveSpeed * Math.sign(distanceToMove);
+ platformNext.x += moveSpeed * Math.sign(distanceToMove) * (platformNext.speedRatio || 1);
+ if (platformNext.x - platformNext.width < 2048) {
+ platformNext.x = 2048 + platformNext.width;
+ }
+ ninja.x += moveSpeed * Math.sign(distanceToMove);
+ stick.x += moveSpeed * Math.sign(distanceToMove);
+ foreground1.x += moveSpeed * Math.sign(distanceToMove) * 1.5;
+ foreground2.x += moveSpeed * Math.sign(distanceToMove) * 1.5;
+ midground1.x += moveSpeed * Math.sign(distanceToMove) * 0.5;
+ midground2.x += moveSpeed * Math.sign(distanceToMove) * 0.5;
+ }
+}
// Initialize game variables
var platformMinWidth = 100;
var level = 1; // Initialize the level variable
var platformMaxWidth = 400;
@@ -333,13 +364,13 @@
}
}
function handleBackgroundMovement() {
// Move midground images to the left
- midground1.x -= 5;
- midground2.x -= 5;
+ midground1.x += NINJA_MOVEMENT_SPEED * 0.8;
+ midground2.x += NINJA_MOVEMENT_SPEED * 0.8;
// Move foreground images to the left
- foreground1.x -= 15;
- foreground2.x -= 15;
+ foreground1.x += NINJA_MOVEMENT_SPEED * 1.5;
+ foreground2.x += NINJA_MOVEMENT_SPEED * 1.5;
// Reset midground position to create an infinite scrolling effect
if (midground1.x + 2048 / 2 < 0) {
midground1.x = midground2.x + 2048;
}
@@ -413,37 +444,9 @@
if (isNinjaMoving) {
moveNinja();
}
if (isReturningToBase) {
- var distanceToMove = basePlatformX - platformCurrent.x;
- var moveSpeed = 10; // Adjust the speed as needed
- if (Math.abs(distanceToMove) <= moveSpeed) {
- // If the distance to move is less than or equal to the move speed, snap to position
- platformCurrent.x = basePlatformX;
- platformTarget.x += distanceToMove;
- //platformNext.x += distanceToMove;
- ninja.x += distanceToMove;
- stick.x += distanceToMove;
- foreground1.x += distanceToMove * 1.5;
- foreground2.x += distanceToMove * 1.5;
- midground1.x += distanceToMove * 0.5;
- midground2.x += distanceToMove * 0.5;
- isReturningToBase = false; // Stop moving objects
- } else {
- // Move objects towards the base position
- platformCurrent.x += moveSpeed * Math.sign(distanceToMove);
- platformTarget.x += moveSpeed * Math.sign(distanceToMove);
- platformNext.x += moveSpeed * Math.sign(distanceToMove) * (platformNext.speedRatio || 1);
- if (platformNext.x - platformNext.width < 2048) {
- platformNext.x = 2048 + platformNext.width;
- }
- ninja.x += moveSpeed * Math.sign(distanceToMove);
- stick.x += moveSpeed * Math.sign(distanceToMove);
- foreground1.x += moveSpeed * Math.sign(distanceToMove) * 1.5;
- foreground2.x += moveSpeed * Math.sign(distanceToMove) * 1.5;
- midground1.x += moveSpeed * Math.sign(distanceToMove) * 0.5;
- midground2.x += moveSpeed * Math.sign(distanceToMove) * 0.5;
- }
+ handleReturningToBase();
}
};
// Call gameInitialize function
gameInitialize();
\ No newline at end of file