gpt-4.1-2025-04-14· OpenAI
LMArena Human Preference 140K
dodaj regulację predkości fry
- User
dodaj regulację predkości fry
- Assistant
Oczywiście! Dodam suwak do regulacji prędkości gry (FPS/rate przesuwania rur i ptaka).
Możesz zmieniać prędkość w trakcie gry – im wyższa wartość, tym szybciej wszystko się porusza.Poniżej znajdziesz kompletny kod z suwakiem "Prędkość gry" nad planszą.
Domyślna prędkość to 1.0 (możesz ustawić od 0.5 do 2.5).
<!DOCTYPE html> <html lang="pl"> <head> <meta charset="UTF-8" /> <title>Flappy Bird – Regulacja prędkości</title> <style> * { box-sizing: border-box; margin: 0; padding: 0; } body { background: #70c5ce; display: flex; flex-direction: column; align-items: center; font-family: Arial, sans-serif; user-select: none; } h1 { color:#fff; margin:15px 0 5px } #score { color:#fff; font-size:22px; margin-bottom:10px } #speedControl { margin: 10px 0 5px 0; color: #fff; font-size: 16px; display: flex; align-items: center; gap: 10px; } #speedValue { width: 40px; display: inline-block; text-align: right; } canvas { background: #4ec0ca; border: 2px solid #fff; box-shadow: 0 4px 20px rgba(0,0,0,.3); } #hint { margin-top:8px; color:#fff; font-size:14px } </style> </head> <body> <h1>Flappy Bird</h1> <div id="speedControl"> Prędkość gry: <input type="range" id="speedSlider" min="0.5" max="2.5" step="0.1" value="1.0"> <span id="speedValue">1.0x</span> </div> <div id="score">Score: 0</div> <canvas id="game" width="400" height="550"></canvas> <div id="hint">Kliknij lub naciśnij SPACJĘ, by skoczyć</div> <script> /******************* USTAWIENIA *******************/ const canvas = document.getElementById("game"); const ctx = canvas.getContext("2d"); const scoreEl = document.getElementById("score"); const speedSlider = document.getElementById("speedSlider"); const speedValue = document.getElementById("speedValue"); const GRAVITY = 0.45; const FLAP_STRENGTH = -8; const PIPE_GAP = 120; const PIPE_WIDTH = 60; const PIPE_INTERVAL = 1500; const BIRD_SIZE = 24; let gameSpeed = 1.0; // domyślna prędkość speedSlider.addEventListener("input", () => { gameSpeed = parseFloat(speedSlider.value); speedValue.textContent = gameSpeed.toFixed(1) + "x"; }); /******************* ZMIENNE GRY *******************/ let bird, pipes, score, lastPipeTime, animId, gameOver; function resetGame() { bird = { x: 80, y: canvas.height/2, vel: 0, frame:0 }; pipes = []; score = 0; lastPipeTime = 0; gameOver = false; scoreEl.textContent = "Score: 0"; } /******************* LOGIKA RYSOWANIA *******************/ function drawBird() { ctx.save(); ctx.translate(bird.x, bird.y); ctx.rotate(Math.min(Math.PI/4, Math.max(-Math.PI/4, bird.vel / 10))); ctx.fillStyle = "#FFD43B"; ctx.strokeStyle = "#333"; ctx.lineWidth = 2; ctx.fillRect(-BIRD_SIZE/2, -BIRD_SIZE/2, BIRD_SIZE, BIRD_SIZE); ctx.strokeRect(-BIRD_SIZE/2, -BIRD_SIZE/2, BIRD_SIZE, BIRD_SIZE); if (Math.floor(bird.frame/5) % 2 === 0) { ctx.fillStyle = "#FFB703"; ctx.fillRect(-BIRD_SIZE/2, -2, BIRD_SIZE/2, 4); } ctx.restore(); } function drawPipes() { ctx.fillStyle = "#5EC639"; pipes.forEach(p => { ctx.fillRect(p.x, 0, PIPE_WIDTH, p.top); ctx.fillRect(p.x, p.top + PIPE_GAP, PIPE_WIDTH, canvas.height - p.top - PIPE_GAP); }); } /******************* PĘTLA GRY *******************/ let lastTimestamp = null; function loop(timestamp) { if (!lastTimestamp) lastTimestamp = timestamp; const delta = (timestamp - lastTimestamp) * gameSpeed; lastTimestamp = timestamp; // Fizyka ptaka bird.vel += GRAVITY * (delta / 16.67); // 16.67ms ~ 60fps bird.y += bird.vel * (delta / 16.67); bird.frame++; // Dodawanie rur co PIPE_INTERVAL ms (uwzględniając prędkość) if (timestamp - lastPipeTime > PIPE_INTERVAL / gameSpeed) { lastPipeTime = timestamp; const topHeight = 50 + Math.random() * (canvas.height - PIPE_GAP - 100); pipes.push({ x: canvas.width, top: topHeight, passed: false }); } // Przesuwanie rur w lewo pipes.forEach(p => p.x -= 2.5 * gameSpeed); // Usuwanie rur poza ekranem if (pipes.length && pipes[0].x + PIPE_WIDTH < 0) pipes.shift(); // Sprawdzenie kolizji & zliczanie punktów pipes.forEach(p => { if (!p.passed && p.x + PIPE_WIDTH < bird.x) { p.passed = true; score++; scoreEl.textContent = "Score: " + score; } if (bird.x + BIRD_SIZE/2 > p.x && bird.x - BIRD_SIZE/2 < p.x + PIPE_WIDTH) { if (bird.y - BIRD_SIZE/2 < p.top || bird.y + BIRD_SIZE/2 > p.top + PIPE_GAP) { gameOver = true; } } }); if (bird.y + BIRD_SIZE/2 >= canvas.height || bird.y - BIRD_SIZE/2 <= 0) { gameOver = true; } ctx.clearRect(0, 0, canvas.width, canvas.height); drawPipes(); drawBird(); if (gameOver) { ctx.fillStyle = "rgba(0,0,0,0.5)"; ctx.fillRect(0,0,canvas.width,canvas.height); ctx.fillStyle = "#fff"; ctx.font = "bold 36px Arial"; ctx.textAlign = "center"; ctx.fillText("GAME OVER", canvas.width/2, canvas.height/2 - 20); ctx.font = "24px Arial"; ctx.fillText("Wynik: " + score, canvas.width/2, canvas.height/2 + 20); ctx.font = "18px Arial"; ctx.fillText("Kliknij lub naciśnij SPACE, aby zagrać ponownie", canvas.width/2, canvas.height/2 + 55); lastTimestamp = null; return; } requestAnimationFrame(loop); } /******************* STEROWANIE *******************/ function flap() { if (gameOver) { resetGame(); lastTimestamp = null; requestAnimationFrame(loop); } else { bird.vel = FLAP_STRENGTH; } } document.addEventListener("keydown", e => { if (e.code === "Space") flap(); }); canvas.addEventListener("mousedown", flap); /******************* START *******************/ resetGame(); requestAnimationFrame(loop); </script> </body> </html>
Jak to działa?
- Suwak „Prędkość gry” zmienia tempo gry w czasie rzeczywistym (od 0.5x do 2.5x).
- Zmienia się szybkość przesuwania rur, grawitacja, częstotliwość pojawiania się rur i ruch ptaka.
- Możesz zmieniać prędkość nawet w trakcie rozgrywki!
Daj znać, jeśli chcesz dodać inne opcje lub efekty!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.