User prompt
oyundaki düğmeleri kodları herşeyi düzelt
User prompt
oyuna ve skor tuşları da çalışsın oynaya basınca oyun başlasın skor tuşuna basınca hem bizim en yüksek rekorumuz ve diğer kullanıcıların rekorları gözüksün ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Oyun ilk açıldığında direkt oyunu başlatma yeri açılmasın. O menüden önce bir menü olsun ve oyuna giriş tuşu olsun, skor tuşumuz olsun gibi gibi.
User prompt
Tüm duvarlar birbirine eşit uzaklıkta olacak yeter artık.
User prompt
İlk iki duvarın bir-birinə uzaqlığı iyi ikən üçüncü duvar ikinci duvara aşırı uzaq.
User prompt
Duvarlar birbirine yani uzaklık olarak ne uzak ne yakın olacak.
User prompt
Oyun kasmasın diye stunları birbirinden uzak yapıyorsan bu kötü birşey. Oyundaki zaten amaç duvarların arasından geçmek. Oyuncuyu oyunda tutmak. O yüzden duvarlar arası uzaklığı eşit yap.
User prompt
İlk İki Duvar Yani İlk İki Skoru Kazanmak Kolayken Üçüncü Skor Yani Üçüncü Duvar Stunu Çok Uzak Aşırı Uzak Bu Stunları Eşit Yap Ve Uzaklıkları Eşit Olsun
User prompt
Tıkla ve oyna yazısına tıklayınca yazı kayboluyor ama arkasındaki renk yani siyah şey kaybolmuyor.
User prompt
Tıkla ve oyna yazısının altına renk koy. Böylece tıkla ve oyna yazısı gözükecek.
User prompt
İlk iki duvar arasında neredeyse hiç boşluk yokken, iki ile üçüncü duvar arasında aşırı uzun bir boşluk var. Orantıyı tuttur.
User prompt
Kuşu hareket ettirdikten sonra rahat bırakıp yere düştüğünü izlerken oyun kasıyor.
User prompt
Duvar aralıqlarını çox dar yapmışsın. Duvarlar arası boşluq yox. Gerçək Flappy Birddən əsinlənərək oyunu təkrar duvarlar arasını genişlət.
User prompt
tamam oyun başlamadığında kuş hareket etmiyor ama kuşu hareket ettirmeye başladığımızda kuşun en son gittiği yerden puan başlıyor yani kuş hareket etmese de dümdüz hareket ediyor ve duvarlardan hasar almıyor kuş hareket etmesin diye sıkıştır
User prompt
Oyun başlamadan önce kuş hareket etmesin diye kuşu bloklar arasına sıkıştır ama bu bloklar bize gözükmesin oyun başladığında bunlar silinsin.
User prompt
oyun başladığında ekranda yazık kalıyor ve duvarlar çok dar
User prompt
Oyundaki tüm kodları her şeyi sil ve baştan yaz.
User prompt
oyundaki tüm duvar kodlarını kontrol et ve tekrar yaz
User prompt
Arasından geçtiklerimizin yukarıdaki yok yani arasından geçmiyoruz üstünden geçiyor oluyoruz Flappy Bird'den örnek alarak oyunu düzelt
User prompt
Arasından geçtiğimiz sütunlar yukarıdakiler silindi ekle ve yukarıdaki en yüksek yere kadar çıksınlar hani ekranda gözüken
User prompt
Arasından Geçtiklerimizi Duvar Olarak Aşağı Ve Yukarıya Orantıla Boşluk Kalmasın Ve En Fazla
User prompt
şu ana kadar yaptığımız hiç kasmayan haline getir
User prompt
Arasından geçtiğimiz stumların kalitesini biraz düşür
User prompt
Her Geçtiğimiz İki Stun'dan Sonra Arkaya Giden Stun'ları Sil Yani Ekranda Gözükmeyen
User prompt
250 ms kapıyı aç
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Bird = Container.expand(function () { var self = Container.call(this); // Create bird body var birdBody = self.attachAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); // Create bird wing var birdWing = self.attachAsset('birdWing', { anchorX: 0.3, anchorY: 0.5 }); birdWing.x = -10; birdWing.y = -5; // Create bird beak var birdBeak = self.attachAsset('birdBeak', { anchorX: 0, anchorY: 0.5 }); birdBeak.x = 30; birdBeak.y = -8; // Create bird eye var birdEye = self.attachAsset('birdEye', { anchorX: 0.5, anchorY: 0.5 }); birdEye.x = 15; birdEye.y = -12; // Create bird pupil var birdPupil = self.attachAsset('birdPupil', { anchorX: 0.5, anchorY: 0.5 }); birdPupil.x = 17; birdPupil.y = -12; // Create bird tail var birdTail = self.attachAsset('birdTail', { anchorX: 1, anchorY: 0.5 }); birdTail.x = -25; birdTail.y = 0; self.velocity = 0; self.gravity = 0.6; self.jumpStrength = -11; self.wingState = 0; // 0 = down, 1 = up self.lastY = 0; self.flap = function () { self.velocity = self.jumpStrength; LK.getSound('flap').play(); // Wing and tail animation self.wingState = 1 - self.wingState; if (self.wingState === 1) { birdWing.y = -15; birdWing.scaleY = 0.8; birdTail.rotation = -0.2; } else { birdWing.y = -5; birdWing.scaleY = 1; birdTail.rotation = 0.1; } }; self.update = function () { self.velocity += self.gravity; self.y += self.velocity; // Rotate bird based on velocity birdBody.rotation = Math.max(-0.4, Math.min(1.2, self.velocity * 0.08)); // Wing flapping animation - reduced to every 60 frames for better performance if (LK.ticks % 60 === 0) { self.wingState = 1 - self.wingState; birdWing.y = self.wingState === 1 ? -15 : -5; birdWing.scaleY = self.wingState === 1 ? 0.8 : 1; birdTail.rotation = self.wingState === 1 ? -0.1 : 0.05; } // Reduce eye pupil movement frequency further if (LK.ticks % 30 === 0) { birdPupil.x = 17 + Math.sin(LK.ticks * 0.02) * 1; } }; return self; }); var Pipe = Container.expand(function (isTop, gapY) { var self = Container.call(this); // Create pipe shadow for depth var pipeShadow = self.attachAsset('pipeShadow', { anchorX: 0.5, anchorY: isTop ? 1 : 0 }); pipeShadow.x = 2; var pipeGraphics = self.attachAsset('pipe', { anchorX: 0.5, anchorY: isTop ? 1 : 0 }); // Create pipe cap for realistic look var pipeCap = self.attachAsset('pipeTop', { anchorX: 0.5, anchorY: isTop ? 1 : 0 }); if (isTop) { pipeCap.y = -20; } else { pipeCap.y = 20; } self.speed = -4; self.passed = false; self.isTop = isTop; self.gapY = gapY; if (isTop) { self.y = gapY - gapSize / 2; var neededHeight = self.y; if (neededHeight > 800) { pipeGraphics.scaleY = neededHeight / 800; } self.y = neededHeight; } else { self.y = Math.max(gapY + gapSize / 2, 2532 - 800); } var cachedSpeed = self.speed; self.update = function () { // Update position with cached speed value self.x += cachedSpeed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var bird; var pipes = []; var ground; var gameSpeed = 4; var gapSize = 500; // Further increased gap size for much easier gameplay var pipeSpacing = 500; // Increased spacing for better playability var nextPipeX = 2048; var gameStarted = false; var gameOver = false; var gameWaitingForRestart = false; var highScore = storage.highScore || 0; // Create score display with better visibility var scoreTxt = new Text2('SKOR: 0', { size: 70, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); scoreTxt.y = 80; // Add text stroke for better visibility scoreTxt.stroke = 0x000000; scoreTxt.strokeThickness = 4; // Create game over display elements with better visibility var gameOverTxt = new Text2('OYUN BİTTİ!', { size: 90, fill: 0xFF0000 }); gameOverTxt.anchor.set(0.5, 0.5); gameOverTxt.visible = false; gameOverTxt.stroke = 0xFFFFFF; gameOverTxt.strokeThickness = 5; LK.gui.center.addChild(gameOverTxt); var currentScoreTxt = new Text2('', { size: 60, fill: 0xFFFFFF }); currentScoreTxt.anchor.set(0.5, 0.5); currentScoreTxt.visible = false; currentScoreTxt.stroke = 0x000000; currentScoreTxt.strokeThickness = 3; LK.gui.center.addChild(currentScoreTxt); currentScoreTxt.y = 100; var highScoreTxt = new Text2('', { size: 60, fill: 0xFFD700 }); highScoreTxt.anchor.set(0.5, 0.5); highScoreTxt.visible = false; highScoreTxt.stroke = 0x000000; highScoreTxt.strokeThickness = 3; LK.gui.center.addChild(highScoreTxt); highScoreTxt.y = 180; // Create bird bird = game.addChild(new Bird()); bird.x = 400; bird.y = 1366; // Create ground ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 1 })); ground.x = 0; ground.y = 2732; // Create grass layer on ground var grass = game.addChild(LK.getAsset('groundTop', { anchorX: 0, anchorY: 1 })); grass.x = 0; grass.y = 2532; // Create decorative clouds var clouds = []; for (var c = 0; c < 4; c++) { var cloud = game.addChild(LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5 })); cloud.x = Math.random() * 2048; cloud.y = 300 + Math.random() * 400; cloud.alpha = 0.7; cloud.scaleX = 0.8 + Math.random() * 0.4; cloud.scaleY = 0.8 + Math.random() * 0.4; clouds.push(cloud); } function createPipePair() { // Ensure gap is positioned properly within screen bounds with better proportions // Account for pipe height (800px), gap size (500px), and ground position (2532) var minGapY = 600; // Higher minimum gap center position for better clearance var maxGapY = 1800; // Ensure bottom pipe can reach ground properly var gapY = minGapY + Math.random() * (maxGapY - minGapY); // Ensure the bottom pipe will touch the ground var bottomPipeTop = gapY + gapSize / 2; var bottomPipeBottom = bottomPipeTop + 800; if (bottomPipeBottom < 2532) { // Adjust gap position so bottom pipe touches ground var adjustment = 2532 - bottomPipeBottom; gapY += adjustment; } var topPipe = new Pipe(true, gapY); topPipe.x = nextPipeX; pipes.push(topPipe); game.addChild(topPipe); var bottomPipe = new Pipe(false, gapY); bottomPipe.x = nextPipeX; pipes.push(bottomPipe); game.addChild(bottomPipe); nextPipeX += pipeSpacing; } function resetGame() { // Reset bird bird.x = 400; bird.y = 1366; bird.velocity = 0; bird.lastY = bird.y; bird.wingState = 0; // Reset bird visual state bird.children[0].rotation = 0; // Reset body rotation bird.children[1].y = -5; // Reset wing position bird.children[1].scaleY = 1; // Reset wing scale // Clear pipes for (var i = pipes.length - 1; i >= 0; i--) { pipes[i].destroy(); } pipes = []; // Reset variables nextPipeX = 2048; gameStarted = false; gameOver = false; gameWaitingForRestart = false; lastBirdY = bird.y; lastFlapTime = 0; gameSpeed = 4; LK.setScore(0); scoreTxt.setText('SKOR: 0'); // Hide game over display elements gameOverTxt.visible = false; currentScoreTxt.visible = false; highScoreTxt.visible = false; // Create initial pipes createPipePair(); createPipePair(); } // Initialize first pipes createPipePair(); createPipePair(); function showGameOverScreen() { var currentScore = LK.getScore(); // Update high score if needed if (currentScore > highScore) { highScore = currentScore; storage.highScore = highScore; } // Show game over display gameOverTxt.visible = true; currentScoreTxt.setText('SKOR: ' + currentScore); currentScoreTxt.visible = true; highScoreTxt.setText('EN YÜKSEK SKOR: ' + highScore); highScoreTxt.visible = true; // Set waiting for restart state and show game over screen gameWaitingForRestart = true; gameOver = true; LK.showGameOver(); } var lastFlapTime = 0; var flapCooldown = 250; // Quarter second delay between flaps in milliseconds game.down = function (x, y, obj) { // Handle restart after game over if (gameWaitingForRestart) { resetGame(); return; } if (gameOver) return; // Ignore clicks when game is over var currentTime = Date.now(); if (currentTime - lastFlapTime < flapCooldown) return; // Debounce rapid clicks with increased delay if (!gameStarted) { gameStarted = true; } bird.flap(); lastFlapTime = currentTime; }; game.update = function () { if (!gameStarted || gameOver || gameWaitingForRestart) return; // Check if bird hits ground (immediate detection with proper hitbox) // Ground is positioned at y=2732 with height 200, so ground surface is at y=2532 if (bird.y + 30 >= 2532) { gameOver = true; showGameOverScreen(); return; } // Check if bird goes too high if (bird.y < 50) { if (!gameOver) { gameOver = true; showGameOverScreen(); } return; } // Only check collision every 4th frame for better performance if (LK.ticks % 4 === 0) { // Pre-calculate bird boundaries once var birdLeft = bird.x - 35; var birdRight = bird.x + 35; var birdTop = bird.y - 25; var birdBottom = bird.y + 25; // Check pipe collisions and scoring - optimized loop for (var i = 0; i < pipes.length; i += 2) { var pipe = pipes[i]; // Skip collision check for distant pipes if (pipe.x < birdLeft - 200 || pipe.x > birdRight + 200) continue; var pipeLeft = pipe.x - 60; var pipeRight = pipe.x + 60; // Check collision if bird is within pipe X range if (birdRight > pipeLeft && birdLeft < pipeRight) { if (birdTop <= pipe.y || birdBottom >= pipes[i + 1].y) { gameOver = true; showGameOverScreen(); return; } } // Check for scoring (only check top pipe) if (!pipe.passed && pipe.x + 60 < bird.x) { pipe.passed = true; pipes[i + 1].passed = true; LK.setScore(LK.getScore() + 1); scoreTxt.setText('SKOR: ' + LK.getScore()); LK.getSound('score').play(); // Remove oldest pipe pairs after every 5 pipes passed if (LK.getScore() % 5 === 0 && pipes.length > 10) { // Remove the first two pipes (one pair) pipes[0].destroy(); pipes[1].destroy(); pipes.splice(0, 2); } } } } // Create new pipes when needed if (pipes.length === 0 || nextPipeX - pipes[pipes.length - 1].x >= pipeSpacing) { createPipePair(); } // Update game speed much less frequently if (LK.ticks % 1200 === 0 && LK.getScore() > 0) { gameSpeed = Math.min(6, 4 + LK.getScore() * 0.02); for (var j = 0; j < pipes.length; j++) { pipes[j].speed = -gameSpeed; } } // Animate clouds much less frequently for better performance if (LK.ticks % 10 === 0 && typeof clouds !== 'undefined') { for (var cloudIndex = 0; cloudIndex < clouds.length; cloudIndex++) { clouds[cloudIndex].x -= 0.3; if (clouds[cloudIndex].x < -60) { clouds[cloudIndex].x = 2108; clouds[cloudIndex].y = 300 + Math.random() * 400; } } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bird = Container.expand(function () {
var self = Container.call(this);
// Create bird body
var birdBody = self.attachAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
// Create bird wing
var birdWing = self.attachAsset('birdWing', {
anchorX: 0.3,
anchorY: 0.5
});
birdWing.x = -10;
birdWing.y = -5;
// Create bird beak
var birdBeak = self.attachAsset('birdBeak', {
anchorX: 0,
anchorY: 0.5
});
birdBeak.x = 30;
birdBeak.y = -8;
// Create bird eye
var birdEye = self.attachAsset('birdEye', {
anchorX: 0.5,
anchorY: 0.5
});
birdEye.x = 15;
birdEye.y = -12;
// Create bird pupil
var birdPupil = self.attachAsset('birdPupil', {
anchorX: 0.5,
anchorY: 0.5
});
birdPupil.x = 17;
birdPupil.y = -12;
// Create bird tail
var birdTail = self.attachAsset('birdTail', {
anchorX: 1,
anchorY: 0.5
});
birdTail.x = -25;
birdTail.y = 0;
self.velocity = 0;
self.gravity = 0.6;
self.jumpStrength = -11;
self.wingState = 0; // 0 = down, 1 = up
self.lastY = 0;
self.flap = function () {
self.velocity = self.jumpStrength;
LK.getSound('flap').play();
// Wing and tail animation
self.wingState = 1 - self.wingState;
if (self.wingState === 1) {
birdWing.y = -15;
birdWing.scaleY = 0.8;
birdTail.rotation = -0.2;
} else {
birdWing.y = -5;
birdWing.scaleY = 1;
birdTail.rotation = 0.1;
}
};
self.update = function () {
self.velocity += self.gravity;
self.y += self.velocity;
// Rotate bird based on velocity
birdBody.rotation = Math.max(-0.4, Math.min(1.2, self.velocity * 0.08));
// Wing flapping animation - reduced to every 60 frames for better performance
if (LK.ticks % 60 === 0) {
self.wingState = 1 - self.wingState;
birdWing.y = self.wingState === 1 ? -15 : -5;
birdWing.scaleY = self.wingState === 1 ? 0.8 : 1;
birdTail.rotation = self.wingState === 1 ? -0.1 : 0.05;
}
// Reduce eye pupil movement frequency further
if (LK.ticks % 30 === 0) {
birdPupil.x = 17 + Math.sin(LK.ticks * 0.02) * 1;
}
};
return self;
});
var Pipe = Container.expand(function (isTop, gapY) {
var self = Container.call(this);
// Create pipe shadow for depth
var pipeShadow = self.attachAsset('pipeShadow', {
anchorX: 0.5,
anchorY: isTop ? 1 : 0
});
pipeShadow.x = 2;
var pipeGraphics = self.attachAsset('pipe', {
anchorX: 0.5,
anchorY: isTop ? 1 : 0
});
// Create pipe cap for realistic look
var pipeCap = self.attachAsset('pipeTop', {
anchorX: 0.5,
anchorY: isTop ? 1 : 0
});
if (isTop) {
pipeCap.y = -20;
} else {
pipeCap.y = 20;
}
self.speed = -4;
self.passed = false;
self.isTop = isTop;
self.gapY = gapY;
if (isTop) {
self.y = gapY - gapSize / 2;
var neededHeight = self.y;
if (neededHeight > 800) {
pipeGraphics.scaleY = neededHeight / 800;
}
self.y = neededHeight;
} else {
self.y = Math.max(gapY + gapSize / 2, 2532 - 800);
}
var cachedSpeed = self.speed;
self.update = function () {
// Update position with cached speed value
self.x += cachedSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var bird;
var pipes = [];
var ground;
var gameSpeed = 4;
var gapSize = 500; // Further increased gap size for much easier gameplay
var pipeSpacing = 500; // Increased spacing for better playability
var nextPipeX = 2048;
var gameStarted = false;
var gameOver = false;
var gameWaitingForRestart = false;
var highScore = storage.highScore || 0;
// Create score display with better visibility
var scoreTxt = new Text2('SKOR: 0', {
size: 70,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 80;
// Add text stroke for better visibility
scoreTxt.stroke = 0x000000;
scoreTxt.strokeThickness = 4;
// Create game over display elements with better visibility
var gameOverTxt = new Text2('OYUN BİTTİ!', {
size: 90,
fill: 0xFF0000
});
gameOverTxt.anchor.set(0.5, 0.5);
gameOverTxt.visible = false;
gameOverTxt.stroke = 0xFFFFFF;
gameOverTxt.strokeThickness = 5;
LK.gui.center.addChild(gameOverTxt);
var currentScoreTxt = new Text2('', {
size: 60,
fill: 0xFFFFFF
});
currentScoreTxt.anchor.set(0.5, 0.5);
currentScoreTxt.visible = false;
currentScoreTxt.stroke = 0x000000;
currentScoreTxt.strokeThickness = 3;
LK.gui.center.addChild(currentScoreTxt);
currentScoreTxt.y = 100;
var highScoreTxt = new Text2('', {
size: 60,
fill: 0xFFD700
});
highScoreTxt.anchor.set(0.5, 0.5);
highScoreTxt.visible = false;
highScoreTxt.stroke = 0x000000;
highScoreTxt.strokeThickness = 3;
LK.gui.center.addChild(highScoreTxt);
highScoreTxt.y = 180;
// Create bird
bird = game.addChild(new Bird());
bird.x = 400;
bird.y = 1366;
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 1
}));
ground.x = 0;
ground.y = 2732;
// Create grass layer on ground
var grass = game.addChild(LK.getAsset('groundTop', {
anchorX: 0,
anchorY: 1
}));
grass.x = 0;
grass.y = 2532;
// Create decorative clouds
var clouds = [];
for (var c = 0; c < 4; c++) {
var cloud = game.addChild(LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
}));
cloud.x = Math.random() * 2048;
cloud.y = 300 + Math.random() * 400;
cloud.alpha = 0.7;
cloud.scaleX = 0.8 + Math.random() * 0.4;
cloud.scaleY = 0.8 + Math.random() * 0.4;
clouds.push(cloud);
}
function createPipePair() {
// Ensure gap is positioned properly within screen bounds with better proportions
// Account for pipe height (800px), gap size (500px), and ground position (2532)
var minGapY = 600; // Higher minimum gap center position for better clearance
var maxGapY = 1800; // Ensure bottom pipe can reach ground properly
var gapY = minGapY + Math.random() * (maxGapY - minGapY);
// Ensure the bottom pipe will touch the ground
var bottomPipeTop = gapY + gapSize / 2;
var bottomPipeBottom = bottomPipeTop + 800;
if (bottomPipeBottom < 2532) {
// Adjust gap position so bottom pipe touches ground
var adjustment = 2532 - bottomPipeBottom;
gapY += adjustment;
}
var topPipe = new Pipe(true, gapY);
topPipe.x = nextPipeX;
pipes.push(topPipe);
game.addChild(topPipe);
var bottomPipe = new Pipe(false, gapY);
bottomPipe.x = nextPipeX;
pipes.push(bottomPipe);
game.addChild(bottomPipe);
nextPipeX += pipeSpacing;
}
function resetGame() {
// Reset bird
bird.x = 400;
bird.y = 1366;
bird.velocity = 0;
bird.lastY = bird.y;
bird.wingState = 0;
// Reset bird visual state
bird.children[0].rotation = 0; // Reset body rotation
bird.children[1].y = -5; // Reset wing position
bird.children[1].scaleY = 1; // Reset wing scale
// Clear pipes
for (var i = pipes.length - 1; i >= 0; i--) {
pipes[i].destroy();
}
pipes = [];
// Reset variables
nextPipeX = 2048;
gameStarted = false;
gameOver = false;
gameWaitingForRestart = false;
lastBirdY = bird.y;
lastFlapTime = 0;
gameSpeed = 4;
LK.setScore(0);
scoreTxt.setText('SKOR: 0');
// Hide game over display elements
gameOverTxt.visible = false;
currentScoreTxt.visible = false;
highScoreTxt.visible = false;
// Create initial pipes
createPipePair();
createPipePair();
}
// Initialize first pipes
createPipePair();
createPipePair();
function showGameOverScreen() {
var currentScore = LK.getScore();
// Update high score if needed
if (currentScore > highScore) {
highScore = currentScore;
storage.highScore = highScore;
}
// Show game over display
gameOverTxt.visible = true;
currentScoreTxt.setText('SKOR: ' + currentScore);
currentScoreTxt.visible = true;
highScoreTxt.setText('EN YÜKSEK SKOR: ' + highScore);
highScoreTxt.visible = true;
// Set waiting for restart state and show game over screen
gameWaitingForRestart = true;
gameOver = true;
LK.showGameOver();
}
var lastFlapTime = 0;
var flapCooldown = 250; // Quarter second delay between flaps in milliseconds
game.down = function (x, y, obj) {
// Handle restart after game over
if (gameWaitingForRestart) {
resetGame();
return;
}
if (gameOver) return; // Ignore clicks when game is over
var currentTime = Date.now();
if (currentTime - lastFlapTime < flapCooldown) return; // Debounce rapid clicks with increased delay
if (!gameStarted) {
gameStarted = true;
}
bird.flap();
lastFlapTime = currentTime;
};
game.update = function () {
if (!gameStarted || gameOver || gameWaitingForRestart) return;
// Check if bird hits ground (immediate detection with proper hitbox)
// Ground is positioned at y=2732 with height 200, so ground surface is at y=2532
if (bird.y + 30 >= 2532) {
gameOver = true;
showGameOverScreen();
return;
}
// Check if bird goes too high
if (bird.y < 50) {
if (!gameOver) {
gameOver = true;
showGameOverScreen();
}
return;
}
// Only check collision every 4th frame for better performance
if (LK.ticks % 4 === 0) {
// Pre-calculate bird boundaries once
var birdLeft = bird.x - 35;
var birdRight = bird.x + 35;
var birdTop = bird.y - 25;
var birdBottom = bird.y + 25;
// Check pipe collisions and scoring - optimized loop
for (var i = 0; i < pipes.length; i += 2) {
var pipe = pipes[i];
// Skip collision check for distant pipes
if (pipe.x < birdLeft - 200 || pipe.x > birdRight + 200) continue;
var pipeLeft = pipe.x - 60;
var pipeRight = pipe.x + 60;
// Check collision if bird is within pipe X range
if (birdRight > pipeLeft && birdLeft < pipeRight) {
if (birdTop <= pipe.y || birdBottom >= pipes[i + 1].y) {
gameOver = true;
showGameOverScreen();
return;
}
}
// Check for scoring (only check top pipe)
if (!pipe.passed && pipe.x + 60 < bird.x) {
pipe.passed = true;
pipes[i + 1].passed = true;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText('SKOR: ' + LK.getScore());
LK.getSound('score').play();
// Remove oldest pipe pairs after every 5 pipes passed
if (LK.getScore() % 5 === 0 && pipes.length > 10) {
// Remove the first two pipes (one pair)
pipes[0].destroy();
pipes[1].destroy();
pipes.splice(0, 2);
}
}
}
}
// Create new pipes when needed
if (pipes.length === 0 || nextPipeX - pipes[pipes.length - 1].x >= pipeSpacing) {
createPipePair();
}
// Update game speed much less frequently
if (LK.ticks % 1200 === 0 && LK.getScore() > 0) {
gameSpeed = Math.min(6, 4 + LK.getScore() * 0.02);
for (var j = 0; j < pipes.length; j++) {
pipes[j].speed = -gameSpeed;
}
}
// Animate clouds much less frequently for better performance
if (LK.ticks % 10 === 0 && typeof clouds !== 'undefined') {
for (var cloudIndex = 0; cloudIndex < clouds.length; cloudIndex++) {
clouds[cloudIndex].x -= 0.3;
if (clouds[cloudIndex].x < -60) {
clouds[cloudIndex].x = 2108;
clouds[cloudIndex].y = 300 + Math.random() * 400;
}
}
}
};