Code edit (3 edits merged)
Please save this source code
User prompt
add a isFalling property to the athlete and update it
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: track is not defined' in or related to this line: 'track.update();' Line Number: 403
User prompt
call track update in gamePlaying
User prompt
use the track class in gameInitialize
User prompt
add a track class
User prompt
Please fix the bug: 'TypeError: undefined is not an object (evaluating 'track.x = trackPosition')' in or related to this line: 'track.x = trackPosition;' Line Number: 380
User prompt
Please fix the bug: 'ReferenceError: track is not defined' in or related to this line: 'track.x = trackPosition;' Line Number: 379
User prompt
make the tracks indefinetly scroll horizontally at the same speed as obstacles
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Stop calling the run anim when falling
Code edit (1 edits merged)
Please save this source code
User prompt
Make a glow effect on the central rod
User prompt
Call the fall anim before gameover
Code edit (2 edits merged)
Please save this source code
User prompt
create a fall anim in athlete class
Code edit (12 edits merged)
Please save this source code
User prompt
add and show the background asset
User prompt
add an asset for the background
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
User prompt
Please fix the bug: 'ReferenceError: runAnim is not defined' in or related to this line: 'runAnim();' Line Number: 129
/**** 
* 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.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; //0.1; // 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.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.isOnGround) {
			self.runAnim();
		}
		if (!self.isOnGround) {
			self.y += self.speedY;
			self.speedY += self.gravity;
			if (self.y >= game.groundLevel - 200) {
				self.y = game.groundLevel - 200;
				self.isOnGround = true;
			}
		}
	};
	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; // - Math.PI * 0.5;
		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.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);
		var rotationSpeed = 0.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 += 35 * rotationSpeed;
			self.leftArm.height += 35 * rotationSpeed;
		} else {
			self.rightArm.rotation += -Math.PI * 3 * rotationSpeed;
			self.leftArm.rotation += Math.PI * 1.75 * rotationSpeed;
			; //+= (1 - self.leftArm.rotation) * rotationSpeed;
			// Continue with jump animation adjustments
			self.rightLeg.rotation += (-2.3 - 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
		self.trunk.rotation += (Math.PI / 2 - self.trunk.rotation) * fallSpeed;
		self.head.rotation += (Math.PI / 2 - self.head.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;
		}
	};
});
/****************************************************************************************** */ 
/************************************** 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 = -10;
	self.move = function () {
		self.x += self.speedX; // * 0; // TEMP DEBUG !!!
	};
});
/**** 
* 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 groundLevel = 2732 - 200; // Ground level set 200px from the bottom
var obstacleSpawnTicker = 0;
var obstacleSpawnRate = 180; // Spawn an obstacle every 2 seconds
var isDebug = true;
/****************************************************************************************** */ 
/************************************** POSTURES ****************************************** */
/****************************************************************************************** */ 
var idlePosture = {
	name: "idlePosture",
	trunk: {
		x: 0,
		y: 0
	},
	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
	var background = LK.getAsset('background', {
		anchorX: 0.0,
		anchorY: 0.0
	});
	game.addChild(background);
	// Initialize athlete
	athlete = game.addChild(new Athlete());
	athlete.x = 400;
	athlete.y = groundLevel - 200;
	athlete.setPosture(idlePosture);
	// Set the ground level globally accessible within the game instance
	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
		if (obstacles[i].x < -100) {
			// Assuming obstacle width is less than 100px
			obstacles[i].destroy();
			obstacles.splice(i, 1);
		}
	}
	// Spawn obstacles
	obstacleSpawnTicker++;
	if (obstacleSpawnTicker >= obstacleSpawnRate) {
		obstacleSpawnTicker = 0;
		var newObstacle = new Obstacle();
		newObstacle.x = 2048; // Start from the right edge
		newObstacle.y = groundLevel + 100;
		obstacles.push(newObstacle);
		game.addChild(newObstacle);
	}
	game.addChild(athlete);
	// Check for collisions
	obstacles.forEach(function (obstacle) {
		if (athlete.intersects(obstacle.centralRod)) {
			athlete.fallAnim(); // Call fall animation before game over
			LK.setTimeout(function () {
				LK.effects.flashScreen(0xff0000, 500); // Flash screen red for half a second
				LK.showGameOver(); // Show game over screen
			}, 1500); // 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
@@ -118,10 +118,8 @@
 	};
 	self.update = function () {
 		if (self.isOnGround) {
 			self.runAnim();
-		} else {
-			self.jumpAnim();
 		}
 		if (!self.isOnGround) {
 			self.y += self.speedY;
 			self.speedY += self.gravity;
@@ -374,9 +372,9 @@
 			athlete.fallAnim(); // Call fall animation before game over
 			LK.setTimeout(function () {
 				LK.effects.flashScreen(0xff0000, 500); // Flash screen red for half a second
 				LK.showGameOver(); // Show game over screen
-			}, 1000); // Delay game over to allow fall animation to be seen
+			}, 1500); // Delay game over to allow fall animation to be seen
 		}
 	});
 }
 /****************************************************************************************** */ 
