User prompt
Add a score thing so you can see your best score and your score ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
The game over screen is broken and the top delete start still doesn't work.
User prompt
To have to play a game doesn't work.
User prompt
It just tapped to play again, but if I tap, it doesn't do anything.
User prompt
Please fix the bug: 'ReferenceError: Can't find variable: showCustomGameOver' in or related to this line: 'showCustomGameOver();' Line Number: 296
User prompt
There's a bug. When I click the play again button, it doesn't play again. So can you fix the bug?
User prompt
change the game over screen so to play again and it shows your score and it shows a badge but if you want to get a brown badge you need 10 points a gold one 20
User prompt
The pipes aren't long and they look like they're messed up.
User prompt
Can you make the pipes longer so they touch the floor and they look like real Flappy Bird? And make it so when you die, there's like a die screen, like just like classic Flappy Bird.
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Wings
Initial prompt
Make Flappy Bird
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = 0;
self.gravity = 0.8;
self.flapPower = -12;
self.maxVelocity = 15;
self.flap = function () {
self.velocity = self.flapPower;
LK.getSound('flap').play();
// Flap animation
tween(birdGraphics, {
rotation: -0.3
}, {
duration: 100
});
tween(birdGraphics, {
rotation: 0.3
}, {
duration: 200,
onFinish: function onFinish() {
tween(birdGraphics, {
rotation: 0
}, {
duration: 100
});
}
});
};
self.update = function () {
self.velocity += self.gravity;
if (self.velocity > self.maxVelocity) {
self.velocity = self.maxVelocity;
}
self.y += self.velocity;
// Rotate bird based on velocity
var targetRotation = Math.min(Math.max(self.velocity * 0.1, -0.5), 0.8);
birdGraphics.rotation = targetRotation;
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.gapSize = 300;
self.speed = -4;
self.scored = false;
// Create top pipe
self.topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
// Create bottom pipe
self.bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
self.setGapPosition = function (gapY) {
self.topPipe.y = gapY - self.gapSize / 2;
self.bottomPipe.y = gapY + self.gapSize / 2;
// Make bottom pipe extend to ground - position it properly and scale it
var groundY = 2732 - 100; // Ground position
var bottomPipeTop = gapY + self.gapSize / 2;
var distanceToGround = groundY - bottomPipeTop;
// Position bottom pipe at gap bottom and scale to reach ground
self.bottomPipe.y = bottomPipeTop;
self.bottomPipe.scaleY = distanceToGround / 800; // Scale to reach ground
self.bottomPipe.anchorY = 0; // Anchor at top so it grows downward
};
self.update = function () {
self.x += self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var bird;
var pipes = [];
var ground;
var scoreTxt;
var gameStarted = false;
var pipeSpawnTimer = 0;
var pipeDistance = 400;
// Create bird
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366; // Center vertically
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = 2732 - 100;
// Create score display
scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 200;
// Game input handler
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
}
;
// Custom game over screen variables
var gameOverScreen = null;
// Function to show custom game over screen
function showCustomGameOver() {
// Create game over screen container
gameOverScreen = game.addChild(new Container());
// Create semi-transparent background
var overlay = gameOverScreen.attachAsset('ground', {
anchorX: 0,
anchorY: 0,
scaleX: 2048 / 2048,
scaleY: 2732 / 100,
alpha: 0.7
});
overlay.tint = 0x000000;
overlay.x = 0;
overlay.y = 0;
// Game Over title
var gameOverText = new Text2('Game Over', {
size: 100,
fill: 0xFFFFFF
});
gameOverText.anchor.set(0.5, 0.5);
gameOverText.x = 1024;
gameOverText.y = 800;
gameOverScreen.addChild(gameOverText);
// Score display
var finalScore = LK.getScore();
var scoreText = new Text2('Score: ' + finalScore, {
size: 80,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0.5);
scoreText.x = 1024;
scoreText.y = 950;
gameOverScreen.addChild(scoreText);
// Badge system
var badgeText = '';
var badgeColor = 0xFFFFFF;
if (finalScore >= 20) {
badgeText = 'GOLD BADGE!';
badgeColor = 0xFFD700;
} else if (finalScore >= 10) {
badgeText = 'BRONZE BADGE!';
badgeColor = 0xCD7F32;
} else {
badgeText = 'No Badge';
badgeColor = 0x888888;
}
if (finalScore >= 10) {
var badge = new Text2(badgeText, {
size: 60,
fill: badgeColor
});
badge.anchor.set(0.5, 0.5);
badge.x = 1024;
badge.y = 1100;
gameOverScreen.addChild(badge);
}
// Play Again button
var playAgainText = new Text2('Tap to Play Again', {
size: 60,
fill: 0x00FF00
});
playAgainText.anchor.set(0.5, 0.5);
playAgainText.x = 1024;
playAgainText.y = 1400;
gameOverScreen.addChild(playAgainText);
// Handle tap to restart
gameOverScreen.down = function (x, y, obj) {
restartGame();
};
}
// Function to restart the game
function restartGame() {
// Remove game over screen
if (gameOverScreen) {
gameOverScreen.destroy();
gameOverScreen = null;
}
// Reset game state
LK.setScore(0);
scoreTxt.setText('0');
gameStarted = false;
pipeSpawnTimer = 0;
// Reset bird position
bird.x = 300;
bird.y = 1366;
bird.velocity = 0;
// Clear all pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].destroy();
}
pipes = [];
}
;
bird.flap();
};
// Main game loop
game.update = function () {
if (!gameStarted) return;
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeDistance / 4) {
var newPipe = new Pipe();
newPipe.x = 2048 + 60;
// Random gap position between 300 and 2000
var gapY = 300 + Math.random() * (2000 - 300);
newPipe.setGapPosition(gapY);
pipes.push(newPipe);
game.addChild(newPipe);
pipeSpawnTimer = 0;
}
// Update pipes and check collisions
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Track last position for scoring
if (pipe.lastX === undefined) pipe.lastX = pipe.x;
// Check for scoring (bird passes pipe)
if (!pipe.scored && pipe.lastX > bird.x && pipe.x <= bird.x) {
pipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('score').play();
}
// Remove off-screen pipes
if (pipe.x < -120) {
pipe.destroy();
pipes.splice(i, 1);
continue;
}
// Collision detection
var birdBounds = {
x: bird.x - 30,
y: bird.y - 20,
width: 60,
height: 40
};
var topPipeBounds = {
x: pipe.x - 60,
y: 0,
width: 120,
height: pipe.topPipe.y
};
var bottomPipeBounds = {
x: pipe.x - 60,
y: pipe.bottomPipe.y,
width: 120,
height: 2732 - 100 - pipe.bottomPipe.y // Height from pipe start to ground
};
// Check collision with pipes
if (birdBounds.x < topPipeBounds.x + topPipeBounds.width && birdBounds.x + birdBounds.width > topPipeBounds.x && birdBounds.y < topPipeBounds.y + topPipeBounds.height && birdBounds.y + birdBounds.height > topPipeBounds.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
showCustomGameOver();
return;
}
if (birdBounds.x < bottomPipeBounds.x + bottomPipeBounds.width && birdBounds.x + birdBounds.width > bottomPipeBounds.x && birdBounds.y < bottomPipeBounds.y + bottomPipeBounds.height && birdBounds.y + birdBounds.height > bottomPipeBounds.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
showCustomGameOver();
return;
}
pipe.lastX = pipe.x;
}
// Check ground collision
if (bird.y + 20 >= ground.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
showCustomGameOver();
return;
}
// Check ceiling collision
if (bird.y - 20 <= 0) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
showCustomGameOver();
return;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -123,8 +123,105 @@
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
}
+ ;
+ // Custom game over screen variables
+ var gameOverScreen = null;
+ // Function to show custom game over screen
+ function showCustomGameOver() {
+ // Create game over screen container
+ gameOverScreen = game.addChild(new Container());
+ // Create semi-transparent background
+ var overlay = gameOverScreen.attachAsset('ground', {
+ anchorX: 0,
+ anchorY: 0,
+ scaleX: 2048 / 2048,
+ scaleY: 2732 / 100,
+ alpha: 0.7
+ });
+ overlay.tint = 0x000000;
+ overlay.x = 0;
+ overlay.y = 0;
+ // Game Over title
+ var gameOverText = new Text2('Game Over', {
+ size: 100,
+ fill: 0xFFFFFF
+ });
+ gameOverText.anchor.set(0.5, 0.5);
+ gameOverText.x = 1024;
+ gameOverText.y = 800;
+ gameOverScreen.addChild(gameOverText);
+ // Score display
+ var finalScore = LK.getScore();
+ var scoreText = new Text2('Score: ' + finalScore, {
+ size: 80,
+ fill: 0xFFFFFF
+ });
+ scoreText.anchor.set(0.5, 0.5);
+ scoreText.x = 1024;
+ scoreText.y = 950;
+ gameOverScreen.addChild(scoreText);
+ // Badge system
+ var badgeText = '';
+ var badgeColor = 0xFFFFFF;
+ if (finalScore >= 20) {
+ badgeText = 'GOLD BADGE!';
+ badgeColor = 0xFFD700;
+ } else if (finalScore >= 10) {
+ badgeText = 'BRONZE BADGE!';
+ badgeColor = 0xCD7F32;
+ } else {
+ badgeText = 'No Badge';
+ badgeColor = 0x888888;
+ }
+ if (finalScore >= 10) {
+ var badge = new Text2(badgeText, {
+ size: 60,
+ fill: badgeColor
+ });
+ badge.anchor.set(0.5, 0.5);
+ badge.x = 1024;
+ badge.y = 1100;
+ gameOverScreen.addChild(badge);
+ }
+ // Play Again button
+ var playAgainText = new Text2('Tap to Play Again', {
+ size: 60,
+ fill: 0x00FF00
+ });
+ playAgainText.anchor.set(0.5, 0.5);
+ playAgainText.x = 1024;
+ playAgainText.y = 1400;
+ gameOverScreen.addChild(playAgainText);
+ // Handle tap to restart
+ gameOverScreen.down = function (x, y, obj) {
+ restartGame();
+ };
+ }
+ // Function to restart the game
+ function restartGame() {
+ // Remove game over screen
+ if (gameOverScreen) {
+ gameOverScreen.destroy();
+ gameOverScreen = null;
+ }
+ // Reset game state
+ LK.setScore(0);
+ scoreTxt.setText('0');
+ gameStarted = false;
+ pipeSpawnTimer = 0;
+ // Reset bird position
+ bird.x = 300;
+ bird.y = 1366;
+ bird.velocity = 0;
+ // Clear all pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ pipes[i].destroy();
+ }
+ pipes = [];
+ }
+ ;
bird.flap();
};
// Main game loop
game.update = function () {
@@ -181,30 +278,30 @@
// Check collision with pipes
if (birdBounds.x < topPipeBounds.x + topPipeBounds.width && birdBounds.x + birdBounds.width > topPipeBounds.x && birdBounds.y < topPipeBounds.y + topPipeBounds.height && birdBounds.y + birdBounds.height > topPipeBounds.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
- LK.showGameOver();
+ showCustomGameOver();
return;
}
if (birdBounds.x < bottomPipeBounds.x + bottomPipeBounds.width && birdBounds.x + birdBounds.width > bottomPipeBounds.x && birdBounds.y < bottomPipeBounds.y + bottomPipeBounds.height && birdBounds.y + birdBounds.height > bottomPipeBounds.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
- LK.showGameOver();
+ showCustomGameOver();
return;
}
pipe.lastX = pipe.x;
}
// Check ground collision
if (bird.y + 20 >= ground.y) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
- LK.showGameOver();
+ showCustomGameOver();
return;
}
// Check ceiling collision
if (bird.y - 20 <= 0) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
- LK.showGameOver();
+ showCustomGameOver();
return;
}
};
\ No newline at end of file