Code edit (1 edits merged)
Please save this source code
User prompt
while reternuing to base the stick should be shorten progressively to 0 insteaf of disappearing
User prompt
insteaf of disappearing when reternuing to base the stick should be shorten progressively to 0
User prompt
insteaf of disappearing when reternuing to base the stick should be shorten to 0
Code edit (1 edits merged)
Please save this source code
User prompt
the first colum disapears (is moved) too early, it shoud pass totaly the left of the screen before moving
Code edit (4 edits merged)
Please save this source code
User prompt
in bumpInterval fix the scope problem
Code edit (1 edits merged)
Please save this source code
User prompt
fix game : can't play because stick start to grow then disapears
User prompt
fix growStick
User prompt
be coherent, currentStick is sometimes local and others global
User prompt
Please fix the bug: 'TypeError: currentStick is undefined' in or related to this line: 'if (!isNinjaMoving && currentStick.rotation >= Math.PI / 2) {' Line Number: 519
User prompt
continue the rework as the ninja doesn't move on the stick
User prompt
continue the rework as there global variable stick is still used
User prompt
Please fix the bug: 'TypeError: currentStick is undefined' in or related to this line: 'if (currentStick.length < 2048 - currentStick.x - 100) {' Line Number: 521
User prompt
change the logic of sticks, be creating each time a new stick and destroying them when their x < length
Code edit (1 edits merged)
Please save this source code
User prompt
rename animateScoreBump to updateScore and move score increase instruction in it
User prompt
refactor handleNinjaReachPlatform to 1 responsibility functions
Code edit (3 edits merged)
Please save this source code
User prompt
when ninja reach platform, move it slowly to the center of the platform
Code edit (1 edits merged)
Please save this source code
User prompt
nextstick should be at the same z-index as stick
User prompt
nextStick should be created at the same time as stick but kept invisible until needed
===================================================================
--- original.js
+++ change.js
@@ -188,9 +188,8 @@
anchorX: 0.5,
anchorY: 1.0
});
self.length = 0;
- self.fallen = false;
self.update = function () {
// Stick update logic
};
});
@@ -222,9 +221,8 @@
var isReturningToBase = false;
var isStickFalling = false;
var isNinjaMoving = false;
var isGameStarted = false; // Flag to indicate the start of the game
-var nextStick = null; // Variable to hold the next stick
var legsOffset = 50;
var score = 0;
var foreground1;
var foreground2;
@@ -342,14 +340,8 @@
stick.x = platformCurrent.x + platformCurrent.width / 2 - 30; // Set stick to the right edge of the platform with an offset of -30
stick.y = platformCurrent.y - platformCurrent.height + 30; // Adjusted y-coordinate to ensure stick is on the platform with an offset of 20
log("stick.y set in startGame:", stick.y);
game.addChildAt(stick, game.children.indexOf(platformCurrent) - 1);
- nextStick = new Stick();
- nextStick.length = 0; // Set initial stick length to zero
- nextStick.height = nextStick.length;
- nextStick.x = platformTarget.x + platformTarget.width / 2 - 30; // Set nextStick to the right edge of the target platform with an offset of -30
- nextStick.y = platformTarget.y - platformTarget.height + 30; // Adjusted y-coordinate to ensure nextStick is on the target platform with an offset of 20
- game.addChildAt(nextStick, game.children.indexOf(stick));
// Add foreground images to create an infinite horizontal foreground
foreground1 = LK.getAsset('foreground', {
anchorX: 0.5,
anchorY: 1.0,
@@ -377,8 +369,20 @@
log("platformTarget.x:", platformTarget.x);
log("platformNext.x:", platformNext.x);
isNinjaMoving = false;
isReturningToBase = true;
+ // Move ninja to the center of the platform
+ var targetX = platformCurrent.x;
+ var targetWidth = platformCurrent.width;
+ var ninjaCenterX = targetX - targetWidth / 2 + ninja.width / 2;
+ var moveNinjaToCenter = LK.setInterval(function () {
+ if (ninja.x < ninjaCenterX) {
+ ninja.x += 5; // Adjust the speed as needed
+ } else {
+ ninja.x = ninjaCenterX; // Snap to the center position
+ LK.clearInterval(moveNinjaToCenter); // Stop the animation
+ }
+ }, 16); // Approximately 60 FPS
// Remove the first platform from the game and the platforms array
platformCurrent.visible = false;
var tempPlatform = platformCurrent;
platformCurrent = platformTarget;
@@ -404,21 +408,13 @@
LK.clearInterval(bumpInterval);
}
}
}, 16); // Approximately 60 FPS
- if (nextStick) {
- // Switch sticks
- var tempStick = stick;
- stick = nextStick;
- nextStick = tempStick;
- } else {
- stick.length = 0;
- stick.height = 0;
- stick.rotation = 0;
- stick.fallen = false;
- 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 + 30; // Adjusted y-coordinate to ensure stick is on the platform with an offset of 20
- }
+ 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 + 30; // Adjusted y-coordinate to ensure stick is on the platform with an offset of 20
log("stick.y set in handleNinjaReachPlatform:", stick.y, isNinjaMoving);
var minDistance = Math.max(100, 300 - level * 10); // Decrease minimum distance as level increases, with a minimum of 100
var maxDistance = Math.min(600, 400 + level * 20); // Increase maximum distance as level increases, with a maximum of 600
var distance = (Math.floor(Math.random() * (maxDistance - minDistance + 1)) + minDistance) * platformNext.speedRatio;
@@ -498,19 +494,13 @@
stick.rotation = Math.PI / 2;
}
}
function growStick() {
- if (!isStickFalling) {
- if (stick.length < 2048 - stick.x - 100 && !stick.fallen) {
- stick.length += 10;
- stick.height = stick.length;
- } else {
- LK.getSound('stickGrowSound').stop();
- }
- if (nextStick && nextStick.length < 2048 - nextStick.x - 100) {
- nextStick.length += 10;
- nextStick.height = nextStick.length;
- }
+ if (stick.length < 2048 - stick.x - 100) {
+ stick.length += 10;
+ stick.height = stick.length;
+ } else {
+ LK.getSound('stickGrowSound').stop();
}
}
function handleBackgroundMovement(distance) {
// Move midground images to the left
@@ -611,34 +601,18 @@
scoreTxt.visible = true;
isGameStarted = true;
startGame();
}, 1000);
- } else if (!intro && !isStickGrowing && !isStickFalling) {
- if (isNinjaMoving) {
- // Check if current stick reached the platform
- if (stick.length >= platformTarget.x - (platformCurrent.x + stick.x) && nextStick === null) {
- // Create nextStick to prepare for the next round
- nextStick = new Stick();
- nextStick.length = 0;
- nextStick.height = nextStick.length;
- nextStick.x = platformTarget.x + platformTarget.width / 2 - 30;
- nextStick.y = platformTarget.y - platformTarget.height + 30;
- game.addChild(nextStick);
- isStickGrowing = true;
- LK.getSound('stickGrowSound').play();
- }
- } else {
- isStickGrowing = true;
- LK.getSound('stickGrowSound').play();
- }
+ } else if (!intro && !isStickGrowing && !isStickFalling && !isNinjaMoving) {
+ isStickGrowing = true;
+ LK.getSound('stickGrowSound').play();
}
};
// Handle touch up event
game.up = function (x, y, obj) {
if (isStickGrowing && !isNinjaMoving) {
isStickGrowing = false;
isStickFalling = true;
- stick.fallen = true;
LK.getSound('stickGrowSound').stop();
}
};
// Update game logic