:quality(85)/https://cdn.frvr.ai/661848ad3c9c5fe61a4c3f8e.png%3F3) 
 Elongated elipse with black top half and white bottom half.
:quality(85)/https://cdn.frvr.ai/661bdc7a58043b89d4ba9e89.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/661bdd1d58043b89d4ba9e8e.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/661be25558043b89d4ba9f0d.png%3F3) 
 full close and front view of empty stands. retro gaming style
:quality(85)/https://cdn.frvr.ai/661f4f57266989b7f2ed94f1.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/661f526b266989b7f2ed954f.png%3F3) 
 delete
:quality(85)/https://cdn.frvr.ai/661f5287266989b7f2ed9554.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66226cbbf46305276d9e4de1.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6622735cf46305276d9e4e30.png%3F3) 
 delete
:quality(85)/https://cdn.frvr.ai/66228a13eff7d73bc2d1d4a9.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66228a2eeff7d73bc2d1d4ad.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662384d91d31755ac753860d.png%3F3) 
 Basquettes à ressort futuriste. vue de profile. Retro gaming style
:quality(85)/https://cdn.frvr.ai/6623cf0f1d31755ac75387a8.png%3F3) 
 a blue iron man style armor flying. Retro gaming style
:quality(85)/https://cdn.frvr.ai/6623cf581d31755ac75387b3.png%3F3) 
 a blue iron man style armor flying horizontally. Retro gaming style
:quality(85)/https://cdn.frvr.ai/6623db441d31755ac753884e.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6623dde21d31755ac753889e.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/662493106b90388bb0195cd3.png%3F3) 
 round button with a big "up" arrow icon and a small line under it. UI
:quality(85)/https://cdn.frvr.ai/6625589e6b90388bb0195eb5.png%3F3) 
 A big black horizontal arrow pointing left with centred text 'YOU' in capital letters, painted on an orange floor.. horizontal and pointing left
:quality(85)/https://cdn.frvr.ai/6625f7dfaefb923f60ced44a.png%3F3) 
 remove
:quality(85)/https://cdn.frvr.ai/66280aa325092f9d66ecfd6b.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66289a7225092f9d66ecfe81.png%3F3) 
 gold athletics medal with ribbon. retro gaming style
:quality(85)/https://cdn.frvr.ai/66294f1a777dbb646cb323ba.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66294f97777dbb646cb323d0.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66295338777dbb646cb32447.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6629533f777dbb646cb3244b.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/6629546e777dbb646cb32460.png%3F3) 
 :quality(85)/https://cdn.frvr.ai/66295506777dbb646cb32474.png%3F3) 
 a black oval with a crying smiley face.
:quality(85)/https://cdn.frvr.ai/66295a3a777dbb646cb324d9.png%3F3)