User prompt
display the score at the top of the screen in big and with dropshadow
Code edit (1 edits merged)
Please save this source code
User prompt
in handleNinjaReachPlatform, log each platform x at function start and end
User prompt
add a different tint to each platform for debugging
User prompt
in game.update when isReturningToBase, move all objects until platformCurrent reaches basePlatformX
User prompt
in handleNinjaReachPlatform set isReturningToBase to true
User prompt
add a new global variable, isReturningToBase
Code edit (2 edits merged)
Please save this source code
User prompt
in handleNinjaReachPlatform, ensure that all objects move left until platformCurrent reached basePlatformX
User prompt
create a global variable basePlatformX = 300
Code edit (1 edits merged)
Please save this source code
User prompt
in createInitialPlatforms, ensure the minimal distance is repected between the borders of the platforms not their centers
Code edit (3 edits merged)
Please save this source code
User prompt
in handleNinjaReachPlatform store platformCurrent in a temporay variable to affect it back as platformNext
Code edit (2 edits merged)
Please save this source code
User prompt
handleNinjaAfterStick is called after the ninja passes the stick so he shouldn't continue
Code edit (1 edits merged)
Please save this source code
User prompt
refactore moveNinja: use a constant for the '-5' value, remove unused code
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
===================================================================
--- original.js
+++ change.js
@@ -64,8 +64,56 @@
/****
* Game Code
****/
+function handleNinjaReachPlatform() {
+ isNinjaMoving = false;
+ // Remove the first platform from the game and the platforms array
+ platformCurrent.visible = false;
+ platformCurrent = platformTarget;
+ platformTarget = platformNext;
+ score++;
+ stick.length = 0;
+ stick.height = 0;
+ 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 (isNinjaMoving) {
+ var minDistance = 200;
+ var maxDistance = 1400;
+ var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
+ platformNext.x = platformCurrent.x + platformCurrent.width / 2 + distance;
+ platformNext.y = 2732; // Adjusted y-coordinate to touch the ground
+ platformNext.width = Math.floor(Math.random() * (400 - 100 + 1)) + 100; // Randomize width between 100 and 400
+ platformNext.visible = true;
+ }
+}
+function handleNinjaFall() {
+ // If the stick does not reach the next platform or exceeds it, make the ninja fall
+ ninja.y += 20;
+ if (ninja.runSoundPlaying) {
+ LK.getSound('runSound').stop();
+ ninja.runSoundPlaying = false;
+ }
+ ninja.ninjaStand.rotation = Math.PI; // Rotate the ninja by 180 degrees
+ if (!fallSoundPlayed) {
+ LK.getSound('fallSound').play();
+ fallSoundPlayed = true; // Set the flag to true after playing the sound
+ if (ninja.runSoundPlaying) {
+ LK.getSound('runSound').stop();
+ ninja.runSoundPlaying = false;
+ }
+ }
+ if (ninja.y > 2732 && isNinjaMoving) {
+ // If ninja falls off the screen
+ if (ninja.runSoundPlaying) {
+ LK.getSound('runSound').stop();
+ ninja.runSoundPlaying = false;
+ }
+ LK.showGameOver();
+ }
+}
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 && isNinjaMoving) {
@@ -73,55 +121,13 @@
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 && isNinjaMoving) {
- // If the stick does not reach the next platform or exceeds it, make the ninja fall
- ninja.y += 20;
- if (ninja.runSoundPlaying) {
- LK.getSound('runSound').stop();
- ninja.runSoundPlaying = false;
- }
- ninja.ninjaStand.rotation = Math.PI; // Rotate the ninja by 180 degrees
- if (!fallSoundPlayed) {
- LK.getSound('fallSound').play();
- fallSoundPlayed = true; // Set the flag to true after playing the sound
- if (ninja.runSoundPlaying) {
- LK.getSound('runSound').stop();
- ninja.runSoundPlaying = false;
- }
- }
- if (ninja.y > 2732 && isNinjaMoving) {
- // If ninja falls off the screen
- if (ninja.runSoundPlaying) {
- LK.getSound('runSound').stop();
- ninja.runSoundPlaying = false;
- }
- LK.showGameOver();
- }
+ handleNinjaFall();
} else {
// If the stick reaches the next platform, stop the ninja and reset the stick
if (platformTarget.x - platformTarget.width / 2 <= 300 && isNinjaMoving) {
- isNinjaMoving = false;
- // Remove the first platform from the game and the platforms array
- platformCurrent.visible = false;
- platformCurrent = platformTarget;
- platformTarget = platformNext;
- score++;
- stick.length = 0;
- stick.height = 0;
- 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 (isNinjaMoving) {
- var minDistance = 200;
- var maxDistance = 1400;
- var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
- platformNext.x = platformCurrent.x + platformCurrent.width / 2 + distance;
- platformNext.y = 2732; // Adjusted y-coordinate to touch the ground
- platformNext.width = Math.floor(Math.random() * (400 - 100 + 1)) + 100; // Randomize width between 100 and 400
- platformNext.visible = true;
- }
+ handleNinjaReachPlatform();
}
}
}
}