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
@@ -122,9 +122,9 @@
self.runSoundPlaying = false;
self.update = function () {
if (isNinjaMoving && !isStickFalling && ninja.x + ninja.width / 2 < stick.x + stick.length) {
self.ninjaStand.visible = false;
- if (LK.ticks % 30 < 15) {
+ if (LK.ticks % 10 < 5) {
self.ninjaRun.visible = false;
self.ninjaRun1.visible = true;
} else {
self.ninjaRun1.visible = false;
@@ -238,8 +238,9 @@
/****
* Game Code
****/
// Initialize game variables
+var isDebug = false;
var clouds;
var platformMinWidth = 100;
var level = 1; // Initialize the level variable
var platformMaxWidth = 400;
@@ -377,12 +378,14 @@
LK.getSound('bgMusic').play();
}, 10000);
}
function handleNinjaReachPlatform() {
- console.log("Start of handleNinjaReachPlatform");
- console.log("platformCurrent.x:", platformCurrent.x);
- console.log("platformTarget.x:", platformTarget.x);
- console.log("platformNext.x:", platformNext.x);
+ if (isDebug) {
+ console.log("Start of handleNinjaReachPlatform");
+ console.log("platformCurrent.x:", platformCurrent.x);
+ console.log("platformTarget.x:", platformTarget.x);
+ console.log("platformNext.x:", platformNext.x);
+ }
isNinjaMoving = false;
isReturningToBase = true;
// Remove the first platform from the game and the platforms array
platformCurrent.visible = false;
@@ -406,12 +409,14 @@
platformNext.width = Math.floor(Math.random() * (platformMaxWidth - platformMinWidth + 1)) + platformMinWidth; // Randomize width between platformMinWidth and platformMaxWidth
level++; // Increment the level after each platform is reached
platformNext.visible = true;
platformNext.speedRatio = 1 + Math.random();
- console.log("End of handleNinjaReachPlatform");
- console.log("platformCurrent.x:", platformCurrent.x);
- console.log("platformTarget.x:", platformTarget.x);
- console.log("platformNext.x:", platformNext.x);
+ if (isDebug) {
+ console.log("End of handleNinjaReachPlatform");
+ console.log("platformCurrent.x:", platformCurrent.x);
+ console.log("platformTarget.x:", platformTarget.x);
+ console.log("platformNext.x:", platformNext.x);
+ }
}
function handleNinjaFall() {
// If the stick does not reach the next platform or exceeds it, make the ninja fall
ninja.y += 20;
@@ -437,9 +442,11 @@
LK.showGameOver();
}
}
function handleNinjaAfterStick() {
- console.log("Passed the stick", "Run= " + ninja.ninjaRun.visible, "Stand= " + ninja.ninjaStand.visible);
+ if (isDebug) {
+ console.log("Passed the stick", "Run= " + ninja.ninjaRun.visible, "Stand= " + ninja.ninjaStand.visible);
+ }
// If the ninja has walked to the end of the stick
if (platformTarget && isNinjaMoving) {
var ninjaMinX = ninja.x - ninja.width / 2 + legsOffset;
var ninjaMaxX = ninja.x + ninja.width / 2 - legsOffset;
@@ -452,9 +459,11 @@
}
}
}
function moveNinja() {
- console.log("Moving...", "ninja.x= " + ninja.x, "stick.x= " + (stick.x + stick.length));
+ if (isDebug) {
+ console.log("Moving...", "ninja.x= " + ninja.x, "stick.x= " + (stick.x + stick.length));
+ }
// Shift platforms, ninja, and stick to the left
if (isNinjaMoving) {
handleBackgroundMovement(NINJA_MOVEMENT_SPEED);
platformCurrent.x += NINJA_MOVEMENT_SPEED;