Code edit (2 edits merged)
Please save this source code
User prompt
in checkForCollisions, the setTimeout uses the iterator line, this can cause unwanted behaviour, secrure this part of the code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: opponents[(line - 1)] is undefined' in or related to this line: 'opponents[line - 1].isRunning = true;' Line Number: 1217
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: blocker is not defined' in or related to this line: 'if (blocker) {' Line Number: 1111
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: opponents[(line - 1)] is undefined' in or related to this line: 'opponents[line - 1].isRunning = true;' Line Number: 1210
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: opponents[(line - 1)] is undefined' in or related to this line: 'log("Line " + line + " : opponent " + opponents[line - 1].lineIndex + " Restore after block");' Line Number: 1207
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: opponents[(line - 1)] is undefined' in or related to this line: 'opponents[line - 1].isRunning = true;' Line Number: 1203
Code edit (17 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: opponent is not defined' in or related to this line: 'opponent.restore();' Line Number: 1202
Code edit (1 edits merged)
Please save this source code
Code edit (19 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: currentPosture is not defined' in or related to this line: 'self.y = linesGroundLevels[self.lineIndex] + (currentPosture.name == startingBlockPosture.name ? 150 : 0);' Line Number: 398
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: obstacles[i][j] is undefined' in or related to this line: 'obstacles[i][j].destroy();' Line Number: 927
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: raceFinishTime is not defined' in or related to this line: 'if (Date.now() - raceFinishTime > 1000) {' Line Number: 726
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self is undefined' in or related to this line: 'self._update_migrated = function () {' Line Number: 1155
User prompt
add an update function in StartingBlocks
===================================================================
--- original.js
+++ change.js
@@ -542,8 +542,9 @@
/****
* Game Code
****/
+var raceFinishTime = 0;
// Enumeration for game states
/****************************************************************************************** */
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */
@@ -576,10 +577,10 @@
var stadium;
var stadiumOdd;
var field;
var fieldOdd;
-var farfield;
-var farfieldOdd;
+var farField;
+var farFieldOdd;
var track;
var track2;
var track3;
var track4;
@@ -696,10 +697,18 @@
break;
}
});
function gamePlayingDown() {
- // Make the athlete jump
- athlete.jump();
+ if (athlete.isRunning && !finishLine.isCut) {
+ // Make the athlete jump
+ athlete.jump();
+ } else {
+ if (Date.now() - raceFinishTime > 1000) {
+ // Return to menu
+ cleanPlayingHurdlesState();
+ initMenuState();
+ }
+ }
}
function hurdlesStartingPlayingDown() {
cleanHurdlesStartingState();
initPlayingState();
@@ -709,17 +718,12 @@
/****************************************************************************************** */
/****************************************************************************************** */
/************************************* GAME STATES **************************************** */
/****************************************************************************************** */
+// GAME INITIALIZE
function gameInitialize() {
log("Game initialize...");
// Add background asset
- scoreTxt = new Text2('0', {
- size: 100,
- fill: "#ffffff" // White color for better visibility
- });
- scoreTxt.anchor.set(1.1, 0.15); // Center the score text horizontally
- LK.gui.topRight.addChild(scoreTxt); // Add the score text to the GUI overlay at the top center
var background = LK.getAsset('background', {
anchorX: 0.0,
anchorY: 0.0,
y: -256,
@@ -781,13 +785,24 @@
// Second line track 2
track4 = game.addChild(new Track(3));
track4.x = 2048;
track4.y = 2732 - 1024;
- // Initialize ground levels & speeds
- for (var line = 0; line < numberOfLines; line++) {
- linesGroundLevels[line] = groundLevel - 200 - 220 * line;
- globalSpeedPerLine[line] = globalBaseSpeed;
+ gameState = GAME_STATE.MENU;
+ initMenuState();
+ if (isDebug) {
+ // Debug Marker
+ debugMarker = LK.getAsset('debugMarker', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ game.addChild(debugMarker);
+ debugMarker.x = 0;
+ debugMarker.y = groundLevel;
}
+}
+// GAME MENU
+function initMenuState() {
+ log("initMenuState...");
// Add Button in the center of the screen
startButton = LK.getAsset('button', {
anchorX: 0.5,
// Center the button horizontally
@@ -799,9 +814,8 @@
});
game.addChild(startButton);
startButton.on('down', function () {
cleanMenuState();
- //initPlayingState();
initHurdlesStartingState();
});
// Add Start Text in the center of the screen
startText = new Text2('START', {
@@ -812,53 +826,23 @@
startText.x = 2048 / 2; // Center horizontally
startText.y = 2732 / 2; // Center vertically
game.addChild(startText);
gameState = GAME_STATE.MENU;
- if (isDebug) {
- // Debug Marker
- debugMarker = LK.getAsset('debugMarker', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- game.addChild(debugMarker);
- debugMarker.x = 0;
- debugMarker.y = groundLevel;
- }
}
-function gamePlaying() {
- //log("Game playing...");
- // Update fields
- updateFields();
- // Update obstacles
- updateObstacles();
- // Update tracks
- updateTracks();
- // Update Progress
- updateProgress();
- // Update opponents
- for (var i = numberOfOpponents - 1; i >= 0; i--) {
- opponents[i]._update_migrated();
- game.addChild(opponents[i]);
- }
- // Update athlete
- athlete._update_migrated();
- game.addChild(athlete);
- // Check for collisions
- checkForCollisions();
-}
-function hurdlesStarting() {
- log("hurdlesStarting...");
- for (var i = 0; i <= numberOfOpponents; i++) {
- var athletes = [athlete].concat(opponents);
- athletes[i]._update_migrated();
- }
-}
function cleanMenuState() {
game.removeChild(startText);
+ startText.destroy();
game.removeChild(startButton);
+ startButton.destroy();
}
+// STARTING HURDLES
function initHurdlesStartingState() {
log("initHurdlesStartingState...");
+ // Initialize ground levels & speeds
+ for (var line = 0; line < numberOfLines; line++) {
+ linesGroundLevels[line] = groundLevel - 200 - 220 * line;
+ globalSpeedPerLine[line] = globalBaseSpeed;
+ }
// Spawn obstacles
spawnObstacles();
// Add starting blocks to each athlete's starting position
for (var i = 0; i <= numberOfOpponents; i++) {
@@ -886,11 +870,68 @@
}
athlete.setPosture(idlePosture);
athlete.isRunning = true;
}
+function hurdlesStarting() {
+ log("hurdlesStarting...");
+ for (var i = 0; i <= numberOfOpponents; i++) {
+ var athletes = [athlete].concat(opponents);
+ athletes[i]._update_migrated();
+ }
+}
+// PLAYING HURDLES
function initPlayingState() {
+ scoreTxt = new Text2('0', {
+ size: 100,
+ fill: "#ffffff" // White color for better visibility
+ });
+ scoreTxt.anchor.set(1.1, 0.15); // Center the score text horizontally
+ LK.gui.topRight.addChild(scoreTxt); // Add the score text to the GUI overlay at the top center
gameState = GAME_STATE.PLAYING;
}
+function cleanPlayingHurdlesState() {
+ // Remove Opponents & Athlete
+ for (var i = numberOfOpponents - 1; i >= 0; i--) {
+ game.removeChild(opponents[i]);
+ opponents[i].destroy();
+ }
+ game.removeChild(athlete);
+ athlete.destroy();
+ // Remove Obstacles
+ for (var i = 0; i < numberOfLines; i++) {
+ for (var j = 0; j < numberOfObstacles; j++) {
+ game.removeChild(obstacles[i][j]);
+ obstacles[i][j].destroy();
+ }
+ }
+ // Remove Finish Line
+ game.removeChild(finishLine);
+ finishLine.destroy();
+ // Remove Score Text
+ LK.gui.topRight.removeChild(scoreTxt);
+ scoreTxt.destroy();
+}
+function gamePlaying() {
+ //log("Game playing...");
+ // Update fields
+ updateFields();
+ // Update obstacles
+ updateObstacles();
+ // Update tracks
+ updateTracks();
+ // Update Progress
+ updateProgress();
+ // Update opponents
+ for (var i = numberOfOpponents - 1; i >= 0; i--) {
+ opponents[i]._update_migrated();
+ game.addChild(opponents[i]);
+ }
+ // Update athlete
+ athlete._update_migrated();
+ game.addChild(athlete);
+ // Check for collisions
+ checkForCollisions();
+}
/****************************************************************************************** */
/************************************** GAME FUNCTIONS ************************************ */
/****************************************************************************************** */
function updateFields() {
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.