Code edit (1 edits merged)
Please save this source code
Code edit (18 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: athlete.setposition is not a function' in or related to this line: 'athlete.setposition(startingBlockPosture);' Line Number: 874
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
use startingBlocks class in initHurdlesStartingState
User prompt
create a class for startingBlocks
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: athletes is not defined' in or related to this line: 'var startingBlocks = LK.getAsset('startingBlocks', {' Line Number: 826
User prompt
in initHurdlesStartingState add startingblocks to the game
Code edit (10 edits merged)
Please save this source code
User prompt
create a new posture 'startingBlockPosture'
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -123,79 +123,79 @@
if (self.isAi) {
// AI Athlete
var nextX = self.x;
self.previousX = self.x;
- var deltaSpeed = Math.abs(globalSpeedPerLine[self.lineIndex]) - Math.abs(globalSpeedPerLine[0]);
- nextX += deltaSpeed;
- if (!self.isFalling) {
- // Normal running
- if (self.isOnGround) {
- // Running
- self.leftLeg.height = 200;
- self.leftArm.height = 200;
- if (self.isRunning) {
- self.trunk.rotation = 0.125;
- self.runAnim();
- }
- // Auto jump first hurdle of the line
- if (obstacles[self.lineIndex].length) {
- var distance = obstacles[self.lineIndex][0].x - nextX;
- if (self.lineIndex == 1) {
- log((self.isOnGround ? 'On ground' : 'In air') + " / x=" + self.x + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
+ if (self.isRunning) {
+ var deltaSpeed = Math.abs(globalSpeedPerLine[self.lineIndex]) - Math.abs(globalSpeedPerLine[0]);
+ nextX += deltaSpeed;
+ if (!self.isFalling) {
+ // Normal running
+ if (self.isOnGround) {
+ // Running
+ self.leftLeg.height = 200;
+ self.leftArm.height = 200;
+ if (self.isRunning) {
+ self.trunk.rotation = 0.125;
+ self.runAnim();
}
- if (self.x > aiJumpLeftLimit && self.x < aiJumpRightLimit && distance > 0 && distance <= 300) {
- self.jump();
+ // Auto jump first hurdle of the line
+ if (obstacles[self.lineIndex].length) {
+ var distance = obstacles[self.lineIndex][0].x - nextX;
+ if (self.lineIndex == 1) {
+ log((self.isOnGround ? 'On ground' : 'In air 1') + " / x=" + self.x + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
+ }
+ if (self.x > aiJumpLeftLimit && self.x < aiJumpRightLimit && distance > 0 && distance <= 300) {
+ self.jump();
+ } else {
+ // Reduce advance when out of screen
+ var normalize = self.nextHurdleSpeedX;
+ normalize = self.x < -200 ? Math.abs(normalize) : normalize;
+ normalize = self.x > 2100 ? -10 + Math.random() * 2 : normalize;
+ normalize = self.x > 3000 ? -20 : normalize;
+ nextX += normalize;
+ }
+ }
+ } else {
+ if (obstacles[self.lineIndex].length) {
+ var distance = obstacles[self.lineIndex][0].x - nextX;
+ if (self.lineIndex == 1) {
+ log((self.isOnGround ? 'On ground' : 'In air 2') + " / x=" + self.x + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
+ }
+ }
+ // 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
+ self.nextHurdleSpeedX = -1 + (-5 + 10 * Math.random()); //(1 - difficultyLevel) * 4 + difficultyLevel * 2 * Math.random();
+ if (obstacles[self.lineIndex].length <= 3 && self.x > athlete.x) {
+ self.nextHurdleSpeedX = -1 * Math.abs(self.nextHurdleSpeedX);
+ }
} else {
- // Reduce advance when out of screen
- var normalize = self.nextHurdleSpeedX;
- normalize = self.x < -200 ? Math.abs(normalize) : normalize;
- normalize = self.x > 2100 ? -10 + Math.random() * 2 : normalize;
- normalize = self.x > 3000 ? -20 : normalize;
- nextX += normalize;
+ self.jumpAnim();
}
}
} else {
- if (obstacles[self.lineIndex].length) {
- var distance = obstacles[self.lineIndex][0].x - nextX;
- if (self.lineIndex == 1) {
- log((self.isOnGround ? 'On ground' : 'In air') + " / x=" + self.x + " / y=" + self.y + " / DeltaY=" + (obstacles[self.lineIndex][0].y - obstacles[self.lineIndex][0].centralRod.y - self.y) + " / distance=" + distance);
- }
- }
- // 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);
+ // Falling
+ self.y += 5;
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
- self.nextHurdleSpeedX = -1 + (-5 + 10 * Math.random()); //(1 - difficultyLevel) * 4 + difficultyLevel * 2 * Math.random();
- if (obstacles[self.lineIndex].length <= 3 && self.x > athlete.x) {
- self.nextHurdleSpeedX = -1 * Math.abs(self.nextHurdleSpeedX);
- }
} else {
- self.jumpAnim();
+ self.fallAnim();
}
}
} else {
- // Falling
- self.y += 5;
- if (self.y >= linesGroundLevels[self.lineIndex]) {
- self.isOnGround = true;
- self.speedY = 0;
- self.y = linesGroundLevels[self.lineIndex];
- } else {
- self.fallAnim();
- }
- }
- if (!self.isRunning) {
if (self.lineIndex == 1) {
log("WAITING / x=" + self.x + " / y=" + self.y + " / globalSpeedPerLine[0]=" + globalSpeedPerLine[0]);
log("rightArm len=" + self.rightArm.height);
}
nextX += -1 * globalSpeedPerLine[0];
- self.victoryAnim();
}
// Update athlete position
self.x = nextX;
self.previousX = self.x;
@@ -323,9 +323,9 @@
self.leftLeg.rotation += (Math.PI / 2 - self.leftLeg.rotation) * fallSpeed;
};
self.victoryAnim = function () {
if (self.lineIndex == 1) {
- log("Check finish for #3 at x=" + opponents[line - 1].x + " vs " + (finishLine.x + 512));
+ log("Victory #1");
}
var jumpHeight = 10;
var waveSpeed = 0.1;
var armWaveAmplitude = 0.5;
@@ -341,10 +341,10 @@
self.isOnGround = true;
}
}
// Wave arms
- self.rightArm.rotation = Math.max(-armWaveAmplitude, Math.min(armWaveAmplitude, Math.sin(LK.ticks * waveSpeed) * armWaveAmplitude));
- self.leftArm.rotation = Math.max(-armWaveAmplitude, Math.min(armWaveAmplitude, -Math.sin(LK.ticks * waveSpeed) * armWaveAmplitude));
+ self.rightArm.rotation = Math.max(-armWaveAmplitude, Math.min(armWaveAmplitude, Math.sin(LK.ticks * waveSpeed) * armWaveAmplitude)) + Math.PI;
+ self.leftArm.rotation = Math.max(-armWaveAmplitude, Math.min(armWaveAmplitude, -Math.sin(LK.ticks * waveSpeed) * armWaveAmplitude * 0.5));
};
self.setPosture = function (newPosture) {
log("Set posture: " + newPosture.name);
self.targetPosture = newPosture;
@@ -402,8 +402,14 @@
self.leftRod = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0 // Anchor at the bottom for collision detection
});
+ self.flag = self.attachAsset('finishFlag', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ x: 580,
+ y: -1540
+ });
self.speedX = globalSpeedPerLine[0];
self.update = function () {
self.speedX = globalSpeedPerLine[0];
self.x += self.speedX;
@@ -485,12 +491,12 @@
/****
* Game Code
****/
-// Enumeration for game states
/****************************************************************************************** */
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */
+// Enumeration for game states
var GAME_STATE = {
INIT: 'INIT',
MENU: 'MENU',
HELP: 'HELP',
@@ -505,9 +511,9 @@
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; //20; // Total number of hurdles
+var numberOfObstacles = 1; //20; //20; // Total number of hurdles
var obstacles = [[]];
var obstacleSpawnTicker = 0;
var obstacleSpawnDistanceRate = 1.5; // Ratio of screen width between obstacles
var obstacleJustPassed = false;
@@ -524,9 +530,10 @@
var track2;
var track3;
var track4;
var scoreTxt;
-var globalBaseSpeed = 0; // -20;
+var currentFinishPosition = 0;
+var globalBaseSpeed = -20;
var globalSpeedPerLine = []; // Global speed for tracks and obstacles default -10 / min = -4
var difficultyLevel = 1; // TODO : Move to global
var colorsArray = [0x1188FF, 0xFF0000, 0x00FF00, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF, 0xFF8811];
var isDebug = true;
@@ -752,14 +759,12 @@
// Initialize opponents
for (var i = numberOfOpponents - 1; i >= 0; i--) {
opponents[i] = game.addChild(new Athlete(i + 1));
opponents[i].restore();
- opponents[i].isRunning = false; //TEMP DEBUG
}
// Initialize athlete
athlete = game.addChild(new Athlete(0));
athlete.restore();
- athlete.isRunning = false;
gameState = GAME_STATE.PLAYING;
}
/****************************************************************************************** */
/************************************** GAME FUNCTIONS ************************************ */
@@ -862,8 +867,18 @@
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
}
+ for (var line = 0; line < numberOfLines; line++) {
+ if (line == 0 && !athlete.finishPosition) {
+ athlete.finishPosition = getFinishPosition();
+ log("athlete => #" + athlete.finishPosition);
+ }
+ if (line > 0 && !opponents[line - 1].finishPosition && opponents[line - 1].x > finishLine.x) {
+ opponents[line - 1].finishPosition = getFinishPosition();
+ log("opponent " + line + "=> #" + opponents[line - 1].finishPosition);
+ }
+ }
if (finishLine.isCut) {
for (var line = 0; line < numberOfLines; line++) {
if (line > 0 && opponents[line - 1].x < 0)
// let opponents finish
@@ -963,8 +978,11 @@
}, 2000);
}
});
}
+function getFinishPosition() {
+ return currentFinishPosition++;
+}
/****************************************************************************************** */
/************************************** MAIN GAME LOOP ************************************ */
/****************************************************************************************** */
LK.on('tick', function () {
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.