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 Particle = Container.expand(function (x, y, color) {
var self = Container.call(this);
var particle = self.attachAsset('speedPowerUp', {
anchorX: 0.5,
anchorY: 0.5
});
particle.tint = color;
particle.scaleX = 0.3;
particle.scaleY = 0.3;
self.x = x;
self.y = y;
self.velocityX = (Math.random() - 0.5) * 8;
self.velocityY = (Math.random() - 0.5) * 8;
self.life = 60; // 1 second at 60fps
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.life--;
// Fade out over time
particle.alpha = self.life / 60;
if (self.life <= 0) {
self.destroy();
}
};
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
});
// Extend pipes to fill entire screen height
self.topPipe.height = 2732;
self.bottomPipe.height = 2732;
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;
});
var PowerUp = Container.expand(function (type) {
var self = Container.call(this);
self.speed = -4;
self.type = type;
self.collected = false;
var powerUpGraphics;
if (type === 'speed') {
powerUpGraphics = self.attachAsset('speedPowerUp', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (type === 'invincibility') {
powerUpGraphics = self.attachAsset('invincibilityPowerUp', {
anchorX: 0.5,
anchorY: 0.5
});
}
// Add pulsing animation
self.pulseTime = 0;
// Add glow effect using tween
tween(powerUpGraphics, {
alpha: 0.6
}, {
duration: 800,
yoyo: true,
repeat: -1
});
self.update = function () {
self.x += self.speed;
// Pulsing animation
self.pulseTime += 0.2;
var scale = 1 + Math.sin(self.pulseTime) * 0.2;
powerUpGraphics.scaleX = scale;
powerUpGraphics.scaleY = scale;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var bird;
var pipes = [];
var powerUps = [];
var particles = [];
var ground;
var gameStarted = false;
var pipeSpawnTimer = 0;
var pipeSpawnInterval = 150; // Spawn pipe every 2.5 seconds at 60fps for more spacing
var powerUpSpawnTimer = 0;
var powerUpSpawnInterval = 300; // Spawn power-up every 5 seconds
var speedBoostTimer = 0;
var invincibilityTimer = 0;
// 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 spawnPowerUp() {
var types = ['speed', 'invincibility'];
var type = types[Math.floor(Math.random() * types.length)];
var powerUp = new PowerUp(type);
powerUp.x = 2048 + 20;
powerUp.y = 200 + Math.random() * (2732 - 400 - 100);
powerUps.push(powerUp);
game.addChild(powerUp);
}
function createParticleEffect(x, y, color, count) {
for (var i = 0; i < count; i++) {
var particle = new Particle(x, y, color);
particles.push(particle);
game.addChild(particle);
}
}
function checkCollisions() {
// Check ground collision
if (bird.y + 30 > ground.y) {
if (invincibilityTimer <= 0) {
gameOver();
return;
}
}
// Check ceiling collision
if (bird.y - 30 < 0) {
if (invincibilityTimer <= 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) {
if (invincibilityTimer <= 0) {
gameOver();
return;
}
}
// Check collision with bottom pipe
if (bird.y + 22 > pipe.bottomPipe.y) {
if (invincibilityTimer <= 0) {
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);
}
}
// Check power-up collisions
for (var j = 0; j < powerUps.length; j++) {
var powerUp = powerUps[j];
if (!powerUp.collected && bird.intersects(powerUp)) {
powerUp.collected = true;
LK.getSound('powerup').play();
if (powerUp.type === 'speed') {
speedBoostTimer = 300; // 5 seconds
createParticleEffect(powerUp.x, powerUp.y, 0xFF6B35, 8);
} else if (powerUp.type === 'invincibility') {
invincibilityTimer = 180; // 3 seconds
createParticleEffect(powerUp.x, powerUp.y, 0x4ECDC4, 8);
}
powerUp.destroy();
powerUps.splice(j, 1);
j--;
}
}
}
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);
}
}
}
function cleanupPowerUps() {
for (var i = powerUps.length - 1; i >= 0; i--) {
var powerUp = powerUps[i];
if (powerUp.x < -60) {
powerUp.destroy();
powerUps.splice(i, 1);
}
}
}
function cleanupParticles() {
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
if (particle.life <= 0) {
particles.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;
}
// Update power-up timers
if (speedBoostTimer > 0) {
speedBoostTimer--;
// Apply speed boost effect to pipes and power-ups
for (var i = 0; i < pipes.length; i++) {
pipes[i].speed = -6; // Faster speed
}
for (var j = 0; j < powerUps.length; j++) {
powerUps[j].speed = -6;
}
ground.scrollSpeed = -3;
} else {
// Normal speed
for (var i = 0; i < pipes.length; i++) {
pipes[i].speed = -4;
}
for (var j = 0; j < powerUps.length; j++) {
powerUps[j].speed = -4;
}
ground.scrollSpeed = -2;
}
if (invincibilityTimer > 0) {
invincibilityTimer--;
// Flash bird when invincible
if (invincibilityTimer % 10 < 5) {
bird.alpha = 0.5;
} else {
bird.alpha = 1.0;
}
} else {
bird.alpha = 1.0;
}
// 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;
}
// Spawn power-ups
powerUpSpawnTimer++;
if (powerUpSpawnTimer >= powerUpSpawnInterval) {
spawnPowerUp();
powerUpSpawnTimer = 0;
}
// Add subtle background color shift based on score
var scoreColorShift = LK.getScore() * 0.01;
var newBgColor = 0x87CEEB + Math.floor(scoreColorShift * 0x111111);
if (newBgColor !== game.backgroundColor) {
game.setBackgroundColor(newBgColor);
}
// Check collisions
checkCollisions();
// Clean up off-screen elements
cleanupPipes();
cleanupPowerUps();
cleanupParticles();
}; ===================================================================
--- original.js
+++ change.js
@@ -91,8 +91,11 @@
self.bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
+ // Extend pipes to fill entire screen height
+ self.topPipe.height = 2732;
+ self.bottomPipe.height = 2732;
self.setGapPosition = function (centerY) {
self.topPipe.y = centerY - self.gapHeight / 2;
self.bottomPipe.y = centerY + self.gapHeight / 2;
};
@@ -119,8 +122,16 @@
});
}
// Add pulsing animation
self.pulseTime = 0;
+ // Add glow effect using tween
+ tween(powerUpGraphics, {
+ alpha: 0.6
+ }, {
+ duration: 800,
+ yoyo: true,
+ repeat: -1
+ });
self.update = function () {
self.x += self.speed;
// Pulsing animation
self.pulseTime += 0.2;
@@ -147,9 +158,9 @@
var particles = [];
var ground;
var gameStarted = false;
var pipeSpawnTimer = 0;
-var pipeSpawnInterval = 90; // Spawn pipe every 1.5 seconds at 60fps
+var pipeSpawnInterval = 150; // Spawn pipe every 2.5 seconds at 60fps for more spacing
var powerUpSpawnTimer = 0;
var powerUpSpawnInterval = 300; // Spawn power-up every 5 seconds
var speedBoostTimer = 0;
var invincibilityTimer = 0;
@@ -381,8 +392,14 @@
if (powerUpSpawnTimer >= powerUpSpawnInterval) {
spawnPowerUp();
powerUpSpawnTimer = 0;
}
+ // Add subtle background color shift based on score
+ var scoreColorShift = LK.getScore() * 0.01;
+ var newBgColor = 0x87CEEB + Math.floor(scoreColorShift * 0x111111);
+ if (newBgColor !== game.backgroundColor) {
+ game.setBackgroundColor(newBgColor);
+ }
// Check collisions
checkCollisions();
// Clean up off-screen elements
cleanupPipes();