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
if (self.x <= -2048) {
self.x = 0;
}
};
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) {
topPipe.y = centerY - self.gapSize / 2;
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
****/
// Game variables
// Initialize bird asset - yellow circle for the flappy bird
// Initialize pipe assets - green rectangles for obstacles
// Initialize ground asset - brown rectangle for the ground
// Initialize sound for flap
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
// Initialize ground
ground1 = game.addChild(new Ground());
ground1.x = 0;
ground1.y = 2632; // Bottom of screen
ground2 = game.addChild(new Ground());
ground2.x = 2048;
ground2.y = 2632; // Bottom of screen
// 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
// Random gap position (avoid top and bottom areas)
var gapCenter = 400 + Math.random() * 1800; // Between 400 and 2200
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 - 30,
y: bird.y - 30,
width: 60,
height: 60
};
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 >= 2582) {
// Ground collision (ground at 2632, 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
@@ -1,71 +1,104 @@
/****
-* Plugins
-****/
-var tween = LK.import("@upit/tween.v1");
-
-/****
* 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;
- self.flap = function () {
- self.velocity = self.flapPower;
- LK.getSound('flap').play();
- // Add flap animation
- tween.stop(birdGraphics, {
- rotation: true
- });
- birdGraphics.rotation = -0.3;
- tween(birdGraphics, {
- rotation: 0.3
- }, {
- duration: 300,
- easing: tween.easeOut
- });
- };
+ // 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
- var targetRotation = Math.max(-0.5, Math.min(0.8, self.velocity * 0.08));
- birdGraphics.rotation = targetRotation;
+ 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 Pipe = Container.expand(function () {
+var Ground = Container.expand(function () {
var self = Container.call(this);
- self.gapSize = 300;
+ // Create ground graphics
+ var groundGraphics = self.attachAsset('ground', {
+ anchorX: 0,
+ anchorY: 0
+ });
+ // Movement properties
self.speed = -4;
- self.scored = false;
- // Create top pipe
- self.topPipe = self.attachAsset('pipe', {
+ self.update = function () {
+ // Move ground left
+ self.x += self.speed;
+ // Reset position when off screen
+ if (self.x <= -2048) {
+ self.x = 0;
+ }
+ };
+ 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
});
- // Create bottom pipe
- self.bottomPipe = self.attachAsset('pipe', {
+ var bottomPipe = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: 0
});
- self.setGapPosition = function (gapY) {
- self.topPipe.y = gapY - self.gapSize / 2;
- self.bottomPipe.y = gapY + self.gapSize / 2;
+ // Movement properties
+ self.speed = -4;
+ self.gapSize = 300;
+ self.passed = false;
+ // Tracking properties
+ self.lastX = 0;
+ self.setGapPosition = function (centerY) {
+ topPipe.y = centerY - self.gapSize / 2;
+ 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;
});
/****
@@ -77,117 +110,112 @@
/****
* Game Code
****/
+// Game variables
+// Initialize bird asset - yellow circle for the flappy bird
+// Initialize pipe assets - green rectangles for obstacles
+// Initialize ground asset - brown rectangle for the ground
+// Initialize sound for flap
var bird;
var pipes = [];
+var ground1, ground2;
var gameStarted = false;
-var gameOver = false;
var pipeTimer = 0;
-var pipeSpacing = 300;
-// UI Elements
+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);
-var instructionTxt = new Text2('TAP TO START', {
- size: 60,
- fill: 0xFFFFFF
-});
-instructionTxt.anchor.set(0.5, 0.5);
-LK.gui.center.addChild(instructionTxt);
// Initialize bird
bird = game.addChild(new Bird());
-bird.x = 300;
-bird.y = 1366;
-function startGame() {
- gameStarted = true;
- gameOver = false;
- instructionTxt.visible = false;
+bird.x = 400;
+bird.y = 1366; // Center of screen vertically
+// Initialize ground
+ground1 = game.addChild(new Ground());
+ground1.x = 0;
+ground1.y = 2632; // Bottom of screen
+ground2 = game.addChild(new Ground());
+ground2.x = 2048;
+ground2.y = 2632; // Bottom of screen
+// 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;
}
-function spawnPipe() {
- var pipe = new Pipe();
- pipe.x = 2200;
- // Random gap position (avoiding top and bottom edges)
- var minGapY = 400;
- var maxGapY = 2332;
- var gapY = minGapY + Math.random() * (maxGapY - minGapY);
- pipe.setGapPosition(gapY);
- pipes.push(pipe);
- game.addChild(pipe);
-}
-function checkCollisions() {
- // Check ground and ceiling collision
- if (bird.y > 2732 - 30 || bird.y < 30) {
- return true;
+// 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
+ // Random gap position (avoid top and bottom areas)
+ var gapCenter = 400 + Math.random() * 1800; // Between 400 and 2200
+ newPipe.setGapPosition(gapCenter);
+ pipes.push(newPipe);
+ game.addChild(newPipe);
+ pipeTimer = 0;
}
- // Check pipe collisions
- for (var i = 0; i < pipes.length; i++) {
+ // Update pipes and check collisions/scoring
+ for (var i = pipes.length - 1; i >= 0; i--) {
var pipe = pipes[i];
- // Simple collision detection with pipes
- if (bird.x + 30 > pipe.x - 60 && bird.x - 30 < pipe.x + 60) {
- if (bird.y - 30 < pipe.topPipe.y || bird.y + 30 > pipe.bottomPipe.y) {
- return true;
- }
- }
- }
- return false;
-}
-function updateScore() {
- for (var i = 0; i < pipes.length; i++) {
- var pipe = pipes[i];
- if (!pipe.scored && bird.x > pipe.x) {
- pipe.scored = true;
+ // 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());
- LK.getSound('score').play();
}
- }
-}
-function cleanupPipes() {
- for (var i = pipes.length - 1; i >= 0; i--) {
- var pipe = pipes[i];
+ // 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 - 30,
+ y: bird.y - 30,
+ width: 60,
+ height: 60
+ };
+ 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;
}
-}
-game.down = function (x, y, obj) {
- if (!gameStarted) {
- startGame();
- } else if (!gameOver) {
- bird.flap();
+ // Check collision with ground
+ if (bird.y >= 2582) {
+ // Ground collision (ground at 2632, bird radius 30)
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
+ return;
}
-};
-game.update = function () {
- if (!gameStarted || gameOver) {
+ // Check collision with ceiling
+ if (bird.y <= 30) {
+ LK.effects.flashScreen(0xff0000, 500);
+ LK.showGameOver();
return;
}
- // Update pipes
- for (var i = 0; i < pipes.length; i++) {
- pipes[i].update();
- }
- // Spawn new pipes
- pipeTimer++;
- if (pipeTimer >= pipeSpacing / 4) {
- spawnPipe();
- pipeTimer = 0;
- }
- // Update bird
- bird.update();
- // Check collisions
- if (checkCollisions()) {
- if (!gameOver) {
- gameOver = true;
- LK.getSound('hit').play();
- LK.showGameOver();
- }
- }
- // Update score
- updateScore();
- // Cleanup old pipes
- cleanupPipes();
+ // Update last position
+ bird.lastY = bird.y;
};
\ No newline at end of file