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
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: runningArmAngle is not defined' in or related to this line: 'log("Posture rightArm.rotation=" + runningArmAngle);' Line Number: 110
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
In jumpAnim replace LK.ticks bt Date.now()
Code edit (1 edits merged)
Please save this source code
User prompt
In jumpAnim add modulos to lehs rotations to ensure values stay consistent
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'athlete.reset();' Line Number: 435
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: 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
/**** * Classes ****/ /****************************************************************************************** */ /**************************************** CLASSES ***************************************** */ /****************************************************************************************** */ /****************************************************************************************** */ /************************************* ATHLETE CLASS ************************************** */ /****************************************************************************************** */ var Athlete = Container.expand(function () { var self = Container.call(this); self.speedX = 5; self.jumpSpeed = -17; self.gravity = 0.5; self.isOnGround = true; 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; self.tint = 0xc0d4FF; // BODY PARTS self.trunk = self.attachAsset('bodyPart', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1, rotation: 0.125, tint: 0x000000 //self.tint // TEMP DEBUG }); self.head = self.trunk.attachAsset('head', { anchorX: 0.5, anchorY: 2, scaleX: 1, scaleY: 1, tint: 0x000000 // self.tint }); self.rightArm = self.trunk.attachAsset('bodyPart', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1, tint: self.tint }); // Right hand asset attachment removed self.leftArm = self.trunk.attachAsset('bodyPart', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1, tint: self.tint }); // Left hand asset attachment removed self.rightLeg = self.trunk.attachAsset('bodyPart', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1.0, tint: self.tint }); // Right foot asset attachment removed self.leftLeg = self.trunk.attachAsset('bodyPart', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1.0, tint: self.tint }); // Left foot asset attachment removed // FUNCTIONS self.updatePosture = function () { var speed = 0.2; // Speed of transition if (!self.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); var handsAndLegsReached = Math.abs(self.rightLeg.x - self.targetPosture.rightLeg.x) < 1 && Math.abs(self.rightLeg.y - self.targetPosture.rightLeg.y) < 1 && Math.abs(self.leftLeg.x - self.targetPosture.leftLeg.x) < 1 && Math.abs(self.leftLeg.y - self.targetPosture.leftLeg.y) < 1 && Math.abs(self.head.x - self.targetPosture.head.x) < 1 && Math.abs(self.head.y - self.targetPosture.head.y) < 1; if (handsAndLegsReached) { //log("handsAndLegsReached !"); // Update currentPosture to the name of the targetPosture when hands and legs posture is reached self.currentPosture = self.targetPosture.name; self.targetPosture = null; self.isChangingPosture = false; if (self.nextPosture) { self.setPosture(self.nextPosture); } return; } else { self.isChangingPosture = true; } if (self.targetPosture && self.targetPosture.head) { self.head.x += (self.targetPosture.head.x - self.head.x) * speed; } self.trunk.rotation += (self.targetPosture.trunk.r - self.trunk.rotation) * speed; self.head.y += (self.targetPosture.head.y - self.head.y) * speed; self.rightArm.x += (self.targetPosture.rightArm.x - self.rightArm.x) * speed; self.rightArm.y += (self.targetPosture.rightArm.y - self.rightArm.y) * speed; self.rightArm.rotation += (self.targetPosture.rightArm.r - self.rightArm.rotation) * speed; // Right hand updates removed due to hand assets being removed self.leftArm.x += (self.targetPosture.leftArm.x - self.leftArm.x) * speed; self.leftArm.y += (self.targetPosture.leftArm.y - self.leftArm.y) * speed; self.leftArm.rotation += (self.targetPosture.leftArm.r - self.leftArm.rotation) * speed; // Left hand updates removed due to hand assets being removed self.trunk.x += (self.targetPosture.trunk.x - self.trunk.x) * speed; self.trunk.y += (self.targetPosture.trunk.y - self.trunk.y) * speed; self.rightLeg.x += (self.targetPosture.rightLeg.x - self.rightLeg.x) * speed; self.rightLeg.y += (self.targetPosture.rightLeg.y - self.rightLeg.y) * speed; // Right foot updates removed due to foot assets being removed self.leftLeg.x += (self.targetPosture.leftLeg.x - self.leftLeg.x) * speed; self.leftLeg.y += (self.targetPosture.leftLeg.y - self.leftLeg.y) * speed; }; self.moveRight = function () { self.x += self.speedX; }; self.jump = function () { if (self.isOnGround) { self.isOnGround = false; self.speedY = self.jumpSpeed; } }; self.update = function () { 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.y += self.speedY * Math.abs(globalSpeed / 10); self.speedY += self.gravity * Math.abs(globalSpeed / 10); var groundY = groundLevel - 200; if (self.y >= groundY) { self.y = groundY; self.isOnGround = true; self.speedY = 0; } self.jumpAnim(); } } else { self.y += 5; if (self.y >= groundLevel) { self.y = groundLevel; self.isOnGround = true; self.speedY = 0; } } self.updatePosture(); }; self.runAnim = function () { var ocsilDelay = 5; var armsAmplitude = 0.5; var legsAmplitude = 0.5; // Simulate running by continuously balancing the arms and legs var runningArmAngle = Math.sin(LK.ticks / ocsilDelay) * armsAmplitude; // Oscillate arm angle to simulate running faster var runningLegAngle = Math.sin(LK.ticks / ocsilDelay) * legsAmplitude; // Oscillate leg angle to simulate running faster var armSwitchProgress = (Math.sin(LK.ticks / 5) + 0) / 2; // Normalize between 0 and 1 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; self.leftArm.rotation = -runningArmAngle; self.rightLeg.rotation = -runningLegAngle; self.leftLeg.rotation = runningLegAngle; 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; // Simulate running by continuously balancing the arms and legs var runningArmAngle = Math.sin(LK.ticks / ocsilDelay) * armsAmplitude; // Oscillate arm angle to simulate running faster var armSwitchProgress = (Math.sin(LK.ticks / 5) + 0) / 2; // Normalize between 0 and 1 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.trunk.width = 30 - 10 * (runningArmAngle * Math.PI * 0.5); //armSwitchProgress; // + 10 * Math.abs(runningArmAngle); self.trunk.rotation = 0.333; //armSwitchProgress; // + 10 * Math.abs(runningArmAngle); var rotationSpeed = .05; // Speed of rotation change 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 -= 30 * rotationSpeed; self.leftArm.height -= 20 * rotationSpeed; } else { self.rightArm.rotation += -Math.PI * 3 * rotationSpeed; self.leftArm.rotation += Math.PI * 1.75 * rotationSpeed; // Continue with jump animation adjustments self.rightLeg.rotation += (-2.6 - self.rightLeg.rotation) * rotationSpeed; self.leftLeg.rotation += (1 - self.leftLeg.rotation) * rotationSpeed; self.leftLeg.height -= 0 * rotationSpeed; self.leftArm.height -= 35 * rotationSpeed; } }; self.fallAnim = function () { var fallSpeed = 0.1; // Speed of fall animation // Adjust body parts to simulate falling self.trunk.rotation += (Math.PI / 2 - self.trunk.rotation) * fallSpeed; self.rightArm.rotation += (Math.PI / 2 - self.rightArm.rotation) * fallSpeed; self.leftArm.rotation += (Math.PI / 2 - self.leftArm.rotation) * fallSpeed; self.rightLeg.rotation += (Math.PI / 2 - self.rightLeg.rotation) * fallSpeed; self.leftLeg.rotation += (Math.PI / 2 - self.leftLeg.rotation) * fallSpeed; }; self.setPosture = function (newPosture) { log("Set posture: " + newPosture.name); if (self.isChangingPosture) { // Store next posture for when target one is reached self.nextPosture = newPosture; return; } if (self.nextPosture) { // If a next posture is set, use it as target newPosture = self.nextPosture; self.nextPosture = null; } if (newPosture && self.currentPosture != newPosture.name) { // Set new posture self.targetPosture = newPosture; } }; self.restore = function () { log("restore..."); self.x = 400; self.y = groundLevel - 200; self.trunk.rotation = 0; self.rightArm.rotation = 0; self.leftArm.rotation = 0; self.rightLeg.rotation = 0; self.leftLeg.rotation = 0; self.setPosture(idlePosture); self.isFalling = false; self.isOnGround = true; self.hasFlashed = false; self.hasFlashedGround = false; }; }); /****************************************************************************************** */ /************************************** OBSTACLE CLASS ************************************ */ /****************************************************************************************** */ // Obstacle class var Obstacle = 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.centralRod = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 1, y: -200, rotation: Math.PI * 0.125, tint: 0xffff00 // Apply a yellow tint for glow effect }); self.rightRod = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 0.0, x: 95, y: -460 }); self.speedX = globalSpeed; self.update = function () { self.speedX = globalSpeed; 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 // 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.x += self.speedX; // Reset position to create a continuous track effect if (self.x <= -2048 - self.speedX * 2) { self.x = 2048 + self.speedX * 2; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to represent the sky }); /**** * Game Code ****/ /****************************************************************************************** */ /************************************** GLOBAL VARIABLES ********************************** */ /****************************************************************************************** */ // Enumeration for game states var GAME_STATE = { INIT: 'INIT', MENU: 'MENU', HELP: 'HELP', STARTING: 'STARTING', NEW_ROUND: 'NEW_ROUND', PLAYING: 'PLAYING', SCORE: 'SCORE' }; var gameState = GAME_STATE.INIT; var athlete; var obstacles = []; var obstaclesLine2 = []; 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 track; var track2; var track3; var track4; var scoreTxt; var globalSpeed = -10; //-10; // Global speed for tracks and obstacles min = -4 var globalSpeedIncreaseStep = 5; var isDebug = true; var debugMarker; /****************************************************************************************** */ /************************************** POSTURES ****************************************** */ /****************************************************************************************** */ var idlePosture = { name: "idlePosture", trunk: { x: 0, y: 0, r: 0.125 }, head: { x: 0, y: 0 }, rightArm: { x: 20, y: -80, r: 0 //Math.PI * 2 * 0.0 }, leftArm: { x: -20, y: -80, r: 0 //Math.PI * 2 * 0.125 }, rightLeg: { x: 5, y: 100 }, leftLeg: { x: -5, y: 100 } }; /****************************************************************************************** */ /*********************************** UTILITY FUNCTIONS ************************************ */ /****************************************************************************************** */ function log() { if (isDebug) { var _console; (_console = console).log.apply(_console, arguments); } } /****************************************************************************************** */ /************************************** INPUT HANDLERS ************************************ */ /****************************************************************************************** */ // Touch event to make the athlete jump game.on('down', function () { athlete.jump(); }); /****************************************************************************************** */ /************************************* AI FUNCTIONS *************************************** */ /****************************************************************************************** */ /****************************************************************************************** */ /************************************* GAME STATES **************************************** */ /****************************************************************************************** */ function gameInitialize() { log("Game initialize..."); // Add background asset scoreTxt = new Text2('0', { size: 150, 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 var background = LK.getAsset('background', { anchorX: 0.0, anchorY: 0.0, visible: false // TEMP DEBUG }); game.addChild(background); // Initialize track using Track class track = game.addChild(new Track()); track.x = 0; track.y = 2732 - 512; // Second track instance for continuous effect track2 = game.addChild(new Track()); track2.x = 2048; // Position the second track right after the first one track2.y = 2732 - 512; // Second line track 1 track3 = game.addChild(new Track()); track3.x = 0; track3.y = 2732 - 1024; // Second line track 2 track4 = game.addChild(new Track()); track4.x = 2048; track4.y = 2732 - 1024; // Initialize athlete athlete = game.addChild(new Athlete()); athlete.x = 400; athlete.y = groundLevel - 200; athlete.setPosture(idlePosture); athlete.restore(); gameState = GAME_STATE.PLAYING; 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..."); // Spawn obstacles spawnObstacles(); // Update obstacles updateObstacles(); // Update tracks updateTracks(); // Update Progress updateProgress(); // Update athlete athlete.update(); game.addChild(athlete); // Check for collisions checkForCollisions(); } /****************************************************************************************** */ /************************************** GAME FUNCTIONS ************************************ */ /****************************************************************************************** */ function updateTracks() { if (!(athlete.isFalling && athlete.isOnGround)) { track.update(); track2.update(); track3.update(); track4.update(); } } function spawnObstacles() { // Spawn obstacles obstacleSpawnTicker += athlete.isFalling ? 0 : 1; if (obstacleSpawnTicker >= obstacleSpawnRate) { obstacleSpawnTicker = 0; // Line 1 var newObstacle = new Obstacle(obstacles.length); newObstacle.x = 2048; // Start from the right edge newObstacle.y = groundLevel + 200; obstacles.push(newObstacle); game.addChild(newObstacle); // Line 2 var newObstacle2 = new Obstacle(obstaclesLine2.length); newObstacle2.x = 2048 + 100; // Start from the right edge newObstacle2.y = groundLevel + 200 - 220; obstaclesLine2.push(newObstacle2); game.addChild(newObstacle2); } } 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; } } for (var i = obstaclesLine2.length - 1; i >= 0; i--) { obstaclesLine2[i].update(); // Remove obstacle if it moves off-screen and increase global speed if (obstaclesLine2[i].x < -100) { // Assuming obstacle width is less than 100px obstaclesLine2[i].destroy(); obstaclesLine2.splice(i, 1); } } } 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) { 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 athlete.restore(); globalSpeed = -10; }, 1000); // Delay game over to allow fall animation to be seen } } /****************************************************************************************** */ /************************************** MAIN GAME LOOP ************************************ */ /****************************************************************************************** */ LK.on('tick', function () { switch (gameState) { case GAME_STATE.MENU: // Handle menu logic here break; case GAME_STATE.STARTING: // Handle game starting logic here break; case GAME_STATE.PLAYING: gamePlaying(); break; case GAME_STATE.SCORE: // Handle score display logic here break; } }); gameInitialize();
===================================================================
--- original.js
+++ change.js
@@ -190,9 +190,9 @@
} else {
self.rightArm.rotation += -Math.PI * 3 * rotationSpeed;
self.leftArm.rotation += Math.PI * 1.75 * rotationSpeed;
// Continue with jump animation adjustments
- self.rightLeg.rotation += (-2.3 - self.rightLeg.rotation) * rotationSpeed;
+ self.rightLeg.rotation += (-2.6 - self.rightLeg.rotation) * rotationSpeed;
self.leftLeg.rotation += (1 - self.leftLeg.rotation) * rotationSpeed;
self.leftLeg.height -= 0 * rotationSpeed;
self.leftArm.height -= 35 * rotationSpeed;
}
@@ -299,12 +299,12 @@
/****
* Game Code
****/
-// Enumeration for game states
/****************************************************************************************** */
/************************************** GLOBAL VARIABLES ********************************** */
/****************************************************************************************** */
+// Enumeration for game states
var GAME_STATE = {
INIT: 'INIT',
MENU: 'MENU',
HELP: 'HELP',
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.