Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'sprite')' in or related to this line: 'var topPipe = LK.create.sprite('greenTile');' Line Number: 248
Code edit (1 edits merged)
Please save this source code
User prompt
Flappy Bird
Initial prompt
const gravity = 0.5; const jumpPower = -10; let bird; let birdY = 200; let birdVelocity = 0; let pipes = []; let pipeSpeed = 2; let pipeGap = 120; let pipeWidth = 50; let score = 0; let gameOver = false; function createBird() { bird = LK.create.sprite('blueTile'); // Kuşu temsil eden blok bird.pos(100, birdY); bird.size(40, 30); } function createPipe(x) { // Boru üst parça let topHeight = Math.random() * 150 + 50; let topPipe = LK.create.sprite('greenTile'); topPipe.pos(x, 0); topPipe.size(pipeWidth, topHeight); // Boru alt parça let bottomPipe = LK.create.sprite('greenTile'); bottomPipe.pos(x, topHeight + pipeGap); bottomPipe.size(pipeWidth, 400 - (topHeight + pipeGap)); pipes.push({top: topPipe, bottom: bottomPipe, passed:false}); } function resetGame() { // Boruları temizle pipes.forEach(p => { LK.remove(p.top); LK.remove(p.bottom); }); pipes = []; score = 0; birdY = 200; birdVelocity = 0; gameOver = false; createBird(); createPipe(400); createPipe(600); createPipe(800); } function update() { if(gameOver) return; birdVelocity += gravity; birdY += birdVelocity; if(birdY > 370 || birdY < 0) { gameOver = true; } bird.pos(bird.x, birdY); // Boruları hareket ettir pipes.forEach(p => { p.top.pos(p.top.x - pipeSpeed, p.top.y); p.bottom.pos(p.bottom.x - pipeSpeed, p.bottom.y); // Boru ekran dışına çıkarsa yenisi gelsin if(p.top.x < -pipeWidth) { LK.remove(p.top); LK.remove(p.bottom); pipes.shift(); let lastX = pipes.length > 0 ? pipes[pipes.length -1].top.x : 800; createPipe(lastX + 200); } // Kuş boruyu geçtiyse skor artar if(!p.passed && p.top.x + pipeWidth < bird.x) { score++; p.passed = true; console.log("Puan: " + score); } // Çarpma kontrolü (basit AABB) if(collides(bird, p.top) || collides(bird, p.bottom)) { gameOver = true; } }); } function collides(a, b) { return !(a.x + a.width < b.x || a.x > b.x + b.width || a.y + a.height < b.y || a.y > b.y + b.height); } // Kuş zıplaması LK.on('click', () => { if(gameOver) { resetGame(); } else { birdVelocity = jumpPower; } }); resetGame(); LK.ticker(() => { update(); });
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
}); /****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});