Code edit (2 edits merged)
Please save this source code
User prompt
log every time stick.y is set with the name of the function. use log() function
User prompt
log every time ninja.y is set with the name of the function. use log() function
Code edit (2 edits merged)
Please save this source code
User prompt
add an isDebug global variable
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
for ninja run anim, use the following sequence : 1,2,1,3,4,3
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -86,39 +86,8 @@
/****
* 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;
@@ -384,8 +353,39 @@
if (foreground2.x + 2048 / 2 < 0) {
foreground2.x = foreground1.x + 2048;
}
}
+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;
+ }
+}
// Create initial platforms
function createInitialPlatforms() {
var platform1 = new Platform();
platform1.x = basePlatformX;