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
Code edit (2 edits merged)
Please save this source code
User prompt
in gameInitialize, mirror vertically track3 and track4
User prompt
in gameInitialize, vertically reverse track3 and track4
Code edit (18 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -16,8 +16,9 @@
self.gravity = 0.5;
self.lineIndex = line;
self.isAi = line > 0;
self.isOnGround = true;
+ self.isRunning = false;
self.isFalling = false; // Indicates if the athlete is currently falling
self.currentPosture = ""; // Store the name of the current posture
self.isChangingPosture = false; // 0 when idle or moving down, 1 when moving up
self.nextPosture = null;
@@ -134,9 +135,11 @@
if (self.isOnGround) {
self.leftLeg.height = 200;
self.leftArm.height = 200;
self.trunk.rotation = 0.125;
- self.runAnim();
+ if (self.isRunning) {
+ self.runAnim();
+ }
} else {
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);
@@ -273,11 +276,51 @@
self.isFalling = false;
self.isOnGround = true;
self.hasFlashed = false;
self.hasFlashedGround = false;
+ self.isRunning = true;
};
});
/****************************************************************************************** */
+/************************************** FINISH LINE CLASS ************************************ */
+/****************************************************************************************** */
+var FinishLine = Container.expand(function () {
+ var self = Container.call(this);
+ self.leftRod = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 1.0 // Anchor at the bottom for collision detection
+ });
+ self.centralRodRight = self.attachAsset('finishLine', {
+ anchorX: 0.5,
+ anchorY: 1,
+ y: -200,
+ rotation: Math.PI * 0.125,
+ tint: 0x00ff00
+ });
+ self.centralRodLeft = self.attachAsset('finishLine', {
+ anchorX: 0.5,
+ anchorY: 1,
+ y: -200,
+ rotation: Math.PI * 0.125,
+ tint: 0x0000ff
+ });
+ self.rightRod = self.attachAsset('obstacle', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ x: 95 + 200,
+ y: -460 - 680
+ });
+ self.speedX = globalSpeedPerLine[0];
+ self.update = function () {
+ self.speedX = globalSpeedPerLine[0];
+ self.x += self.speedX;
+ };
+ self.cut = function () {
+ self.centralRodRight.height = self.centralRodRight.height * 0.5;
+ self.centralRodLeft.height = self.centralRodLeft.height * 0.5;
+ };
+});
+/****************************************************************************************** */
/************************************** OBSTACLE CLASS ************************************ */
/****************************************************************************************** */
// Obstacle class
var Obstacle = Container.expand(function (line) {
@@ -357,14 +400,14 @@
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;
+var numberOfObstacles = 1;
var obstacles = [[]];
var obstacleSpawnTicker = 0;
-var obstacleSpawnRate = 180; // Spawn an obstacle every 2 seconds //TEMP DEBUG
-var obstacleSpawnDistanceRate = 1.5; // Spawn an obstacle 1 screen * 1.5
+var obstacleSpawnDistanceRate = 0.3; //1.5; // Spawn an obstacle 1 screen * 1.5
var obstacleJustPassed = false;
+var finishLine;
var stadium;
var stadiumOdd;
var field;
var fieldOdd;
@@ -458,13 +501,13 @@
function gameInitialize() {
log("Game initialize...");
// Add background asset
scoreTxt = new Text2('0', {
- size: 150,
+ size: 100,
fill: "#ffffff" // White color for better visibility
});
- scoreTxt.anchor.set(0.5, 0); // Center the score text horizontally
- LK.gui.top.addChild(scoreTxt); // Add the score text to the GUI overlay at the top center
+ 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,
@@ -500,16 +543,16 @@
stadium = LK.getAsset('stadium', {
anchorX: 0.0,
anchorY: 0.0,
x: 0,
- y: 0
+ y: 150
});
game.addChild(stadium);
stadiumOdd = LK.getAsset('stadiumOdd', {
anchorX: 0.0,
anchorY: 0.0,
x: 2048,
- y: 0
+ y: 150
});
game.addChild(stadiumOdd);
// Initialize track using Track class
track = game.addChild(new Track(0));
@@ -676,8 +719,12 @@
obstacles[line].push(newObstacle);
game.addChild(newObstacle);
}
}
+ finishLine = new FinishLine();
+ finishLine.x = 2048 * obstacleSpawnDistanceRate * (numberOfObstacles + 1); // Start from the right edge
+ finishLine.y = groundLevel + 200;
+ game.addChild(finishLine);
}
function updateObstacles() {
// Update obstacles
for (var line = 0; line < numberOfLines; line++) {
@@ -694,8 +741,9 @@
}
}
}
}
+ finishLine.update();
}
function updateProgress() {
if (obstacleJustPassed) {
// Update Progress
@@ -704,8 +752,11 @@
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
for (var line = 0; line < numberOfLines; line++) {
globalSpeedPerLine[line] -= globalSpeedIncreaseStep;
+ if (line == 3) {
+ log("new Speed :" + globalSpeedPerLine[line]);
+ }
}
}
}
function checkForCollisions() {
@@ -729,8 +780,17 @@
}
}
}
handleFallEvent();
+ if (athlete.intersects(finishLine.centralRodLeft) || athlete.intersects(finishLine.centralRodRight)) {
+ for (var line = 0; line < numberOfLines; line++) {
+ globalSpeedPerLine[line] = 0;
+ }
+ athlete.isRunning = false;
+ opponents.forEach(function (opponent) {
+ opponent.isRunning = false;
+ });
+ }
}
function handleFallEvent() {
if (athlete.isFalling && !athlete.hasFlashed) {
LK.effects.flashScreen(0xaaaaaa, 500); // Flash screen red for half a second
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.