User prompt
Make it so there top pipe is flipped vertically
User prompt
Put the ground sprite infront of the pipes
User prompt
Undo
User prompt
Place the bottom pipe just above the ground sprite
User prompt
Make the gap between pipes slightly bigger
User prompt
Make the gravity slightly floaty
User prompt
Make the gap between pipes slightly bigger
User prompt
Undo
User prompt
Make it so that the pipes fill the whole y position instead of it just spewing in the air with gaps under and above it
User prompt
Undo
User prompt
Make the pipes go from the top to bottom
User prompt
Make it so that the player stays still until the game is started
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Flight
Initial prompt
Create a flappy bird game
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.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.3;
self.flapStrength = -10;
self.rotation = 0;
self.dead = false;
self.flap = function () {
if (self.dead) {
return;
}
self.velocity = self.flapStrength;
LK.getSound('flap').play();
// Rotate bird upward when flapping
tween(self, {
rotation: -0.5
}, {
duration: 200,
easing: tween.easeOut
});
};
self.update = function () {
if (self.dead) {
return;
}
if (gameStarted) {
self.velocity += self.gravity;
self.y += self.velocity;
}
// Rotate bird downward when falling
if (self.velocity > 0) {
var targetRotation = Math.min(Math.PI / 2, self.velocity * 0.05);
tween(self, {
rotation: targetRotation
}, {
duration: 100,
easing: tween.linear
});
}
};
self.die = function () {
if (self.dead) {
return;
}
self.dead = true;
LK.getSound('hit').play();
// Flash red when dying
LK.effects.flashObject(self, 0xFF0000, 500);
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1.0,
flipY: 1 // Flip the top pipe vertically
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0
});
self.gapSize = 450;
self.speed = 5;
self.scored = false;
self.setGapPosition = function (y) {
topPipe.y = y - self.gapSize / 2; // Adjust top pipe position
bottomPipe.y = y + self.gapSize / 2; // Revert bottom pipe position to its original state
};
self.update = function () {
self.x -= self.speed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var bird;
var pipes = [];
var ground;
var gameStarted = false;
var gameSpeed = 5;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 100;
var score = 0;
var highScore = storage.highScore || 0;
var gameOver = false;
// Initialize GUI elements
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var tapToStartTxt = new Text2('TAP TO START', {
size: 80,
fill: 0xFFFFFF
});
tapToStartTxt.anchor.set(0.5, 0.5);
LK.gui.center.addChild(tapToStartTxt);
var highScoreTxt = new Text2('BEST: 0', {
size: 60,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.y = 160;
highScoreTxt.setText('BEST: ' + highScore);
LK.gui.top.addChild(highScoreTxt);
// Initialize game objects
function initGame() {
// Create bird
bird = new Bird();
bird.x = 400;
bird.y = 2732 / 2;
bird.velocity = 0; // Ensure bird doesn't move before game starts
game.addChild(bird);
// Create ground
ground = LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
});
ground.y = 2732 - ground.height;
game.addChild(ground);
// Move ground to the front
game.setChildIndex(ground, game.children.length - 1);
// Reset game state
pipes = [];
gameStarted = false;
gameSpeed = 5;
pipeSpawnTimer = 0;
score = 0;
gameOver = false;
// Update score display
scoreTxt.setText('0');
LK.setScore(0);
// Show tap to start message
tapToStartTxt.visible = true;
// Play background music
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 0.4,
duration: 1000
}
});
}
// Create a new pipe
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + pipe.width / 2;
// Random gap position, but keep within reasonable bounds
var minGapX = 400;
var maxGapX = 2048 - 400;
var gapX = minGapX + Math.random() * (maxGapX - minGapX);
pipe.setGapPosition(gapX);
pipe.speed = gameSpeed;
game.addChild(pipe);
pipes.push(pipe);
}
// Start the game
function startGame() {
if (gameStarted || gameOver) {
return;
}
gameStarted = true;
tapToStartTxt.visible = false;
bird.flap();
}
// Handle collision detection
function checkCollisions() {
if (!gameStarted || gameOver) {
return;
}
// Check for ground collision
if (bird.y + bird.height / 2 > ground.y) {
gameEnd();
return;
}
// Check for ceiling collision
if (bird.y - bird.height / 2 < 0) {
bird.y = bird.height / 2; // Prevent going above the screen
bird.velocity = 0;
}
// Check for pipe collisions
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
// Get references to the pipe parts
var topPipe = pipe.children[0];
var bottomPipe = pipe.children[1];
// Convert positions to global game coordinates
var topPipeGlobal = game.toLocal(topPipe.parent.toGlobal(topPipe.position));
var bottomPipeGlobal = game.toLocal(bottomPipe.parent.toGlobal(bottomPipe.position));
// Check for collision with top pipe
if (bird.x + bird.width / 3 > pipe.x - topPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + topPipe.width / 2 && bird.y - bird.height / 3 < topPipeGlobal.y) {
gameEnd();
return;
}
// Check for collision with bottom pipe
if (bird.x + bird.width / 3 > pipe.x - bottomPipe.width / 2 && bird.x - bird.width / 3 < pipe.x + bottomPipe.width / 2 && bird.y + bird.height / 3 > bottomPipeGlobal.y) {
gameEnd();
return;
}
// Check if bird passed pipe (scoring)
if (!pipe.scored && pipe.x + topPipe.width / 2 < bird.x - bird.width / 2) {
pipe.scored = true;
incrementScore();
}
}
}
// Increment the score
function incrementScore() {
score++;
LK.setScore(score);
scoreTxt.setText(score.toString());
// Increase game speed slightly with each point
if (score % 5 === 0 && gameSpeed < 10) {
gameSpeed += 0.5;
// Update speed for existing pipes
for (var i = 0; i < pipes.length; i++) {
pipes[i].speed = gameSpeed;
}
}
LK.getSound('point').play();
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('BEST: ' + highScore);
}
}
// End the game
function gameEnd() {
if (gameOver) {
return;
}
gameOver = true;
bird.die();
// Flash screen red
LK.effects.flashScreen(0xFF0000, 500);
// Show game over after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Input handlers
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else if (!gameOver) {
bird.flap();
}
};
// Game update function
game.update = function () {
if (gameStarted && !gameOver) {
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
// Update pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].update();
// Remove pipes that have gone off-screen
if (pipes[i].x < -pipes[i].width) {
pipes[i].destroy();
pipes.splice(i, 1);
}
}
// Check for collisions
checkCollisions();
}
};
// Initialize the game
initGame(); ===================================================================
--- original.js
+++ change.js
@@ -65,9 +65,10 @@
var Pipe = Container.expand(function () {
var self = Container.call(this);
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
- anchorY: 1.0
+ anchorY: 1.0,
+ flipY: 1 // Flip the top pipe vertically
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0
Flappy bird pipe, is green. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Grass. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pile of sugar. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows