User prompt
pipe ı düzelt karekter iki borunun arasından geçemiyor
User prompt
fix the game bug
User prompt
fix the bird and pipe size
User prompt
fix game
User prompt
fix pipe
User prompt
ground iyi fkat sonsuz gözükmüyor
User prompt
oyundaki pipe ve ground du düzelt
User prompt
oyunu düzenle ve hataları kapat
User prompt
Flappy bird game
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Wings
Initial prompt
Flappy bird
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
// Create bird graphics
var birdGraphics = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
// Physics properties
self.velocity = 0;
self.gravity = 0.8;
self.flapPower = -12;
self.maxVelocity = 15;
// Tracking properties
self.lastY = 0;
self.update = function () {
// Store last position
self.lastY = self.y;
// Apply gravity
self.velocity += self.gravity;
// Limit velocity
if (self.velocity > self.maxVelocity) {
self.velocity = self.maxVelocity;
}
// Update position
self.y += self.velocity;
// Rotate bird based on velocity
birdGraphics.rotation = Math.min(Math.max(self.velocity * 0.05, -0.5), 1.2);
};
self.flap = function () {
self.velocity = self.flapPower;
LK.getSound('flap').play();
};
return self;
});
var Ground = Container.expand(function () {
var self = Container.call(this);
// Create ground graphics
var groundGraphics = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0
});
// Movement properties
self.speed = -4;
self.update = function () {
// Move ground left
self.x += self.speed;
// Reset position when off screen for infinite scrolling
if (self.x <= -2048) {
self.x = 2048;
}
};
return self;
});
// Game variables
var Pipe = Container.expand(function () {
var self = Container.call(this);
// Create top and bottom pipe parts
var topPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 1
});
var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
// Movement properties
self.speed = -4;
self.gapSize = 300;
self.passed = false;
// Tracking properties
self.lastX = 0;
self.setGapPosition = function (centerY) {
// Position top pipe (anchor at bottom, so y is bottom edge)
topPipe.y = centerY - self.gapSize / 2;
// Position bottom pipe (anchor at top, so y is top edge)
bottomPipe.y = centerY + self.gapSize / 2;
};
self.update = function () {
// Store last position
self.lastX = self.x;
// Move pipe left
self.x += self.speed;
};
self.getTopBounds = function () {
return {
x: self.x - 60,
y: 0,
width: 120,
height: topPipe.y
};
};
self.getBottomBounds = function () {
return {
x: self.x - 60,
y: bottomPipe.y,
width: 120,
height: 2732 - bottomPipe.y
};
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Initialize sound for flap
// Initialize ground asset - brown rectangle for the ground
// Initialize pipe assets - green rectangles for obstacles
// Initialize bird asset - yellow circle for the flappy bird
// Game variables
var bird;
var pipes = [];
var ground1, ground2;
var gameStarted = false;
var pipeTimer = 0;
var pipeSpacing = 400;
// Score display
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Initialize bird
bird = game.addChild(new Bird());
bird.x = 400;
bird.y = 1366; // Center of screen vertically
bird.lastY = bird.y; // Initialize tracking property
// Initialize ground
ground1 = game.addChild(new Ground());
ground1.x = 0;
ground1.y = 1524; // Position ground so it's visible (2732 - 1208 = 1524)
ground2 = game.addChild(new Ground());
ground2.x = 2048;
ground2.y = 1524; // Position ground so it's visible
// Tap to flap
game.down = function (x, y, obj) {
if (!gameStarted) {
gameStarted = true;
}
bird.flap();
};
// Collision detection helper function
function checkCollision(birdBounds, pipeBounds) {
return birdBounds.x < pipeBounds.x + pipeBounds.width && birdBounds.x + birdBounds.width > pipeBounds.x && birdBounds.y < pipeBounds.y + pipeBounds.height && birdBounds.y + birdBounds.height > pipeBounds.y;
}
// Main game update
game.update = function () {
if (!gameStarted) return;
// Store bird's last Y position
if (bird.lastY === undefined) bird.lastY = bird.y;
// Spawn pipes
pipeTimer++;
if (pipeTimer >= pipeSpacing / 4) {
// Adjust timing based on speed
var newPipe = new Pipe();
newPipe.x = 2200; // Start off-screen right
newPipe.lastX = newPipe.x; // Initialize tracking property
// Random gap position (avoid top and bottom areas)
var gapCenter = 500 + Math.random() * 1200; // Between 500 and 1700 for better gameplay
newPipe.setGapPosition(gapCenter);
pipes.push(newPipe);
game.addChild(newPipe);
pipeTimer = 0;
}
// Update pipes and check collisions/scoring
for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
// Initialize tracking properties
if (pipe.lastX === undefined) pipe.lastX = pipe.x;
// Check if pipe passed bird for scoring
if (!pipe.passed && pipe.lastX > bird.x && pipe.x <= bird.x) {
pipe.passed = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
}
// Remove pipes that are off screen
if (pipe.x < -200) {
pipe.destroy();
pipes.splice(i, 1);
continue;
}
// Check collision with pipes
var birdBounds = {
x: bird.x - 25,
y: bird.y - 25,
width: 50,
height: 50
};
var topBounds = pipe.getTopBounds();
var bottomBounds = pipe.getBottomBounds();
if (checkCollision(birdBounds, topBounds) || checkCollision(birdBounds, bottomBounds)) {
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Update last position
pipe.lastX = pipe.x;
}
// Check collision with ground
if (bird.y >= 1494) {
// Ground collision (ground at 1524, bird radius 30)
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Check collision with ceiling
if (bird.y <= 30) {
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
// Update last position
bird.lastY = bird.y;
}; ===================================================================
--- original.js
+++ change.js
@@ -88,17 +88,17 @@
return {
x: self.x - 60,
y: 0,
width: 120,
- height: topPipe.y + topPipe.height
+ height: topPipe.y
};
};
self.getBottomBounds = function () {
return {
x: self.x - 60,
y: bottomPipe.y,
width: 120,
- height: 1524 - bottomPipe.y
+ height: 2732 - bottomPipe.y
};
};
return self;
});