User prompt
make sure all speed of obstacles coins and powerups are set to 0 when game over is up, even the accumulated one
User prompt
miles and coiins displlye on the top right has to be rendered behind the game over screen when up
User prompt
destroy miles and coinis counter on the top right when game over screen is up
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'setText')' in or related to this line: 'milesTxt.setText(Math.floor(milesTraveled));' Line Number: 1405
User prompt
remove miles and coins background image ont he top right when game over is up
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'setText')' in or related to this line: 'milesTxt.setText(Math.floor(milesTraveled));' Line Number: 1422
User prompt
game over text should be higher
User prompt
add animation on how game over text appears
User prompt
add space bteween miles coins and final score
User prompt
game over animationo should make it come from the back forward, from very small to big
Code edit (2 edits merged)
Please save this source code
User prompt
instead of ccounting upwards, miles on gmae over screen should go from the number they were on game over to 0, and while doing that, final score should be increasing from 0 to the miles number
User prompt
Please fix the bug: 'Timeout.tick error: finalScoreText is not defined' in or related to this line: 'finalScoreText.setText('Final Score: ' + currentFinalScore);' Line Number: 144
User prompt
when game over screen is loaded, first should miles and final score for 1 second and keep coins hidden. then start decreasing miles and increasing final score. after that is done, show coins.
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'setText')' in or related to this line: 'milesTxt.setText(Math.floor(milesTraveled));' Line Number: 1444
Code edit (2 edits merged)
Please save this source code
User prompt
add 100 pixels of space between miles travelled, coins and final score
User prompt
create a final score for the game. that final score is the result of the miles traveled plus 100 extra points per each coin collected
User prompt
show final score in the game over message from the lk engine
User prompt
use lk.setscore to track final score
User prompt
make flash screen game white
User prompt
play gameover sound when before game over pops up
User prompt
change music to gameover before game over
User prompt
wait one second after playing gameover sound before showing game over
Code edit (3 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -36,134 +36,8 @@
self.scale.x = 1 + Math.sin(LK.ticks / 20) * 0.05;
self.scale.y = 1 + Math.sin(LK.ticks / 20) * 0.05;
};
});
-// Define the GameOverScreen class
-var GameOverScreen = Container.expand(function () {
- var self = Container.call(this);
- var background = self.attachAsset('new_miles_background_id', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 / 2,
- scaleX: 2048 / 100,
- scaleY: 2732 / 100,
- alpha: 1.0,
- // Set alpha to 1.0 to ensure background is not transparent
- tint: 0x000000 // Set background color to black
- });
- self.addChildAt(background, self.children.length);
- var gameOverText = new Text2('Game Over', {
- size: 300,
- fill: "#83de44",
- stroke: "#000000",
- strokeThickness: 10,
- border: true,
- borderColor: "#000000",
- borderWidth: 5
- });
- gameOverText.anchor.set(0.5, 0.5);
- gameOverText.x = 2048 / 2;
- gameOverText.y = 2732 / 2 - 600; // Start above the final position
- gameOverText.scale.set(0.1, 0.1); // Start very small
- self.addChildAt(gameOverText, 1);
- // Animate the game over text to move down to its final position and scale up
- var animationDuration = 60; // Duration in frames (1 second at 60 FPS)
- var animationStepY = (2732 / 2 - 400 - gameOverText.y) / animationDuration;
- var animationStepScale = (1 - gameOverText.scale.x) / animationDuration;
- var animationInterval = LK.setInterval(function () {
- if (animationDuration > 0) {
- gameOverText.y += animationStepY;
- gameOverText.scale.x += animationStepScale;
- gameOverText.scale.y += animationStepScale;
- animationDuration--;
- } else {
- LK.clearInterval(animationInterval);
- }
- }, 16.67); // Update every frame (16.67ms for 60 FPS)
- var milesText = new Text2('Miles: 0', {
- size: 100,
- fill: "#ffffff",
- stroke: "#000000",
- strokeThickness: 5,
- border: true,
- borderColor: "#000000",
- borderWidth: 3
- });
- milesText.anchor.set(0.5, 0.5);
- milesText.x = 2048 / 2;
- milesText.y = 2732 / 2 + 50;
- coinsText.y = 2732 / 2 + 150 + 100; // Add 100 pixels of space
- self.addChild(milesText);
- // Animate miles counter from 0 to milesTraveled
- var currentMiles = 0;
- var milesInterval = LK.setInterval(function () {
- if (currentMiles < Math.floor(milesTraveled)) {
- currentMiles += Math.ceil(Math.floor(milesTraveled) / 30); // Increment quickly
- if (currentMiles > Math.floor(milesTraveled)) {
- currentMiles = Math.floor(milesTraveled);
- }
- milesText.setText('Miles Travelled ' + currentMiles);
- } else {
- LK.clearInterval(milesInterval);
- var coinsText = new Text2('Orbs 0', {
- // Animate coins counter from 0 to score after miles are done
- size: 100,
- fill: "#ffffff",
- stroke: "#000000",
- strokeThickness: 5,
- border: true,
- borderColor: "#000000",
- borderWidth: 3
- });
- coinsText.anchor.set(0.5, 0.5);
- coinsText.x = 2048 / 2;
- coinsText.y = 2732 / 2 + 150;
- finalScoreText.y = 2732 / 2 + 250 + 100; // Add 100 pixels of space
- self.addChild(coinsText);
- var currentCoins = 0;
- var coinsInterval = LK.setInterval(function () {
- if (currentCoins < score) {
- currentCoins += Math.ceil(score / 30); // Increment quickly
- if (currentCoins > score) {
- currentCoins = score;
- }
- coinsText.setText('Orbs Collected ' + currentCoins);
- } else {
- LK.clearInterval(coinsInterval);
- var finalScoreText = new Text2('Final Score 0', {
- // Animate final score counter from 0 to final score after coins are done
- size: 100,
- fill: "#ffffff",
- stroke: "#000000",
- strokeThickness: 5,
- border: true,
- borderColor: "#000000",
- borderWidth: 3
- });
- finalScoreText.anchor.set(0.5, 0.5);
- finalScoreText.x = 2048 / 2;
- finalScoreText.y = 2732 / 2 + 250;
- self.addChild(finalScoreText);
- var finalScore = Math.floor(milesTraveled) + score * 100;
- // Animate final score counter from 0 to final score
- var currentFinalScore = 0;
- var finalScoreInterval = LK.setInterval(function () {
- if (currentFinalScore < finalScore) {
- currentFinalScore += Math.ceil(finalScore / 30); // Increment quickly
- if (currentFinalScore > finalScore) {
- currentFinalScore = finalScore;
- }
- finalScoreText.setText('Final Score ' + currentFinalScore);
- } else {
- LK.clearInterval(finalScoreInterval);
- }
- }, 30); // Update every 30ms
- }
- }, 30); // Update every 30ms
- }
- }, 30); // Update every 30ms
-});
// Define the LaneSeparator class
var LaneSeparator = Container.expand(function () {
var self = Container.call(this);
var separatorGraphics = self.attachAsset('lineobstacle', {
@@ -209,9 +83,9 @@
});
self.speed = 15;
self.update = function () {
// Add any specific update logic for LeftPlayer here
- if (LK.ticks % 4 == 0 && !gameOverScreen) {
+ if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (self && self.x !== undefined) {
@@ -374,9 +248,9 @@
if (Math.abs(playerGraphics.rotation) < 0.1) {
playerGraphics.rotation = 0; // Reset rotation when player is not moving
}
}
- if (!self.isJumping && self.visible && !gameOverScreen && !gameOverScreen) {
+ if (!self.isJumping && self.visible) {
if (self.isMoving && LK.ticks % 1 == 0) {
var trail = new Trail();
trail.x = self.x;
trail.y = self.y + playerGraphics.height / 2;
@@ -469,25 +343,8 @@
LK.getSound('jump').play();
}
};
});
-var PlayerParticle = Container.expand(function () {
- var self = Container.call(this);
- var particleGraphics = self.attachAsset('particle', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.speed = Math.random() * 5 + 2; // Random speed for each particle
- self.direction = Math.random() * Math.PI * 2; // Random direction for each particle
- self.update = function () {
- self.x += Math.cos(self.direction) * self.speed; // Move the particle in the direction
- self.y += Math.sin(self.direction) * self.speed;
- self.alpha -= 0.01; // Fade out the particle
- if (self.alpha <= 0) {
- self.destroy();
- }
- };
-});
// Define the PowerUp class
var PowerUp = Container.expand(function () {
var self = Container.call(this);
var powerUpGraphics = self.attachAsset('powerup', {
@@ -544,9 +401,9 @@
});
self.speed = 15;
self.update = function () {
// Add any specific update logic for RightPlayer here
- if (LK.ticks % 4 == 0 && !gameOverScreen) {
+ if (LK.ticks % 4 == 0) {
var trail = new Trail();
trail.scale.x = 0.5;
trail.scale.y = 0.5;
if (self && self.x !== undefined) {
@@ -699,9 +556,8 @@
/****
* Game Code
****/
-var gameOverScreen = null;
function spawnSmallObstacleMiddlePowerUpLeftCoinRight() {
var smallObstacleMiddle = new SmallObstacleMiddlePowerUpLeftCoinRight();
smallObstacleMiddle.x = lanes[1]; // Middle lane
smallObstacleMiddle.y = -smallObstacleMiddle.height * 2;
@@ -835,10 +691,12 @@
scoreBackground.visible = true; // Show score background when game starts
milesTxt.visible = true; // Show miles when game starts
milesBackground.visible = true; // Show miles background when game starts
// Background music is already playing from the main menu
- // Initialize game elements based on selected mode
- obstacleSpawnOrder = []; // Reset obstacleSpawnOrder to default
+ // Hide final score text on game start
+ if (finalScoreTxt) {
+ finalScoreTxt.visible = false;
+ }
if (mode === 'mode1') {
// Initialize mode 1 specific elements
obstacleSpawnOrder = [{
type: 'TextObstacle',
@@ -1004,18 +862,16 @@
var coins = [];
// Initialize split duration timer
var splitDuration = 120; // Duration in frames (2 seconds at 60 FPS)
var splitTimer = 0;
-// Initialize score
+// Initialize score and final score text
var score = 0;
-// Initialize final score
-var finalScore = 0;
+var finalScoreTxt;
// Initialize game speed
var gameSpeed = 5;
// Initialize global spawn interval
var globalSpawnInterval = 120; // Default interval in frames (2 seconds at 60 FPS)
-var scoreTxt = null;
-scoreTxt = new Text2('0', {
+var scoreTxt = new Text2('0', {
size: 50,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
@@ -1381,48 +1237,16 @@
titleButton.update();
}
// Update miles traveled
milesTraveled += gameSpeed / 30; // Increase the speed at which miles are counted
- if (milesTxt) {
- if (milesTxt) {
- if (milesTxt) {
- if (milesTxt) {
- if (milesTxt) {
- if (milesTxt) {
- if (milesTxt) {
- milesTxt.setText(Math.floor(milesTraveled));
- }
- }
- }
- }
- }
- }
- }
+ milesTxt.setText(Math.floor(milesTraveled));
// Update mode1 button
mode1Button.update();
// Update mode2 button
mode2Button.update();
// Update miles traveled
milesTraveled += gameSpeed / 30; // Increase the speed at which miles are counted
milesTxt.setText(Math.floor(milesTraveled));
- if (gameOverScreen) {
- if (milesTxt) {
- milesTxt.destroy();
- milesTxt = null;
- }
- if (milesBackground) {
- milesBackground.destroy();
- milesBackground = null;
- }
- if (scoreTxt) {
- scoreTxt.destroy();
- scoreTxt = null;
- }
- if (scoreBackground) {
- scoreBackground.destroy();
- scoreBackground = null;
- }
- }
if (!gameStarted) {
// Update starfield
return;
}
@@ -1441,15 +1265,11 @@
globalSpawnInterval = Math.max(30, globalSpawnInterval - 10); // Ensure interval doesn't go below 30 frames (0.5 seconds)
}
// Update obstacles, coins, and powerups
for (var i = powerups.length - 1; i >= 0; i--) {
- if (!gameOverScreen) {
- powerups[i].y += gameSpeed;
- powerups[i].update();
- } else {
- powerups[i].speed = 0;
- }
- if (player && !player.isJumping && player.hitbox && player.hitbox.some(function (hitbox) {
+ powerups[i].y += gameSpeed;
+ powerups[i].update();
+ if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return hitbox.intersects(powerups[i]);
})) {
player.isInvulnerable = true;
player.invulnerableTimer = 600; // 10 seconds at 60 FPS
@@ -1465,22 +1285,14 @@
powerups.splice(i, 1);
}
}
for (var i = obstacles.length - 1; i >= 0; i--) {
- if (!gameOverScreen) {
- obstacles[i].y += gameSpeed;
- obstacles[i].update();
- } else {
- obstacles[i].speed = 0;
- }
- if (!player.isJumping && player.hitbox && player.hitbox && player.hitbox.some(function (hitbox) {
+ obstacles[i].y += gameSpeed;
+ obstacles[i].update();
+ if (!player.isJumping && player.hitbox && player.hitbox.some(function (hitbox) {
return checkBoundingBoxCollision(hitbox, obstacles[i]) && obstacles[i].hitbox !== null;
})) {
- if (player.isInvulnerable || gameOverScreen) {
- obstacleSpawnOrder = [];
- if (gameOverScreen) {
- game.setChildIndex(gameOverScreen, game.children.length - 1);
- }
+ if (player.isInvulnerable) {
// Spawn particles
for (var j = 0; j < 20; j++) {
// Increase the number of particles to 20
var particle = new Particle();
@@ -1494,46 +1306,53 @@
LK.getSound('destroy').play();
obstacles[i].destroy();
obstacles.splice(i, 1);
} else {
- gameOverScreen = new GameOverScreen();
- game.addChild(gameOverScreen);
- game.setChildIndex(gameOverScreen, game.children.length - 1);
- // Create particles for player destruction effect
- for (var j = 0; j < 30; j++) {
- var particle = new PlayerParticle();
- particle.x = player.x;
- particle.y = player.y;
- game.addChild(particle);
+ LK.effects.flashScreen(0xff0000, 1000);
+ // Calculate final score
+ var finalScore = Math.floor(milesTraveled) + score * 100;
+ // Display final score
+ var finalScoreTxt = new Text2('Final Score: ' + finalScore, {
+ size: 100,
+ fill: "#ffffff",
+ stroke: "#000000",
+ strokeThickness: 5,
+ border: true,
+ borderColor: "#000000",
+ borderWidth: 3
+ });
+ finalScoreTxt.anchor.set(0.5, 0.5);
+ finalScoreTxt.x = 2048 / 2;
+ finalScoreTxt.y = 2732 / 2;
+ LK.gui.center.addChild(finalScoreTxt);
+ // Calculate final score
+ var finalScore = Math.floor(milesTraveled) + score * 100;
+ // Display final score
+ if (!finalScoreTxt) {
+ finalScoreTxt = new Text2('Final Score: ' + finalScore, {
+ size: 100,
+ fill: "#ffffff",
+ stroke: "#000000",
+ strokeThickness: 5,
+ border: true,
+ borderColor: "#000000",
+ borderWidth: 3
+ });
+ finalScoreTxt.anchor.set(0.5, 0.5);
+ finalScoreTxt.x = 2048 / 2;
+ finalScoreTxt.y = 2732 / 2;
+ LK.gui.center.addChild(finalScoreTxt);
+ } else {
+ finalScoreTxt.setText('Final Score: ' + finalScore);
+ finalScoreTxt.visible = true;
}
- // Play destroy sound when game over screen appears
- LK.getSound('destroy').play();
- // Disable all hitboxes
- player.hitbox = null;
- if (leftPlayer) {
- leftPlayer.hitbox = null;
- }
- if (rightPlayer) {
- rightPlayer.hitbox = null;
- }
- for (var k = 0; k < obstacles.length; k++) {
- obstacles[k].hitbox = null;
- }
- for (var l = 0; l < coins.length; l++) {
- coins[l].hitbox = null;
- }
- for (var m = 0; m < powerups.length; m++) {
- powerups[m].hitbox = null;
- }
- LK.setTimeout(function () {
- LK.showGameOver();
- }, 5000);
+ LK.showGameOver();
}
}
}
// Handle obstacle spawning based on configuration
obstacleSpawnTimer++;
- if (obstacleSpawnOrder.length > 0 && obstacleSpawnTimer >= obstacleSpawnOrder[currentObstacleIndex].interval) {
+ if (obstacleSpawnTimer >= obstacleSpawnOrder[currentObstacleIndex].interval) {
var obstacleType = obstacleSpawnOrder[currentObstacleIndex].type;
if (obstacleType === 'BigObstacle') {
spawnBigObstacle();
} else if (obstacleType === 'LineObstacle') {
@@ -1629,15 +1448,11 @@
};
}
}
for (var i = coins.length - 1; i >= 0; i--) {
- if (!gameOverScreen) {
- coins[i].y += gameSpeed;
- coins[i].update();
- } else {
- coins[i].speed = 0;
- }
- if (player && !player.isJumping && player.hitbox && player.hitbox.some(function (hitbox) {
+ coins[i].y += gameSpeed;
+ coins[i].update();
+ if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return checkBoundingBoxCollision(hitbox, coins[i]);
})) {
score += 1;
scoreTxt.setText(score);
@@ -1657,9 +1472,9 @@
}
for (var i = powerups.length - 1; i >= 0; i--) {
powerups[i].y += gameSpeed;
powerups[i].update();
- if (player && !player.isJumping && player.hitbox && player.hitbox.some(function (hitbox) {
+ if (player && !player.isJumping && player.hitbox.some(function (hitbox) {
return checkBoundingBoxCollision(hitbox, powerups[i]);
})) {
player.isInvulnerable = true;
player.invulnerableTimer = 600; // 10 seconds at 60 FPS
@@ -1865,10 +1680,9 @@
}
// Initialize miles traveled
var milesTraveled = 0;
// Create miles traveled text
-var milesTxt = null;
-milesTxt = new Text2('Miles: 0', {
+var milesTxt = new Text2('Miles: 0', {
size: 100,
fill: "#ffffff",
stroke: "#000000",
strokeThickness: 5,
cartoon white circle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon light blue circle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon white square. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
black rectangle