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
Code edit (17 edits merged)
Please save this source code
User prompt
in updateProgress, when (finishLine.isCut) , reduce globalSpeedPerLine[line] to 0 progressievly
Code edit (1 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: clearInterval is not a function' in or related to this line: 'clearInterval(cutInterval);' Line Number: 351
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: setInterval is not a function' in or related to this line: 'var cutInterval = setInterval(function () {' Line Number: 345
User prompt
in FinishLine, make the cut pregressive
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 (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -116,21 +116,8 @@
// Right foot updates removed due to foot assets being removed
self.leftLeg.x += (self.targetPosture.leftLeg.x - self.leftLeg.x) * speed;
self.leftLeg.y += (self.targetPosture.leftLeg.y - self.leftLeg.y) * speed;
};
- self.jump = function () {
- if (Date.now() - self.lastJumpTime > self.interJumpDelayMs) {
- if (self.isOnGround) {
- self.isOnGround = false;
- self.speedY = self.jumpSpeed;
- self.lastJumpTime = Date.now();
- globalSpeedPerLine[self.lineIndex] = globalSpeedPerLine[self.lineIndex] * 0.9;
- if (self.lineIndex == 3) {
- log("--------------- JUMP --------------------");
- }
- }
- }
- };
self.update = function () {
if (!self.isFalling) {
if (self.isOnGround) {
self.leftLeg.height = 200;
@@ -139,8 +126,11 @@
if (self.isRunning) {
self.runAnim();
}
} else {
+ if (self.lineIndex == 3) {
+ log("Current pultiplier=" + Math.abs(globalSpeedPerLine[self.lineIndex] / 10));
+ }
self.speedY += self.gravity * Math.abs(globalSpeedPerLine[self.lineIndex] / 10); //self.lineIndex
self.y += self.speedY * Math.abs(globalSpeedPerLine[self.lineIndex] / 10); //self.lineIndex
//log("self.speedY=" + self.speedY, " / self.y=" + self.y);
if (self.y >= linesGroundLevels[self.lineIndex]) {
@@ -168,26 +158,32 @@
if (self.lineIndex == 3) {
log("Player falls add=" + self.speedX);
}
//nextX += self.speedX;
- nextX -= globalSpeedPerLine[self.lineIndex];
+ nextX -= globalSpeedPerLine[self.lineIndex] * 1.5;
} else {
- nextX += globalSpeedPerLine[self.lineIndex] * 0.05 * Math.random();
+ //nextX += globalSpeedPerLine[self.lineIndex] * 0.5 * Math.random();
}
if (!athlete.isFalling && !athlete.isOnGround) {
// Little advance when player plays jumping
if (self.lineIndex == 3) {
log("Player jumping add=" + self.speedX * 0.1);
}
- nextX += self.speedX * 0.1;
+ //nextX += self.speedX * 0.1;
}
}
// Auto jump hurdles in obstacles[self.lineIndex]
if (self.isOnGround) {
+ if (globalSlowDownAfterJump) {
+ if (self.lineIndex == 3) {
+ log("globalSlowDownAfterJump SET=-10");
+ }
+ globalSpeedPerLine[self.lineIndex] = -10;
+ }
if (obstacles[self.lineIndex].length) {
var distance = obstacles[self.lineIndex][0].x - nextX;
if (self.lineIndex == 3) {
- //log("distance=" + distance);
+ log("distance=" + distance);
}
if (distance > 0 && distance <= 250 + self.speedX) {
self.jump();
}
@@ -196,8 +192,21 @@
self.x = nextX;
self.previousX = self.x;
}
};
+ self.jump = function () {
+ if (Date.now() - self.lastJumpTime > self.interJumpDelayMs) {
+ if (self.isOnGround) {
+ self.isOnGround = false;
+ self.speedY = self.jumpSpeed;
+ self.lastJumpTime = Date.now();
+ //globalSpeedPerLine[self.lineIndex] = globalSpeedPerLine[self.lineIndex] * 1.1;
+ if (self.lineIndex == 3) {
+ log("--------------- JUMP --------------------");
+ }
+ }
+ }
+ };
self.runAnim = function () {
var ocsilDelay = 5;
var armsAmplitude = 0.5;
var legsAmplitude = 0.5;
@@ -263,9 +272,9 @@
self.targetPosture = newPosture;
};
self.restore = function () {
log("restore...");
- self.x = self.previousX || 400;
+ self.x = self.previousX || 400 + 100 * self.lineIndex;
self.y = linesGroundLevels[self.lineIndex];
self.speedY = 0;
self.trunk.rotation = 0;
self.rightArm.rotation = idlePosture.rightArm.r;
@@ -414,12 +423,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 = 1;
+var numberOfObstacles = 20; // Total number of hurdles
var obstacles = [[]];
var obstacleSpawnTicker = 0;
-var obstacleSpawnDistanceRate = 0.3; //1.5; // Spawn an obstacle 1 screen * 1.5
+var obstacleSpawnDistanceRate = 1.5; // Ratio of screen width between obstacles
var obstacleJustPassed = false;
var finishLine;
var stadium;
var stadiumOdd;
@@ -431,9 +440,11 @@
var track2;
var track3;
var track4;
var scoreTxt;
-var globalSpeedIncreaseStep = 5;
+var globalSpeedBase = -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;
@@ -586,9 +597,13 @@
track4.y = 2732 - 1024;
// Initialize ground levels & speeds
for (var line = 0; line < numberOfLines; line++) {
linesGroundLevels[line] = groundLevel - 200 - 220 * line;
- globalSpeedPerLine[line] = -10;
+ if (typeof globalBaseSpeed !== 'undefined') {
+ globalSpeedPerLine[line] = globalBaseSpeed;
+ } else {
+ console.error('globalBaseSpeed is not defined');
+ }
}
// Add Button in the center of the screen
startButton = LK.getAsset('button', {
anchorX: 0.5,
@@ -780,19 +795,24 @@
} 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
- athlete.isRunning = false;
- athlete.setPosture(idlePosture);
- opponents.forEach(function (opponent) {
- opponent.isRunning = false;
- opponent.setPosture(idlePosture);
- });
+ if (athlete.isRunning) {
+ athlete.isRunning = false;
+ athlete.setPosture(idlePosture);
+ opponents.forEach(function (opponent) {
+ opponent.isRunning = false;
+ opponent.setPosture(idlePosture);
+ });
+ }
}
}
}
}
function checkForCollisions() {
+ if (finishLine.isCut) {
+ return;
+ }
for (var line = 0; line < numberOfLines; line++) {
obstacles[line] = obstacles[line] || [];
if (obstacles[line].length) {
var obstacle = obstacles[line][0]; // Check only the first obstacle in the line
@@ -828,26 +848,34 @@
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;
globalSpeedPerLine[0] = 0;
LK.setTimeout(function () {
- //LK.showGameOver(); // Show game over screen
- globalSpeedPerLine[0] = -10;
+ globalSpeedPerLine[0] = globalBaseSpeed;
+ globalSlowDownAfterJump = false;
athlete.restore();
}, 1000); // Delay game over to allow fall animation to be seen
}
opponents.forEach(function (opponent, index) {
if (opponent.isFalling && !opponent.hasFlashed && !opponent.isOnGround) {
opponent.hasFlashed = true;
LK.setTimeout(function () {
- globalSpeedPerLine[opponent.lineIndex] = -10;
+ globalSpeedPerLine[opponent.lineIndex] = globalBaseSpeed;
opponent.restore();
- }, 1000);
+ }, 2000);
}
});
}
/****************************************************************************************** */
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.