User prompt
upgrade
User prompt
Increase the distance between stages and improve the game
User prompt
Increase the distance between the wall and the wall behind it, and extend the walls up and down to fill the ground and the sky completely. and upgrade
User prompt
Upgrade
User prompt
Upgrade
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Bird
Initial prompt
make me a 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.maxFallSpeed = 15;
self.maxRiseSpeed = -15;
self.flap = function () {
self.velocity = self.flapPower;
LK.getSound('flap').play();
// Rotate bird upward when flapping
tween(birdGraphics, {
rotation: -0.5
}, {
duration: 200
});
};
self.update = function () {
// Apply gravity
self.velocity += self.gravity;
// Limit velocity
if (self.velocity > self.maxFallSpeed) {
self.velocity = self.maxFallSpeed;
}
if (self.velocity < self.maxRiseSpeed) {
self.velocity = self.maxRiseSpeed;
}
// Update position
self.y += self.velocity;
// Rotate bird based on velocity
var targetRotation = self.velocity * 0.1;
if (targetRotation > 1.5) targetRotation = 1.5;
if (targetRotation < -0.5) targetRotation = -0.5;
tween(birdGraphics, {
rotation: targetRotation
}, {
duration: 100
});
};
return self;
});
var Pipe = Container.expand(function () {
var self = Container.call(this);
self.speed = -4;
self.scored = false;
self.gapHeight = 300;
// 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 (centerY) {
self.topPipe.y = centerY - self.gapHeight / 2;
self.bottomPipe.y = centerY + self.gapHeight / 2;
};
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 gameStarted = false;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 90; // Spawn pipe every 1.5 seconds at 60fps
// Create score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = 2732 - 100;
ground.width = 2048 * 3; // Make ground wider for scrolling effect
ground.scrollSpeed = -2;
// Create bird
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366; // Middle of screen
bird.startY = 1366;
bird.floatTime = 0;
// Add gentle floating animation before game starts
bird.updateFloat = function () {
if (!gameStarted) {
bird.floatTime += 0.1;
bird.y = bird.startY + Math.sin(bird.floatTime) * 20;
}
};
// Create instruction text
var instructionTxt = new Text2('TAP TO FLAP', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0.5);
instructionTxt.x = 1024;
instructionTxt.y = 1000;
game.addChild(instructionTxt);
function startGame() {
gameStarted = true;
instructionTxt.visible = false;
bird.flap();
}
function spawnPipe() {
var pipe = new Pipe();
pipe.x = 2048 + 60; // Start off screen
// Random gap position (avoid too high or too low)
var minGapCenter = 200;
var maxGapCenter = 2732 - 200 - 100; // Account for ground
var gapCenter = minGapCenter + Math.random() * (maxGapCenter - minGapCenter);
pipe.setGapPosition(gapCenter);
pipes.push(pipe);
game.addChild(pipe);
}
function checkCollisions() {
// Check ground collision
if (bird.y + 30 > ground.y) {
gameOver();
return;
}
// Check ceiling collision
if (bird.y - 30 < 0) {
gameOver();
return;
}
// Check pipe collisions
for (var i = 0; i < pipes.length; i++) {
var pipe = pipes[i];
// Check if bird is in pipe's x range
if (bird.x + 30 > pipe.x - 60 && bird.x - 30 < pipe.x + 60) {
// Check collision with top pipe
if (bird.y - 22 < pipe.topPipe.y) {
gameOver();
return;
}
// Check collision with bottom pipe
if (bird.y + 22 > pipe.bottomPipe.y) {
gameOver();
return;
}
}
// Check for scoring
if (!pipe.scored && bird.x > pipe.x + 60) {
pipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('score').play();
// Flash score text when scoring
LK.effects.flashObject(scoreTxt, 0xFFD700, 300);
}
}
}
function gameOver() {
LK.getSound('hit').play();
LK.showGameOver();
}
function cleanupPipes() {
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
if (pipe.x < -120) {
pipe.destroy();
pipes.splice(i, 1);
}
}
}
// Touch controls
game.down = function (x, y, obj) {
if (!gameStarted) {
startGame();
} else {
bird.flap();
}
};
// Game update loop
game.update = function () {
// Update bird floating animation
bird.updateFloat();
if (!gameStarted) {
return;
}
// Scroll ground for visual effect
ground.x += ground.scrollSpeed;
if (ground.x <= -2048) {
ground.x = 0;
}
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();
pipeSpawnTimer = 0;
}
// Check collisions
checkCollisions();
// Clean up off-screen pipes
cleanupPipes();
}; ===================================================================
--- original.js
+++ change.js
@@ -106,12 +106,23 @@
anchorY: 0
}));
ground.x = 0;
ground.y = 2732 - 100;
+ground.width = 2048 * 3; // Make ground wider for scrolling effect
+ground.scrollSpeed = -2;
// Create bird
bird = game.addChild(new Bird());
bird.x = 300;
bird.y = 1366; // Middle of screen
+bird.startY = 1366;
+bird.floatTime = 0;
+// Add gentle floating animation before game starts
+bird.updateFloat = function () {
+ if (!gameStarted) {
+ bird.floatTime += 0.1;
+ bird.y = bird.startY + Math.sin(bird.floatTime) * 20;
+ }
+};
// Create instruction text
var instructionTxt = new Text2('TAP TO FLAP', {
size: 60,
fill: 0xFFFFFF
@@ -168,8 +179,10 @@
pipe.scored = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
LK.getSound('score').play();
+ // Flash score text when scoring
+ LK.effects.flashObject(scoreTxt, 0xFFD700, 300);
}
}
}
function gameOver() {
@@ -194,11 +207,18 @@
}
};
// Game update loop
game.update = function () {
+ // Update bird floating animation
+ bird.updateFloat();
if (!gameStarted) {
return;
}
+ // Scroll ground for visual effect
+ ground.x += ground.scrollSpeed;
+ if (ground.x <= -2048) {
+ ground.x = 0;
+ }
// Spawn pipes
pipeSpawnTimer++;
if (pipeSpawnTimer >= pipeSpawnInterval) {
spawnPipe();