Code edit (15 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: opponents[(line - 1)] is undefined' in or related to this line: 'if (!opponents[line - 1].finishPosition && opponents[line - 1].x > finishLine.x) {' Line Number: 897
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in victoryAnim, clamp the rotations
Code edit (15 edits merged)
Please save this source code
User prompt
implement the victoryAnim
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: opponents[0] is undefined' in or related to this line: 'opponents[0].update();' Line Number: 706
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'var distance = obstacles[self.lineIndex][0].x - nextX;' Line Number: 173
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'var distance = obstacles[self.lineIndex][0].x - nextX;' Line Number: 171
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (22 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: deltaSpeed is not defined' in or related to this line: 'if (distance > 0 && distance <= 250) {' Line Number: 164
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'globalSpeedPerLine[line] = globalBaseSpeed;' Line Number: 621
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'if (!obstacles[line].length && !finishLine.isCut) {' Line Number: 836
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -95,11 +95,9 @@
return;
} else {
self.isChangingPosture = true;
}
- if (self.targetPosture && self.targetPosture.head) {
- self.head.x += (self.targetPosture.head.x - self.head.x) * speed;
- }
+ self.head.x += (self.targetPosture.head.x - self.head.x) * speed;
self.trunk.rotation += (self.targetPosture.trunk.r - self.trunk.rotation) * speed;
self.head.y += (self.targetPosture.head.y - self.head.y) * speed;
self.rightArm.x += (self.targetPosture.rightArm.x - self.rightArm.x) * speed;
self.rightArm.y += (self.targetPosture.rightArm.y - self.rightArm.y) * speed;
@@ -137,9 +135,11 @@
self.runAnim();
}
// Auto jump first hurdle of the line
if (obstacles[self.lineIndex].length) {
- var distance = obstacles[self.lineIndex][0].x - nextX;
+ if (obstacles[self.lineIndex] && obstacles[self.lineIndex].length > 0) {
+ var distance = obstacles[self.lineIndex][0].x - nextX;
+ }
if (self.lineIndex == 3) {
log((self.isOnGround ? 'On ground' : 'In air') + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
}
if (distance > 0 && distance <= 300) {
@@ -153,20 +153,19 @@
var distance = obstacles[self.lineIndex][0].x - nextX;
if (self.lineIndex == 3) {
log((self.isOnGround ? 'On ground' : 'In air') + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
}
- // Jumping
- self.speedY += self.gravity * Math.abs(globalSpeedPerLine[self.lineIndex] / 10);
- self.y += self.speedY * Math.abs(globalSpeedPerLine[self.lineIndex] / 10);
+ // Jumping - if not running, finish the jump
+ self.speedY += self.gravity * Math.abs(globalSpeedPerLine[self.lineIndex] / 10) + (!self.isRunning ? 0.5 : 0);
+ self.y += self.speedY * Math.abs(globalSpeedPerLine[self.lineIndex] / 10) + (!self.isRunning ? self.speedY : 0);
if (self.y >= linesGroundLevels[self.lineIndex]) {
// Reached the ground
self.isOnGround = true;
self.speedY = 0;
self.y = linesGroundLevels[self.lineIndex];
// Define speed for next hurdle
var difficultyLevel = 1; // TODO : Move to global
- self.nextHurdleSpeedX = -8 + difficultyLevel * 4 * Math.random();
- //self.nextHurdleSpeedX = 0;// TEMP DEBUG
+ self.nextHurdleSpeedX = -7 + difficultyLevel * 9 * Math.random();
} else {
self.jumpAnim();
}
}
@@ -303,8 +302,15 @@
self.targetPosture = newPosture;
};
self.restore = function () {
log("restore...");
+ self.stop();
+ self.hasFlashed = false;
+ self.hasFlashedGround = false;
+ self.isRunning = true;
+ };
+ self.stop = function () {
+ log("stop...");
self.x = self.previousX || 400 + 100 * self.lineIndex;
self.y = linesGroundLevels[self.lineIndex];
self.speedY = 0;
self.trunk.rotation = 0;
@@ -314,11 +320,8 @@
self.leftLeg.rotation = 0;
self.setPosture(idlePosture);
self.isFalling = false;
self.isOnGround = true;
- self.hasFlashed = false;
- self.hasFlashedGround = false;
- self.isRunning = true;
};
});
/****************************************************************************************** */
/************************************** FINISH LINE CLASS ************************************ */
@@ -454,12 +457,12 @@
var numberOfOpponents = 3; // Adjust based on the actual number of opponents in the game
var groundLevel = 2732 - 200; // Ground level set 200px from the bottom
var linesGroundLevels = []; // Ground level set 200px from the bottom
var numberOfLines = 1 + numberOfOpponents;
-var numberOfObstacles = 20; // Total number of hurdles
+var numberOfObstacles = 2; //20; // Total number of hurdles
var obstacles = [[]];
var obstacleSpawnTicker = 0;
-var obstacleSpawnDistanceRate = 2; //1.5; // Ratio of screen width between obstacles
+var obstacleSpawnDistanceRate = 1.5; // Ratio of screen width between obstacles
var obstacleJustPassed = false;
var finishLine;
var stadium;
var stadiumOdd;
@@ -472,10 +475,8 @@
var track3;
var track4;
var scoreTxt;
var globalBaseSpeed = -20;
-var globalSpeedIncreaseStep = 0; //5; TEMP DEBUG
-var globalSlowDownAfterJump = false;
var globalSpeedPerLine = []; // Global speed for tracks and obstacles default -10 / min = -4
var colorsArray = [0x1188FF, 0xFF0000, 0x00FF00, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF, 0xFF8811];
var isDebug = true;
var debugMarker;
@@ -805,15 +806,8 @@
// Update Progress
obstacleJustPassed = false;
LK.setScore(LK.getScore() + 1); // Add 1 to score for each hurdle passed only if not falling
scoreTxt.setText(LK.getScore()); // Update score text with prefix
- // Increase global speed after each obstacle passed and add 1 to score only if not falling
- /*for (var line = 0; line < numberOfLines; line++) {
- globalSpeedPerLine[line] -= globalSpeedIncreaseStep;
- if (line == 3) {
- log("new Speed :" + globalSpeedPerLine[line]);
- }
- }.*/
}
if (finishLine.isCut) {
for (var line = 0; line < numberOfLines; line++) {
// Ensure a smooth transition to 0 speed
@@ -822,16 +816,16 @@
} else if (globalSpeedPerLine[line] > 0.25) {
globalSpeedPerLine[line] -= 0.25; // Increment speed gradually if somehow above 0
} else {
globalSpeedPerLine[line] = 0; // Set to 0 if very close to it
- if (athlete.isRunning) {
+ if (line == 0 && athlete.isRunning) {
athlete.isRunning = false;
- athlete.setPosture(idlePosture);
- opponents.forEach(function (opponent) {
- opponent.isRunning = false;
- opponent.setPosture(idlePosture);
- });
+ athlete.stop();
}
+ if (line > 0 && opponents[line - 1].isRunning) {
+ opponents[line - 1].isRunning = false;
+ opponents[line - 1].stop();
+ }
}
}
}
}
@@ -846,26 +840,21 @@
if (line === 0) {
if (athlete.intersects(obstacle.centralRod)) {
athlete.isFalling = true;
athlete.isOnGround = false;
- //athlete.fallAnim(); // Call fall animation before game over
}
} else {
if (opponents[line - 1].intersects(obstacle.centralRod)) {
log("Line " + line + " : opponent " + opponents[line - 1].lineIndex + " collided with obstacle " + obstacle.lineIndex);
opponents[line - 1].isFalling = true;
opponents[line - 1].isOnGround = false;
- //opponents[line - 1].fallAnim(); // Call fall animation before game over
}
}
}
}
handleFallEvent();
if (!obstacles[0].length && !finishLine.isCut) {
var isReached = athlete.intersects(finishLine.centralRodRight);
- // opponents.forEach(function (opponent) {
- // isReached |= opponent.intersects(finishLine.centralRodRight);
- // });
if (isReached) {
finishLine.isCut = true;
finishLine.cut();
}
@@ -875,16 +864,9 @@
if (athlete.isFalling && !athlete.hasFlashed) {
LK.effects.flashScreen(0xaaaaaa, 500); // Flash screen red for half a second
athlete.hasFlashed = true;
globalSpeedPerLine[0] /= 1.5;
- // TEMP TEST FIX AI SPEED
- /*opponents.forEach(function (opponent) {
- globalSpeedPerLine[opponent.lineIndex] /= 1.5;
- });
- => OK but make AI FALL
- */
globalSlowDownAfterJump = true;
- // TEMP TEST FIX AI SPEED
}
if (athlete.hasFlashed && !athlete.hasFlashedGround && athlete.isFalling && athlete.isOnGround) {
LK.effects.flashScreen(0xff0000, 500); // Flash screen red for half a second
athlete.hasFlashedGround = true;
Elongated elipse with black top half and white bottom half.
full close and front view of empty stands. retro gaming style
delete
delete
Basquettes à ressort futuriste. vue de profile. Retro gaming style
a blue iron man style armor flying. Retro gaming style
a blue iron man style armor flying horizontally. Retro gaming style
round button with a big "up" arrow icon and a small line under it. UI
A big black horizontal arrow pointing left with centred text 'YOU' in capital letters, painted on an orange floor.. horizontal and pointing left
remove
gold athletics medal with ribbon. retro gaming style
a black oval with a crying smiley face.