User prompt
make the pipes extend to the top and bottom of the screen
User prompt
make the pipes bigger and more centered
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Flight
Initial prompt
To create the Flappy Bird game, first set up the game screen as portrait mode with a static background that scrolls endlessly to the left. The screen should not resize, and the game world moves forward from right to left. The player controls a bird that moves automatically to the right at a constant speed. The bird is affected by gravity, so it will constantly fall unless the player taps the screen. When the screen is tapped, the bird jumps slightly upwards, and the jump should have an animation to show the bird flapping its wings. If the player does not tap, the bird will fall, and the faster it falls, the more gravity pulls it downward. Create pipes that appear from the right side of the screen and move left. These pipes should always come in pairs: one top pipe and one bottom pipe. The space between these pipes (the gap) is where the player must fly through. The gap's vertical position is randomly chosen each time the pipes spawn. The pipes move left at a constant speed, and if the bird collides with any part of a pipe or the top/bottom of the screen, the game ends. The player’s goal is to fly through as many pairs of pipes as possible without hitting them. Each time the bird successfully flies through a gap between pipes, the score increases by 1, and the score is displayed at the top of the screen. Additionally, the game tracks a high score that is saved. When the bird crashes into a pipe or hits the ground or ceiling, the game ends. A "Game Over" screen appears, showing the player’s current score and high score, and the player must tap the screen again to restart the game. When restarted, the game resets: the bird is placed back in the starting position, the score resets to 0, the pipes reset, and the entire game loop begins again. You may also add extra polish, like showing a "Tap to Start" text before the game begins and playing sound effects for the bird’s flap, scoring points, and crashing into things.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
// Bird graphics
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
// Bird physics properties
self.velocity = 0;
self.gravity = 0.5;
self.flapStrength = -10;
self.isDead = false;
// Flap the bird
self.flap = function () {
if (!self.isDead) {
self.velocity = self.flapStrength;
LK.getSound('flap').play();
// Rotate bird up when flapping
tween(self, {
rotation: -0.5
}, {
duration: 200
});
}
};
self.die = function () {
self.isDead = true;
LK.getSound('hit').play();
LK.effects.flashObject(self, 0xFF0000, 500);
};
self.update = function () {
if (self.isDead) {
return;
}
// Apply gravity
self.velocity += self.gravity;
self.y += self.velocity;
// Rotate bird based on velocity (falling rotation)
if (self.velocity > 5) {
tween(self, {
rotation: 1.2
}, {
duration: 500
});
}
// Check boundaries
if (self.y < 0) {
self.y = 0;
self.velocity = 0;
}
if (self.y > 2732) {
self.die();
LK.showGameOver();
}
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
// Pipe properties
self.speed = 5;
self.scored = false;
// Create top pipe
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1.0
});
// Create top pipe cap
var topPipeCap = self.attachAsset('pipeTop', {
anchorX: 0.5,
anchorY: 1.0,
y: -500
});
// Create bottom pipe
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0.0,
y: 200 // Gap will be between top and bottom pipes
});
// Create bottom pipe cap
var bottomPipeCap = self.attachAsset('pipeTop', {
anchorX: 0.5,
anchorY: 0.0,
y: 200
});
// Set pipe gap
self.setGap = function (gapPosition, gapSize) {
topPipe.y = gapPosition - gapSize / 2;
topPipeCap.y = topPipe.y;
bottomPipe.y = gapPosition + gapSize / 2;
bottomPipeCap.y = bottomPipe.y;
};
self.update = function () {
// Move pipe left
self.x -= self.speed;
// Check if pipe is offscreen
if (self.x < -100) {
self.destroy();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game state variables
var bird;
var pipes = [];
var isGameStarted = false;
var spawnInterval;
var score = 0;
var highScore = storage.highScore || 0;
// Background
var background = LK.getAsset('background', {
anchorX: 0,
anchorY: 0
});
game.addChild(background);
// Score text
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
// High score text
var highScoreTxt = new Text2('Best: 0', {
size: 80,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0.5, 0);
highScoreTxt.setText('Best: ' + highScore);
LK.gui.top.addChild(highScoreTxt);
highScoreTxt.y = 220;
// Initialize bird
function initBird() {
bird = new Bird();
bird.x = 400;
bird.y = 2732 / 2;
game.addChild(bird);
}
// Create a new pipe
function spawnPipe() {
if (!isGameStarted) {
return;
}
var pipe = new Pipe();
pipe.x = 2048 + 100;
// Random gap position between 30% and 70% of screen height
var gapPosition = Math.random() * (2732 * 0.4) + 2732 * 0.3;
var gapSize = 300; // Fixed gap size
pipe.setGap(gapPosition, gapSize);
pipes.push(pipe);
game.addChild(pipe);
}
// Start game
function startGame() {
if (isGameStarted) {
return;
}
isGameStarted = true;
score = 0;
scoreTxt.setText(score);
// Clear any existing pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].destroy();
}
pipes = [];
// Reset bird position
if (bird) {
bird.destroy();
}
initBird();
// Start spawning pipes
spawnInterval = LK.setInterval(spawnPipe, 2000);
// Play background music
LK.playMusic('bgMusic');
}
// Initialize game
initBird();
highScoreTxt.setText('Best: ' + highScore);
// Game input
game.down = function (x, y, obj) {
if (!isGameStarted) {
startGame();
}
if (bird && !bird.isDead) {
bird.flap();
}
};
// Main game update
game.update = function () {
if (!isGameStarted) {
return;
}
// Update all pipes
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Check for scoring (when bird passes pipe)
if (!pipe.scored && bird && bird.x > pipe.x) {
pipe.scored = true;
score += 1;
scoreTxt.setText(score);
LK.setScore(score);
LK.getSound('score').play();
// Update high score if needed
if (score > highScore) {
highScore = score;
storage.highScore = highScore;
highScoreTxt.setText('Best: ' + highScore);
}
}
// Check for collision with bird
if (bird && !bird.isDead) {
// Get pipe children for collision checks
var pipeChildren = pipe.children;
for (var j = 0; j < pipeChildren.length; j++) {
if (bird.intersects(pipeChildren[j])) {
bird.die();
LK.showGameOver();
break;
}
}
}
// Remove pipe if it's off screen
if (pipe.x < -200) {
pipe.destroy();
pipes.splice(i, 1);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,251 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ highScore: 0
+});
+
+/****
+* Classes
+****/
+var Bird = Container.expand(function () {
+ var self = Container.call(this);
+ // Bird graphics
+ var birdGraphics = self.attachAsset('bird', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Bird physics properties
+ self.velocity = 0;
+ self.gravity = 0.5;
+ self.flapStrength = -10;
+ self.isDead = false;
+ // Flap the bird
+ self.flap = function () {
+ if (!self.isDead) {
+ self.velocity = self.flapStrength;
+ LK.getSound('flap').play();
+ // Rotate bird up when flapping
+ tween(self, {
+ rotation: -0.5
+ }, {
+ duration: 200
+ });
+ }
+ };
+ self.die = function () {
+ self.isDead = true;
+ LK.getSound('hit').play();
+ LK.effects.flashObject(self, 0xFF0000, 500);
+ };
+ self.update = function () {
+ if (self.isDead) {
+ return;
+ }
+ // Apply gravity
+ self.velocity += self.gravity;
+ self.y += self.velocity;
+ // Rotate bird based on velocity (falling rotation)
+ if (self.velocity > 5) {
+ tween(self, {
+ rotation: 1.2
+ }, {
+ duration: 500
+ });
+ }
+ // Check boundaries
+ if (self.y < 0) {
+ self.y = 0;
+ self.velocity = 0;
+ }
+ if (self.y > 2732) {
+ self.die();
+ LK.showGameOver();
+ }
+ };
+ return self;
+});
+var Pipe = Container.expand(function () {
+ var self = Container.call(this);
+ // Pipe properties
+ self.speed = 5;
+ self.scored = false;
+ // Create top pipe
+ var topPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 1.0
+ });
+ // Create top pipe cap
+ var topPipeCap = self.attachAsset('pipeTop', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ y: -500
+ });
+ // Create bottom pipe
+ var bottomPipe = self.attachAsset('pipe', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ y: 200 // Gap will be between top and bottom pipes
+ });
+ // Create bottom pipe cap
+ var bottomPipeCap = self.attachAsset('pipeTop', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ y: 200
+ });
+ // Set pipe gap
+ self.setGap = function (gapPosition, gapSize) {
+ topPipe.y = gapPosition - gapSize / 2;
+ topPipeCap.y = topPipe.y;
+ bottomPipe.y = gapPosition + gapSize / 2;
+ bottomPipeCap.y = bottomPipe.y;
+ };
+ self.update = function () {
+ // Move pipe left
+ self.x -= self.speed;
+ // Check if pipe is offscreen
+ if (self.x < -100) {
+ self.destroy();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var bird;
+var pipes = [];
+var isGameStarted = false;
+var spawnInterval;
+var score = 0;
+var highScore = storage.highScore || 0;
+// Background
+var background = LK.getAsset('background', {
+ anchorX: 0,
+ anchorY: 0
+});
+game.addChild(background);
+// Score text
+var scoreTxt = new Text2('0', {
+ size: 150,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 50;
+// High score text
+var highScoreTxt = new Text2('Best: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+highScoreTxt.anchor.set(0.5, 0);
+highScoreTxt.setText('Best: ' + highScore);
+LK.gui.top.addChild(highScoreTxt);
+highScoreTxt.y = 220;
+// Initialize bird
+function initBird() {
+ bird = new Bird();
+ bird.x = 400;
+ bird.y = 2732 / 2;
+ game.addChild(bird);
+}
+// Create a new pipe
+function spawnPipe() {
+ if (!isGameStarted) {
+ return;
+ }
+ var pipe = new Pipe();
+ pipe.x = 2048 + 100;
+ // Random gap position between 30% and 70% of screen height
+ var gapPosition = Math.random() * (2732 * 0.4) + 2732 * 0.3;
+ var gapSize = 300; // Fixed gap size
+ pipe.setGap(gapPosition, gapSize);
+ pipes.push(pipe);
+ game.addChild(pipe);
+}
+// Start game
+function startGame() {
+ if (isGameStarted) {
+ return;
+ }
+ isGameStarted = true;
+ score = 0;
+ scoreTxt.setText(score);
+ // Clear any existing pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ pipes[i].destroy();
+ }
+ pipes = [];
+ // Reset bird position
+ if (bird) {
+ bird.destroy();
+ }
+ initBird();
+ // Start spawning pipes
+ spawnInterval = LK.setInterval(spawnPipe, 2000);
+ // Play background music
+ LK.playMusic('bgMusic');
+}
+// Initialize game
+initBird();
+highScoreTxt.setText('Best: ' + highScore);
+// Game input
+game.down = function (x, y, obj) {
+ if (!isGameStarted) {
+ startGame();
+ }
+ if (bird && !bird.isDead) {
+ bird.flap();
+ }
+};
+// Main game update
+game.update = function () {
+ if (!isGameStarted) {
+ return;
+ }
+ // Update all pipes
+ for (var i = pipes.length - 1; i >= 0; i--) {
+ var pipe = pipes[i];
+ // Check for scoring (when bird passes pipe)
+ if (!pipe.scored && bird && bird.x > pipe.x) {
+ pipe.scored = true;
+ score += 1;
+ scoreTxt.setText(score);
+ LK.setScore(score);
+ LK.getSound('score').play();
+ // Update high score if needed
+ if (score > highScore) {
+ highScore = score;
+ storage.highScore = highScore;
+ highScoreTxt.setText('Best: ' + highScore);
+ }
+ }
+ // Check for collision with bird
+ if (bird && !bird.isDead) {
+ // Get pipe children for collision checks
+ var pipeChildren = pipe.children;
+ for (var j = 0; j < pipeChildren.length; j++) {
+ if (bird.intersects(pipeChildren[j])) {
+ bird.die();
+ LK.showGameOver();
+ break;
+ }
+ }
+ }
+ // Remove pipe if it's off screen
+ if (pipe.x < -200) {
+ pipe.destroy();
+ pipes.splice(i, 1);
+ }
+ }
+};
\ No newline at end of file