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
@@ -65,8 +65,23 @@
/****
* Game Code
****/
+// Create and display the score text at the top of the screen with drop shadow
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: "#ffffff",
+ stroke: "#000000",
+ strokeThickness: 10,
+ dropShadow: true,
+ dropShadowColor: "#000000",
+ dropShadowBlur: 4,
+ dropShadowDistance: 6
+});
+scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally, anchor point set at the middle of its top edge.
+scoreTxt.x = 2048 / 2; // Center horizontally
+scoreTxt.y = 50; // Position near the top
+game.addChild(scoreTxt);
var basePlatformX = 300;
var NINJA_MOVEMENT_SPEED = -5;
function handleNinjaReachPlatform() {
console.log("Start of handleNinjaReachPlatform");
@@ -81,20 +96,22 @@
platformCurrent = platformTarget;
platformTarget = platformNext;
platformNext = tempPlatform;
score++;
+ scoreTxt.setText(score); // Update score text
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
var minDistance = 200;
var maxDistance = 400;
var distance = Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance;
- tempPlatform.x = platformTarget.x + platformTarget.width / 2 + distance;
- tempPlatform.y = 2732; // Adjusted y-coordinate to touch the ground
- tempPlatform.width = Math.floor(Math.random() * (400 - 100 + 1)) + 100; // Randomize width between 100 and 400
- tempPlatform.visible = true;
+ platformNext.x = 2048 + distance; //platformTarget.x + platformTarget.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;
+ 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);
@@ -326,9 +343,9 @@
} 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.x += moveSpeed * Math.sign(distanceToMove) * (platformNext.speedRatio || 1);
ninja.x += moveSpeed * Math.sign(distanceToMove);
stick.x += moveSpeed * Math.sign(distanceToMove);
}
}