Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: isFalling is not defined' in or related to this line: 'obstacleSpawnTicker += isFalling ? 0 : 1;' Line Number: 474
Code edit (11 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: fallSpeed is not defined' in or related to this line: 'self.rightArm.rotation += (Math.PI / 2 - self.rightArm.rotation) * fallSpeed;' Line Number: 245
Code edit (1 edits merged)
Please save this source code
User prompt
add obstaclesLine2
User prompt
add a second line of obstacles
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: track4 is not defined' in or related to this line: 'track4.update();' Line Number: 458
User prompt
make the new tracks move like the previous one
User prompt
add other tracks above current tracks
Code edit (17 edits merged)
Please save this source code
User prompt
add a debugMarker to the game
Code edit (1 edits merged)
Please save this source code
User prompt
separate gamePlaying code in functions
Code edit (1 edits merged)
Please save this source code
Code edit (22 edits merged)
Please save this source code
User prompt
divide globalspeed by when falling
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Don’t Count a point when falling
Code edit (1 edits merged)
Please save this source code
User prompt
Update score text
Code edit (15 edits merged)
Please save this source code
User prompt
Add a text2 at top center for the score
===================================================================
--- original.js
+++ change.js
@@ -117,36 +117,34 @@
self.speedY = self.jumpSpeed;
}
};
self.update = function () {
- if (self.isOnGround && !self.isFalling) {
- self.leftLeg.height = 200;
- self.leftArm.height = 200;
- self.trunk.rotation = 0.125;
- self.runAnim();
- }
- if (!self.isOnGround && !self.isFalling) {
- //log("self.leftArm.height", self.leftArm.height);
- self.jumpAnim();
- }
- if (!self.isOnGround && !self.isFalling) {
- self.y += self.speedY * Math.abs(globalSpeed / 10);
- self.speedY += self.gravity * Math.abs(globalSpeed / 10);
- var groundY = game.groundLevel - 200;
- if (self.y >= groundY) {
- self.y = groundY;
- self.isOnGround = true;
+ if (!self.isFalling) {
+ if (self.isOnGround) {
+ self.leftLeg.height = 200;
+ self.leftArm.height = 200;
+ self.trunk.rotation = 0.125;
+ self.runAnim();
+ } else {
+ //log("self.leftArm.height", self.leftArm.height);
+ self.jumpAnim();
+ self.y += self.speedY * Math.abs(globalSpeed / 10);
+ self.speedY += self.gravity * Math.abs(globalSpeed / 10);
+ var groundY = game.groundLevel - 200;
+ if (self.y >= groundY) {
+ self.y = groundY;
+ self.isOnGround = true;
+ }
}
- }
- if (self.isFalling) {
- self.y += 10; //self.speedY;
- //self.speedY += self.gravity;
- var groundY = game.groundLevel + 100;
+ } else {
+ self.y += 5;
+ var groundY = game.groundLevel;
if (self.y >= groundY) {
self.y = groundY;
self.isOnGround = true;
}
}
+ self.updatePosture();
};
self.runAnim = function () {
var ocsilDelay = 5;
var armsAmplitude = 0.5;
@@ -158,18 +156,14 @@
self.rightArm.x = 10 * (1 - armSwitchProgress) - 5 * armSwitchProgress;
self.leftArm.x = -15 * (1 - armSwitchProgress) + 20 * armSwitchProgress;
self.rightLeg.x = 5 * (1 - armSwitchProgress) - 5 * armSwitchProgress;
self.leftLeg.x = -10 * (1 - armSwitchProgress) + 10 * armSwitchProgress;
- self.rightArm.rotation = runningArmAngle; // - Math.PI * 0.5;
+ self.rightArm.rotation = runningArmAngle;
self.leftArm.rotation = -runningArmAngle;
self.rightLeg.rotation = -runningLegAngle;
self.leftLeg.rotation = runningLegAngle;
- self.trunk.width = 30 - 10 * (runningArmAngle * Math.PI * 0.5); //armSwitchProgress; // + 10 * Math.abs(runningArmAngle);
- self.head.width = 50 - 10 * (runningArmAngle * Math.PI * 0.5); //armSwitchProgress; // + 10 * Math.abs(runningArmAngle);
- //self.rightArm.height = 180 * (0.5 + Math.abs(runningArmAngle));
- //self.leftArm.height = 150 * (0.7 + Math.abs(runningArmAngle));
- //self.rightLeg.height = 200 * (0.5 + Math.abs(runningArmAngle + Math.PI * 0.125));
- //self.leftLeg.height = 200 * (0.5 + Math.abs(runningArmAngle + Math.PI * 0.125));
+ self.trunk.width = 30 - 10 * (runningArmAngle * Math.PI * 0.5);
+ self.head.width = 50 - 10 * (runningArmAngle * Math.PI * 0.5);
};
self.jumpAnim = function () {
var ocsilDelay = 50;
var armsAmplitude = 1;
@@ -200,26 +194,8 @@
self.leftLeg.rotation += (1 - self.leftLeg.rotation) * rotationSpeed;
self.leftLeg.height -= 0 * rotationSpeed;
self.leftArm.height -= 35 * rotationSpeed;
}
- /*
- if (self.speedY > 0) {
- self.rightArm.rotation += (0 - self.rightArm.rotation) * rotationSpeed;
- self.leftArm.rotation += (0 - self.leftArm.rotation) * rotationSpeed;
- // Return legs to initial rotation when descending
- self.rightLeg.rotation += (0 - self.rightLeg.rotation) * rotationSpeed;
- self.leftLeg.rotation += (0 - self.leftLeg.rotation) * rotationSpeed;
- self.leftLeg.height += 35 * rotationSpeed;
- self.leftArm.height += 35 * rotationSpeed;
- } else {
- self.rightArm.rotation += -Math.PI * 3 * rotationSpeed;
- self.leftArm.rotation += Math.PI * 1.75 * rotationSpeed;
- self.rightLeg.rotation += (2 - self.rightLeg.rotation) * rotationSpeed;
- self.leftLeg.rotation += (1.8 - self.leftLeg.rotation) * rotationSpeed;
- self.leftLeg.height -= 35 * rotationSpeed;
- self.leftArm.height -= 35 * rotationSpeed;
- }
- */
};
self.fallAnim = function () {
var fallSpeed = 0.1; // Speed of fall animation
// Adjust body parts to simulate falling
@@ -251,11 +227,10 @@
/****************************************************************************************** */
/************************************** OBSTACLE CLASS ************************************ */
/****************************************************************************************** */
// Obstacle class
-var Obstacle = Container.expand(function (index) {
+var Obstacle = Container.expand(function () {
var self = Container.call(this);
- self.index = index;
self.leftRod = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0 // Anchor at the bottom for collision detection
});
@@ -275,13 +250,8 @@
self.speedX = globalSpeed;
self.update = function () {
self.speedX = globalSpeed;
self.x += self.speedX;
- // Remove obstacle if it moves off-screen
- if (self.x < -100) {
- self.destroy();
- obstacles.splice(self.index, 1);
- }
};
});
/****************************************************************************************** */
/************************************** TRACK CLASS ************************************ */
@@ -295,8 +265,9 @@
anchorY: 0.0
});
// Method to update track position
self.update = function () {
+ self.speedX = globalSpeed;
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,8 +284,17 @@
/****
* Game Code
****/
+// Debug Marker
+var debugMarker = LK.getAsset('debugMarker', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 1024,
+ // Center of the screen horizontally
+ y: 1366 // Center of the screen vertically
+});
+game.addChild(debugMarker);
// Enumeration for game states
/****************************************************************************************** */
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */
@@ -332,8 +312,9 @@
var obstacles = [];
var groundLevel = 2732 - 200; // Ground level set 200px from the bottom
var obstacleSpawnTicker = 0;
var obstacleSpawnRate = 180; // Spawn an obstacle every 2 seconds
+var obstacleJustPassed = false;
var isDebug = true;
var track;
var track2;
var track3;
@@ -431,84 +412,33 @@
game.groundLevel = groundLevel;
gameState = GAME_STATE.PLAYING;
}
function gamePlaying() {
- log("Game playing...");
- athlete.update();
- athlete.updatePosture();
- // Move obstacles and check for off-screen
- /*
- for (var i = obstacles.length - 1; i >= 0; i--) {
- obstacles[i].move();
- // Remove obstacle if it moves off-screen and increase global speed
- if (obstacles[i].x < -100 && !athlete.isFalling) {
- // Assuming obstacle width is less than 100px
- obstacles[i].destroy();
- obstacles.splice(i, 1);
- }
- }
- */
+ //log("Game playing...");
// Spawn obstacles
spawnObstacles();
// Update obstacles
updateObstacles();
- /* update Progress
- // Increase global speed after each obstacle passed and add 1 to score only if not falling
- globalSpeed -= globalSpeedIncreaseStep; // Increase the speed
- track.speedX = globalSpeed; // Update track speed
- track2.speedX = globalSpeed; // Update track2 speed
- 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
- obstacles.forEach(function (obstacle) {
- // Update all obstacles speed
- obstacle.speedX = globalSpeed;
- });
- */
- /*
- obstacleSpawnTicker++;
- if (obstacleSpawnTicker >= obstacleSpawnRate) {
- obstacleSpawnTicker = 0;
- var newObstacle = new Obstacle(obstacles.length);
- newObstacle.x = 2048; // Start from the right edge
- newObstacle.y = groundLevel + 200;
- obstacles.push(newObstacle);
- game.addChild(newObstacle);
- }
- if (!(athlete.isFalling && athlete.isOnGround)) {
- track.update();
- track2.update();
- track3.update();
- } else {
- // Stop obstacles movement when athlete is falling and on ground
- obstacles.forEach(function (obstacle) {
- obstacle.speedX = 0;
- });
- }
- */
+ // Update tracks
+ updateTracks();
+ // Update Progress
+ updateProgress();
+ // Update athlete
+ athlete.update();
game.addChild(athlete);
// Check for collisions
- obstacles.forEach(function (obstacle) {
- if (athlete.intersects(obstacle.centralRod)) {
- athlete.isFalling = true;
- athlete.isOnGround = false;
- athlete.fallAnim(); // Call fall animation before game over
- if (!athlete.hasFlashed) {
- LK.effects.flashScreen(0xaaaaaa, 500); // Flash screen red for half a second
- athlete.hasFlashed = true;
- }
- LK.setTimeout(function () {
- LK.showGameOver(); // Show game over screen
- }, 600); // Delay game over to allow fall animation to be seen
- }
- });
- if (athlete.hasFlashed && athlete.isFalling && athlete.isOnGround) {
- LK.effects.flashScreen(0xff0000, 100); // Flash screen red for half a second
- athlete.hasFlashedGround = true;
- }
+ checkForCollisions();
}
/****************************************************************************************** */
/************************************** GAME FUNCTIONS ************************************ */
/****************************************************************************************** */
+function updateTracks() {
+ if (!(athlete.isFalling && athlete.isOnGround)) {
+ track.update();
+ track2.update();
+ track3.update();
+ }
+}
function spawnObstacles() {
// Spawn obstacles
obstacleSpawnTicker++;
if (obstacleSpawnTicker >= obstacleSpawnRate) {
@@ -521,12 +451,54 @@
}
}
function updateObstacles() {
// Update obstacles
+ for (var i = obstacles.length - 1; i >= 0; i--) {
+ obstacles[i].update();
+ // Remove obstacle if it moves off-screen and increase global speed
+ if (obstacles[i].x < -100) {
+ // Assuming obstacle width is less than 100px
+ obstacles[i].destroy();
+ obstacles.splice(i, 1);
+ obstacleJustPassed = true;
+ }
+ }
+}
+function updateProgress() {
+ if (obstacleJustPassed) {
+ // Update Progress
+ 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
+ }
+}
+function checkForCollisions() {
obstacles.forEach(function (obstacle) {
- obstacle.update();
+ if (athlete.intersects(obstacle.centralRod)) {
+ athlete.isFalling = true;
+ athlete.isOnGround = false;
+ athlete.fallAnim(); // Call fall animation before game over
+ }
});
+ handleFallEvent();
}
+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;
+ }
+ 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;
+ LK.setTimeout(function () {
+ LK.showGameOver(); // Show game over screen
+ }, 1000); // Delay game over to allow fall animation to be seen
+ }
+}
/****************************************************************************************** */
/************************************** 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.