Code edit (1 edits merged)
Please save this source code
User prompt
Ice Tap Challenge
Initial prompt
// Global değişkenler let blocks = []; let score = 0; let gameOver = false; let blockSize = 80; let spawnInterval = 1500; // ms aralıklarla yeni blok let lastSpawn = 0; // Buz bloğu sınıfı class Block { constructor(x, y, isGood) { this.x = x; this.y = y; this.size = blockSize; this.isGood = isGood; // true = beyaz, false = kırmızı (yanlış) this.img = LK.getAsset(isGood ? "ice_good.png" : "ice_bad.png"); this.lastTapped = false; // Önceki dokunma durumu } draw(ctx) { ctx.drawImage(this.img, this.x, this.y, this.size, this.size); } isHit(x, y) { return ( x >= this.x && x <= this.x + this.size && y >= this.y && y <= this.y + this.size ); } } // Oyunu başlatma fonksiyonu LK.onStart(() => { score = 0; gameOver = false; blocks = []; lastSpawn = Date.now(); // Başlangıçta 3 blok oluştur for (let i = 0; i < 3; i++) { spawnBlock(); } // Dokunma olayı LK.onTouchStart(handleTap); // Fare için (PC) LK.onMouseDown(handleTap); }); // Yeni blok oluştur function spawnBlock() { let cols = Math.floor(LK.getWidth() / blockSize); let x = Math.floor(Math.random() * cols) * blockSize; let y = Math.floor(Math.random() * (LK.getHeight() / blockSize)) * blockSize; // Aynı yerde blok varsa yeniden dene for (let b of blocks) { if (b.x === x && b.y === y) return; // spawn iptal, tekrar çağıracak update } // %70 beyaz, %30 kırmızı blok let isGood = Math.random() < 0.7; blocks.push(new Block(x, y, isGood)); } // Dokunma / tıklama işleyici function handleTap(x, y) { if (gameOver) return; for (let i = 0; i < blocks.length; i++) { let b = blocks[i]; if (b.isHit(x, y)) { if (b.isGood) { score++; blocks.splice(i, 1); // Bloğu kaldır } else { // Kötü bloğa dokunma = oyun bitti gameOver = true; } break; } } } // Güncelleme döngüsü LK.onUpdate((ctx) => { ctx.clearRect(0, 0, LK.getWidth(), LK.getHeight()); if (gameOver) { ctx.fillStyle = "red"; ctx.font = "48px Arial"; ctx.textAlign = "center"; ctx.fillText("Oyun Bitti!", LK.getWidth() / 2, LK.getHeight() / 2 - 20); ctx.font = "24px Arial"; ctx.fillText("Skor: " + score, LK.getWidth() / 2, LK.getHeight() / 2 + 20); ctx.fillText("Yeniden başlamak için dokun", LK.getWidth() / 2, LK.getHeight() / 2 + 60); return; } // Yeni blok oluşturma zaman kontrolü if (Date.now() - lastSpawn > spawnInterval) { spawnBlock(); lastSpawn = Date.now(); // Oyun zorlaştıkça blok çıkış hızını artır if (spawnInterval > 500) { spawnInterval -= 20; } } // Blokları çiz for (let block of blocks) { block.draw(ctx); } // Skoru çiz ctx.fillStyle = "black"; ctx.font = "24px Arial"; ctx.textAlign = "left"; ctx.fillText("Skor: " + score, 10, 30); }); // Yeniden başlatma için dokunma yakalama LK.onTouchStart((x, y) => { if (gameOver) { // Oyunu sıfırla score = 0; gameOver = false; blocks = []; lastSpawn = Date.now(); for (let i = 0; i < 3; i++) { spawnBlock(); } } }); LK.onMouseDown((x, y) => { if (gameOver) { score = 0; gameOver = false; blocks = []; lastSpawn = Date.now(); for (let i = 0; i < 3; i++) { spawnBlock(); } } });
/**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 });
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});