User prompt
in handleNinjaAfterStick separate code in dedicated functions
User prompt
in handleNinjaAfterStick, don't create a new platform, just move the old one
User prompt
in handleNinjaAfterStick, don't use game.removeChild()
User prompt
Please fix the bug: 'TypeError: ninja is undefined' in or related to this line: 'ninja.update();' Line Number: 318
Code edit (1 edits merged)
Please save this source code
User prompt
dans game.down, si isGameStarted est faux, passe le à vrai et appel startgame
User prompt
place le isGameStarted seulement apres un click
User prompt
ajoute un boolen en tant que flag pour le demarrage du jeu
Code edit (1 edits merged)
Please save this source code
User prompt
Joue le BG Music une première fois au start.
User prompt
joue la bg musique toutes les 10 secondes
User prompt
joue la bg musique toutes les 10 secondes
User prompt
répete toujours la musique bg
User prompt
always play the bgMusic
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot set properties of undefined (setting 'runSoundPlaying')' in or related to this line: 'ninja.runSoundPlaying = false; // Reset the run sound flag when the game starts' Line Number: 241
User prompt
Arrête le son de la course quand le ninja tombe.
User prompt
Joue le son run quand le ninja court.
User prompt
ne joue le son qu'une seule fois.
User prompt
Je joue le son un peu plus tôt.
User prompt
Joue le son l'heure de la chute
Code edit (1 edits merged)
Please save this source code
User prompt
fix : there's a platform that moves 2 times not like the other elments
User prompt
separate the states logic before and after the ninja passes the stick
Code edit (1 edits merged)
Please save this source code
User prompt
fix the bug : a platform moves before the ninjapasses the stick
===================================================================
--- original.js
+++ change.js
@@ -61,24 +61,24 @@
****/
function handleNinjaAfterStick() {
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) {
+ if (platformTarget && isNinjaMoving) {
var ninjaMinX = ninja.x - ninja.width / 2 + legsOffset;
var ninjaMaxX = ninja.x + ninja.width / 2 - legsOffset;
var platformMinX = platformTarget.x - platformTarget.width / 2;
var platformMaxX = platformTarget.x + platformTarget.width / 2;
- if (ninjaMaxX < platformMinX || ninjaMinX > platformMaxX) {
+ if (ninjaMaxX < platformMinX || ninjaMinX > platformMaxX && isNinjaMoving) {
// If the stick does not reach the next platform or exceeds it, make the ninja fall
ninja.y += 20;
ninja.ninjaStand.rotation = Math.PI; // Rotate the ninja by 180 degrees
- if (ninja.y > 2732) {
+ if (ninja.y > 2732 && isNinjaMoving) {
// If ninja falls off the screen
LK.showGameOver();
}
} else {
// If the stick reaches the next platform, stop the ninja and reset the stick
- if (platformTarget.x - platformTarget.width / 2 <= 300) {
+ if (platformTarget.x - platformTarget.width / 2 <= 300 && isNinjaMoving) {
isNinjaMoving = false;
// Remove the first platform from the game and the platforms array
game.removeChild(platformCurrent);
platformCurrent = platformTarget;
@@ -89,9 +89,9 @@
stick.rotation = 0;
stick.x = platformCurrent.x + platformCurrent.width / 2 - 30; // Set stick to the right edge of the current platform with an offset of -30
stick.y = platformCurrent.y - platformCurrent.height + 20; // Adjusted y-coordinate to ensure stick is on the platform with an offset of 20
// Create a new platform to the right of the screen only if there are less than two platforms
- if (!platformNext) {
+ if (!platformNext && isNinjaMoving) {
var newPlatform = new Platform();
var minDistance = 200;
var maxDistance = 1400;
var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
@@ -108,19 +108,19 @@
function moveNinja() {
console.log("Moving...", "ninja.x= " + ninja.x, "stick.x= " + (stick.x + stick.length));
handleBackgroundMovement();
// Shift platforms, ninja, and stick to the left
- if (!isStickGrowing && !isStickFalling && isNinjaMoving) {
+ if (isNinjaMoving) {
platformCurrent.x -= 5;
platformTarget.x -= 5;
platformNext.x -= 5;
- if (platformCurrent.x + platformCurrent.width / 2 < 0 && !isNinjaMoving && ninja.x >= stick.x + stick.length) {
+ if (platformCurrent.x + platformCurrent.width / 2 < 0 && isNinjaMoving) {
platformCurrent.x = 2048 + platformCurrent.width / 2;
}
- if (platformTarget.x + platformTarget.width / 2 < 0 && !isNinjaMoving && ninja.x >= stick.x + stick.length) {
+ if (platformTarget.x + platformTarget.width / 2 < 0 && isNinjaMoving) {
platformTarget.x = 2048 + platformTarget.width / 2;
}
- if (platformNext.x + platformNext.width / 2 < 0 && !isNinjaMoving && ninja.x >= stick.x + stick.length) {
+ if (platformNext.x + platformNext.width / 2 < 0 && isNinjaMoving) {
platformNext.x = 2048 + platformNext.width / 2;
}
}
if (isNinjaMoving) {