User prompt
Please fix the bug: 'TypeError: obstacles[i].update is not a function' in or related to this line: 'obstacles[i].update();' Line Number: 529
User prompt
use a 2 dimension array for obstacle lines
Code edit (1 edits merged)
Please save this source code
User prompt
use the opponents array instead of oppenent1 in all the code where oppenent1 is used
User prompt
use the opponents array instead of oppenent1 in all the code where oppenent1 is used
User prompt
use the opponents array instead of oppenent1
Code edit (13 edits merged)
Please save this source code
User prompt
add a global variable for the number of opponents
User prompt
add an array for opponents
User prompt
add all request code for opponent2
User prompt
in the same way as opponnent1, add an opponnent2 with all necessery stuff
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in Athlete class use the line as an index in color array for the tint
Code edit (5 edits merged)
Please save this source code
User prompt
add an array of colors
Code edit (6 edits merged)
Please save this source code
User prompt
In athlete update() if isAi, call jump once when an obstacle of obstaclesLine1 is at a x distance of 300
Code edit (1 edits merged)
Please save this source code
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: 'ReferenceError: opponent1 is not defined' in or related to this line: 'opponent1.update();' Line Number: 453
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'rightArm')' in or related to this line: 'self.rightArm.rotation = idlePosture.rightArm.r;' Line Number: 236
User prompt
add an opponent1 athlete at x=400, y=groundLevel-200-220
===================================================================
--- original.js
+++ change.js
@@ -8,10 +8,12 @@
/************************************* ATHLETE CLASS ************************************** */
/****************************************************************************************** */
var Athlete = Container.expand(function (line) {
var self = Container.call(this);
- self.speedX = -globalSpeed;
+ self.speedX = -1 * globalSpeedPerLine[line];
self.jumpSpeed = -17;
+ self.lastJumpTime = 0;
+ self.interJumpDelayMs = 500;
self.gravity = 0.5;
self.lineIndex = line;
self.isAi = line > 0;
self.isOnGround = true;
@@ -71,9 +73,9 @@
// FUNCTIONS
self.updatePosture = function () {
var speed = 0.2; // Speed of transition
if (!self.targetPosture) {
- log("no targetPosture.");
+ //log("no targetPosture.");
return;
}
// Check if the target posture for hands and legs is reached
//log("self.targetPosture: " + self.targetPosture.name + " : self.rightHand.x: " + self.rightHand.x, " self.targetPosture.rightHand.x: " + self.targetPosture.rightHand.x);
@@ -116,12 +118,13 @@
self.moveRight = function () {
self.x += self.speedX;
};
self.jump = function () {
- globalSpeed = globalSpeed * 0.8;
- if (self.isOnGround) {
+ globalSpeedPerLine[self.lineIndex] = globalSpeedPerLine[self.lineIndex] * 0.9;
+ if (self.isOnGround && Date.now() - self.lastJumpTime > self.interJumpDelayMs) {
self.isOnGround = false;
self.speedY = self.jumpSpeed;
+ self.lastJumpTime = Date.now();
log("--------------- JUMP --------------------");
}
};
self.update = function () {
@@ -131,10 +134,10 @@
self.leftArm.height = 200;
self.trunk.rotation = 0.125;
self.runAnim();
} else {
- self.speedY += self.gravity * Math.abs(globalSpeed / 10);
- self.y += self.speedY * Math.abs(globalSpeed / 10);
+ self.speedY += self.gravity * Math.abs(globalSpeedPerLine[0] / 10); //self.lineIndex
+ self.y += self.speedY * Math.abs(globalSpeedPerLine[0] / 10); //self.lineIndex
//log("self.speedY=" + self.speedY, " / self.y=" + self.y);
if (self.y >= linesGroundLevels[self.lineIndex]) {
self.y = linesGroundLevels[self.lineIndex];
self.isOnGround = true;
@@ -151,20 +154,22 @@
self.speedY = 0;
}
}
self.updatePosture();
+ /* ********************************************************** ATHLETE AI **************************************************** */
if (self.isAi) {
if (athlete.isFalling) {
self.moveRight();
} else {
//self.x += 4 - 8 * Math.random();
- self.x += globalSpeed * 0.05 * Math.random();
+ self.x += globalSpeedPerLine[self.lineIndex] * 0.05 * Math.random();
}
// Auto jump hurdles in obstaclesLine1
if (self.isOnGround) {
for (var i = 0; i < obstaclesLine1.length; i++) {
var distance = obstaclesLine1[i].x - self.x;
- if (distance > 0 && distance <= 300) {
+ 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
}
}
@@ -256,10 +261,11 @@
/****************************************************************************************** */
/************************************** OBSTACLE CLASS ************************************ */
/****************************************************************************************** */
// Obstacle class
-var Obstacle = Container.expand(function () {
+var Obstacle = Container.expand(function (line) {
var self = Container.call(this);
+ self.lineIndex = line;
self.leftRod = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0 // Anchor at the bottom for collision detection
});
@@ -275,28 +281,28 @@
anchorY: 0.0,
x: 95,
y: -460
});
- self.speedX = globalSpeed;
+ self.speedX = globalSpeedPerLine[0];
self.update = function () {
- self.speedX = globalSpeed;
+ self.speedX = globalSpeedPerLine[0];
self.x += self.speedX;
};
});
/****************************************************************************************** */
/************************************** TRACK CLASS ************************************ */
/****************************************************************************************** */
var Track = Container.expand(function () {
var self = Container.call(this);
- self.speedX = globalSpeed; // Use global speed for track movement
+ self.speedX = globalSpeedPerLine[0]; // Use global speed for track movement
// Attach track asset
self.trackAsset = self.attachAsset('track', {
anchorX: 0.0,
anchorY: 0.0
});
// Method to update track position
self.update = function () {
- self.speedX = globalSpeed;
+ self.speedX = globalSpeedPerLine[0];
self.x += self.speedX;
// Reset position to create a continuous track effect
if (self.x <= -2048 - self.speedX * 2) {
self.x = 2048 + self.speedX * 2;
@@ -313,12 +319,12 @@
/****
* Game Code
****/
-// Enumeration for game states
/****************************************************************************************** */
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */
+// Enumeration for game states
var GAME_STATE = {
INIT: 'INIT',
MENU: 'MENU',
HELP: 'HELP',
@@ -344,8 +350,9 @@
var track4;
var scoreTxt;
var globalSpeed = -10; //-10; // Global speed for tracks and obstacles min = -4
var globalSpeedIncreaseStep = 5;
+var globalSpeedPerLine = [-10, -10];
var colorsArray = [0x1188FF, 0xFF0000, 0x00FF00, 0xFFFF00, 0xFF00FF, 0x00FFFF, 0xFFFFFF, 0xFF8811];
var isDebug = true;
var debugMarker;
/****************************************************************************************** */
@@ -440,8 +447,11 @@
athlete.restore();
// Initialize opponents
opponent1 = game.addChild(new Athlete(1));
opponent1.restore();
+ // Initialize opponent2
+ opponent2 = game.addChild(new Athlete(2));
+ opponent2.restore();
gameState = GAME_STATE.PLAYING;
if (isDebug) {
// Debug Marker
debugMarker = LK.getAsset('debugMarker', {
@@ -488,15 +498,15 @@
obstacleSpawnTicker += athlete.isFalling ? 0 : 1;
if (obstacleSpawnTicker >= obstacleSpawnRate) {
obstacleSpawnTicker = 0;
// Line 1
- var newObstacle = new Obstacle(obstacles.length);
+ 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(obstaclesLine1.length);
+ 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);
@@ -530,9 +540,10 @@
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
- globalSpeed -= globalSpeedIncreaseStep; // Increase the speed
+ globalSpeedPerLine[0] -= globalSpeedIncreaseStep; // Increase the speed
+ globalSpeedPerLine[1] -= globalSpeedIncreaseStep; // Increase the speed
}
}
function checkForCollisions() {
obstacles.forEach(function (obstacle) {
@@ -552,17 +563,17 @@
function handleFallEvent() {
if (athlete.isFalling && !athlete.hasFlashed) {
LK.effects.flashScreen(0xaaaaaa, 500); // Flash screen red for half a second
athlete.hasFlashed = true;
- globalSpeed /= 1.5;
+ globalSpeedPerLine[0] /= 1.5;
}
if (athlete.hasFlashed && !athlete.hasFlashedGround && athlete.isFalling && athlete.isOnGround) {
LK.effects.flashScreen(0xff0000, 500); // Flash screen red for half a second
athlete.hasFlashedGround = true;
- globalSpeed = 0;
+ globalSpeedPerLine[0] = 0;
LK.setTimeout(function () {
//LK.showGameOver(); // Show game over screen
- globalSpeed = -10;
+ globalSpeedPerLine[0] = -10;
athlete.restore();
}, 1000); // Delay game over to allow fall animation to be seen
}
}
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.