Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'intersects')' in or related to this line: 'if (opponents[line - 1].intersects(obstacle.centralRod)) {' Line Number: 630
Code edit (13 edits merged)
Please save this source code
User prompt
reverse opponents spawn order
User prompt
reverse opponents spawn
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'restore')' in or related to this line: 'opponents[i].restore();' Line Number: 633
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'restore')' in or related to this line: 'opponents[i].restore();' Line Number: 632
Code edit (3 edits merged)
Please save this source code
User prompt
in gameInitialize, after startButton init, on button press, call cleanMenuState and switch to playing state
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'on')' in or related to this line: 'startButton.on('down', function () {' Line Number: 419
User prompt
on button press, call cleanMenuState and switch to playing state
Code edit (1 edits merged)
Please save this source code
User prompt
add a button Asset at the center of the screen before the Start text. don't replace Start text
Code edit (1 edits merged)
Please save this source code
User prompt
add a button Asset at the center of the screen
Code edit (1 edits merged)
Please save this source code
User prompt
add a Start Text in the center of the screen
Code edit (3 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: 'for (var i = obstacles[line].length - 1; i >= 0; i--) {' Line Number: 529
Code edit (1 edits merged)
Please save this source code
User prompt
update updateObstacles for the new obstacles array system
User prompt
Please fix the bug: 'ReferenceError: obstaclesLine1 is not defined' in or related to this line: 'for (var i = obstaclesLine1.length - 1; i >= 0; i--) {' Line Number: 540
User prompt
update checkForCollisions for the new obstacles array system
===================================================================
--- original.js
+++ change.js
@@ -162,14 +162,13 @@
} else {
//self.x += 4 - 8 * Math.random();
self.x += globalSpeedPerLine[self.lineIndex] * 0.05 * Math.random();
}
- // Auto jump hurdles in obstaclesLine1
+ // Auto jump hurdles in obstacles[self.lineIndex]
if (self.isOnGround) {
- for (var i = 0; i < obstaclesLine1.length; i++) {
- var distance = obstaclesLine1[i].x - self.x;
+ for (var i = 0; i < obstacles[self.lineIndex].length; i++) {
+ var distance = obstacles[self.lineIndex][i].x - self.x;
if (distance > 0 && distance <= 200) {
- //Math.max(50, (300 - globalSpeedPerLine[0]*2))) {//self.lineIndex
self.jump();
break; // Jump once for the closest obstacle within range
}
}
@@ -336,12 +335,13 @@
var gameState = GAME_STATE.INIT;
var athlete;
var opponents = [];
var numberOfOpponents = 3; // Adjust based on the actual number of opponents in the game
-var obstacles = [[], []]; // 2D array for obstacles on different lines
var groundLevel = 2732 - 200; // Ground level set 200px from the bottom
var linesGroundLevels = [groundLevel - 200, groundLevel - 420, groundLevel - 640]; // Ground level set 200px from the bottom
var groundLevelLine1 = 2732 - 200; // Ground level set 200px from the bottom
+var numberOfLines = 1 + numberOfOpponents;
+var obstacles = [[], []];
var obstacleSpawnTicker = 0;
var obstacleSpawnRate = 180; // Spawn an obstacle every 2 seconds
var obstacleJustPassed = false;
var track;
@@ -497,25 +497,21 @@
// Spawn obstacles
obstacleSpawnTicker += athlete.isFalling ? 0 : 1;
if (obstacleSpawnTicker >= obstacleSpawnRate) {
obstacleSpawnTicker = 0;
- // Line 1
- var newObstacle = new Obstacle(0);
- newObstacle.x = 2048; // Start from the right edge
- newObstacle.y = groundLevel + 200;
- obstacles.push(newObstacle);
- game.addChild(newObstacle);
- // Line 2
- var newObstacle2 = new Obstacle(1);
- newObstacle2.x = 2048 + 100; // Start from the right edge
- newObstacle2.y = groundLevel + 200 - 220;
- obstaclesLine1.push(newObstacle2);
- game.addChild(newObstacle2);
+ for (var line = 0; line < numberOfLines; line++) {
+ obstacles[line] = obstacles[line] || [];
+ var newObstacle = new Obstacle(line);
+ newObstacle.x = 2048; // Start from the right edge
+ newObstacle.y = groundLevel + 200 - 220 * line;
+ obstacles[line].push(newObstacle);
+ game.addChild(newObstacle);
+ }
}
}
function updateObstacles() {
// Update obstacles
- for (var line = 0; line < obstacles.length; line++) {
+ for (var line = 0; line < numberOfLines; line++) {
for (var i = obstacles[line].length - 1; i >= 0; i--) {
obstacles[line][i].update();
// Remove obstacle if it moves off-screen and increase global speed
if (obstacles[line][i].x < -100) {
@@ -533,28 +529,30 @@
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
- globalSpeedPerLine[0] -= globalSpeedIncreaseStep; // Increase the speed
- globalSpeedPerLine[1] -= globalSpeedIncreaseStep; // Increase the speed
+ for (var line = 0; line < numberOfLines; line++) {
+ globalSpeedPerLine[line] += globalSpeedIncreaseStep;
+ }
}
}
function checkForCollisions() {
- for (var line = 0; line < obstacles.length; line++) {
+ for (var line = 0; line < numberOfLines; line++) {
for (var i = 0; i < obstacles[line].length; i++) {
var obstacle = obstacles[line][i];
- if (athlete.lineIndex === line && athlete.intersects(obstacle.centralRod)) {
- athlete.isFalling = true;
- athlete.isOnGround = false;
- athlete.fallAnim(); // Call fall animation before game over
- }
- opponents.forEach(function (opponent) {
- if (opponent.lineIndex === line && opponent.intersects(obstacle.centralRod)) {
- opponent.isFalling = true;
- opponent.isOnGround = false;
- opponent.fallAnim(); // Call fall animation before game over
+ 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)) {
+ opponents[line - 1].isFalling = true;
+ opponents[line - 1].isOnGround = false;
+ opponents[line - 1].fallAnim(); // Call fall animation before game over
+ }
+ }
}
}
handleFallEvent();
}
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.