ノート

ブレイクアウトアーケードゲームをHTMLで完全に構築する

フリーのプロンプト百科事典 Wikiprompt より

Eyisha Zyer

2026年7月11日

ブレイクアウトアーケードゲームをHTMLで完全に構築する 包括游戏玩法、控制、视觉、音频和技术细节在内的完整提示,用于在单个HTML文件中生成功能齐全的Breakout游戏。

プロンプト内容保存

🌐
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Neon Breakout</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { background: #0a0a1a; display: flex; justify-content: center; align-items: center; min-height: 100vh; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; overflow: hidden; } #gameContainer { position: relative; width: 100%; max-width: 900px; aspect-ratio: 16/9; background: #0d0d2b; border-radius: 12px; box-shadow: 0 0 40px rgba(0, 200, 255, 0.2), 0 0 80px rgba(0, 200, 255, 0.1); overflow: hidden; } canvas { display: block; width: 100%; height: 100%; background: #0d0d2b; } #startScreen, #gameOverScreen, #winScreen, #pauseOverlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; background: rgba(10, 10, 30, 0.9); color: #fff; z-index: 10; text-align: center; backdrop-filter: blur(5px); } #startScreen h1, #gameOverScreen h1, #winScreen h1 { font-size: 3.5rem; margin-bottom: 20px; text-shadow: 0 0 20px rgba(0, 200, 255, 0.8), 0 0 40px rgba(0, 200, 255, 0.4); letter-spacing: 4px; } #startScreen p, #gameOverScreen p, #winScreen p { font-size: 1.2rem; margin: 10px 0; color: #aaa; } #startScreen .highlight, #gameOverScreen .highlight, #winScreen .highlight { color: #00d4ff; font-weight: bold; text-shadow: 0 0 10px rgba(0, 212, 255, 0.5); } .btn { margin-top: 30px; padding: 15px 40px; font-size: 1.2rem; background: linear-gradient(135deg, #00d4ff, #0080ff); color: #fff; border: none; border-radius: 50px; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; box-shadow: 0 0 20px rgba(0, 212, 255, 0.4); font-weight: bold; letter-spacing: 2px; } .btn:hover { transform: scale(1.05); box-shadow: 0 0 30px rgba(0, 212, 255, 0.7); } #pauseOverlay { display: none; background: rgba(10, 10, 30, 0.7); } #pauseOverlay h2 { font-size: 2.5rem; color: #00d4ff; text-shadow: 0 0 20px rgba(0, 212, 255, 0.8); letter-spacing: 3px; } #pauseOverlay p { color: #aaa; margin-top: 15px; } .hidden { display: none !important; } #gameOverScreen, #winScreen { display: none; } @media (max-width: 768px) { #startScreen h1, #gameOverScreen h1, #winScreen h1 { font-size: 2.5rem; } .btn { padding: 12px 30px; font-size: 1rem; } } </style> </head> <body> <div id="gameContainer"> <canvas id="gameCanvas"></canvas> <div id="startScreen"> <h1>NEON BREAKOUT</h1> <p>Break all the bricks to win!</p> <p class="highlight">Press SPACE to start</p> <p>Move: Mouse or Arrow Keys | Pause: P</p> </div> <div id="pauseOverlay"> <h2>PAUSED</h2> <p>Press P to resume</p> </div> <div id="gameOverScreen"> <h1>GAME OVER</h1> <p>Final Score: <span id="finalScore">0</span></p> <p>Level Reached: <span id="finalLevel">1</span></p> <button class="btn" onclick="restartGame()">PLAY AGAIN</button> </div> <div id="winScreen"> <h1>YOU WIN!</h1> <p>Final Score: <span id="winScore">0</span></p> <p>Congratulations!</p> <button class="btn" onclick="restartGame()">PLAY AGAIN</button> </div> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const container = document.getElementById('gameContainer'); const startScreen = document.getElementById('startScreen'); const gameOverScreen = document.getElementById('gameOverScreen'); const winScreen = document.getElementById('winScreen'); const pauseOverlay = document.getElementById('pauseOverlay'); // Game state let gameState = 'start'; // start, playing, paused, gameover, win let score = 0; let lives = 3; let level = 1; let ballSpeed = 5; let ballSpeedMultiplier = 1; let paddleWidth = 120; let paddleHeight = 15; let paddleX = 0; let ballX = 0; let ballY = 0; let ballDX = 0; let ballDY = 0; let ballRadius = 8; let ballLaunched = false; let bricks = []; let particles = []; let powerUps = []; let keys = {}; let lastTime = 0; let gameTime = 0; let shakeAmount = 0; let paddleColor = '#00d4ff'; // Audio context let audioCtx = null; function initAudio() { if (!audioCtx) { audioCtx = new (window.AudioContext || window.webkitAudioContext)(); } } function playSound(freq, duration, type = 'sine', volume = 0.3) { if (!audioCtx) return; const osc = audioCtx.createOscillator(); const gain = audioCtx.createGain(); osc.type = type; osc.frequency.setValueAtTime(freq, audioCtx.currentTime); gain.gain.setValueAtTime(volume, audioCtx.currentTime); gain.gain.exponentialRampToValueAtTime(0.01, audioCtx.currentTime + duration); osc.connect(gain); gain.connect(audioCtx.destination); osc.start(); osc.stop(audioCtx.currentTime + duration); } function playBounceSound() { playSound(200 + Math.random() * 100, 0.1, 'triangle', 0.2); } function playBrickSound() { playSound(400 + Math.random() * 200, 0.15, 'square', 0.25); } function playGameOverSound() { playSound(300, 0.3, 'sawtooth', 0.3); setTimeout(() => playSound(200, 0.3, 'sawtooth', 0.3), 200); setTimeout(() => playSound(150, 0.5, 'sawtooth', 0.3), 400); } function playWinSound() { playSound(523, 0.2, 'sine', 0.3); setTimeout(() => playSound(659, 0.2, 'sine', 0.3), 200); setTimeout(() => playSound(784, 0.2, 'sine', 0.3), 400); setTimeout(() => playSound(1047, 0.4, 'sine', 0.3), 600); } // Brick colors const brickColors = [ '#ff6b6b', '#ffa500', '#ffd93d', '#6bcb77', '#4d96ff', '#9b59b6' ]; // Brick layout function createBricks() { bricks = []; const rows = 6; const cols = 10; const brickWidth = (canvas.width - 60) / cols; const brickHeight = 25; const gap = 5; const topOffset = 60; for (let row = 0; row < rows; row++) { for (let col = 0; col < cols; col++) { bricks.push({ x: 30 + col * (brickWidth + gap), y: topOffset + row * (brickHeight + gap), width: brickWidth, height: brickHeight, color: brickColors[row % brickColors.length], alive: true, row: row, col: col }); } } } // Particle system function createParticles(x, y, color) { for (let i = 0; i < 12; i++) { particles.push({ x: x, y: y, vx: (Math.random() - 0.5) * 8, vy: (Math.random() - 0.5) * 8 - 2, life: 1, color: color, size: Math.random() * 4 + 2 }); } } // Power-up system function createPowerUp(x, y) { if (Math.random() < 0.15) { const types = ['multi', 'wide', 'slow']; const type = types[Math.floor(Math.random() * types.length)]; powerUps.push({ x: x, y: y, type: type, vy: 2, width: 20, height: 20, color: type === 'multi' ? '#ff6b6b' : type === 'wide' ? '#6bcb77' : '#4d96ff' }); } } // Reset game function resetGame() { score = 0; lives = 3; level = 1; ballSpeed = 5; ballSpeedMultiplier = 1; paddleWidth = 120; createBricks(); resetBall(); particles = []; powerUps = []; gameState = 'playing'; startScreen.classList.add('hidden'); gameOverScreen.style.display = 'none'; winScreen.style.display = 'none'; pauseOverlay.style.display = 'none'; } function resetBall() { ballX = canvas.width / 2; ballY = canvas.height - 50; ballDX = 0; ballDY = 0; ballLaunched = false; ballSpeedMultiplier = 1; } function launchBall() { if (!ballLaunched) { ballLaunched = true; const angle = -Math.PI / 4 + Math.random() * (Math.PI / 2); ballDX = Math.cos(angle) * ballSpeed; ballDY = Math.sin(angle) * ballSpeed; initAudio(); } } // Collision detection function checkCollisions() { // Ball vs walls if (ballX - ballRadius < 0) { ballX = ballRadius; ballDX = -ballDX; playBounceSound(); } if (ballX + ballRadius > canvas.width) { ballX = canvas.width - ballRadius; ballDX = -ballDX; playBounceSound(); } if (ballY - ballRadius < 0) { ballY = ballRadius; ballDY = -ballDY; playBounceSound(); } // Ball vs paddle if (ballY + ballRadius > canvas.height - paddleHeight - 10 && ballY + ballRadius < canvas.height - 5 && ballX > paddleX - paddleWidth / 2 && ballX < paddleX + paddleWidth / 2) { const hitPos = (ballX - paddleX) / (paddleWidth / 2); const angle = hitPos * Math.PI / 3; ballDX = Math.sin(angle) * ballSpeed * ballSpeedMultiplier; ballDY = -Math.cos(angle) * ballSpeed * ballSpeedMultiplier; ballY = canvas.height - paddleHeight - 10 - ballRadius; playBounceSound(); } // Ball vs bricks for (let i = 0; i < bricks.length; i++) { const brick = bricks[i]; if (!brick.alive) continue; if (ballX + ballRadius > brick.x && ballX - ballRadius < brick.x + brick.width && ballY + ballRadius > brick.y && ballY - ballRadius < brick.y + brick.height) { brick.alive = false; score += 10; createParticles(ballX, ballY, brick.color); createPowerUp(brick.x + brick.width / 2, brick.y + brick.height / 2); playBrickSound(); // Determine collision side const overlapLeft = ballX + ballRadius - brick.x; const overlapRight = brick.x + brick.width - (ballX - ballRadius); const overlapTop = ballY + ballRadius - brick.y; const overlapBottom = brick.y + brick.height - (ballY - ballRadius); const minOverlap = Math.min(overlapLeft, overlapRight, overlapTop, overlapBottom); if (minOverlap === overlapLeft || minOverlap === overlapRight) { ballDX = -ballDX; } else { ballDY = -ballDY; } break; } } // Ball vs power-ups for (let i = powerUps.length - 1; i >= 0; i--) { const powerUp = powerUps[i]; if (ballX > powerUp.x - powerUp.width / 2 && ballX < powerUp.x + powerUp.width / 2 && ballY > powerUp.y - powerUp.height / 2 && ballY < powerUp.y + powerUp.height / 2) { applyPowerUp(powerUp.type); powerUps.splice(i, 1); playSound(600, 0.2, 'sine', 0.3); } } } function applyPowerUp(type) { if (type === 'multi') { // Multi-ball effect for (let i = 0; i < 2; i++) { setTimeout(() => { if (gameState === 'playing') { const angle = Math.random() * Math.PI * 2; const speed = ballSpeed * ballSpeedMultiplier; // Create a new ball balls.push({ x: ballX, y: ballY, dx: Math.cos(angle) * speed, dy: Math.sin(angle) * speed, radius: ballRadius }); } }, 100 * i); } } else if (type === 'wide') { paddleWidth = Math.min(paddleWidth * 1.5, 250); setTimeout(() => { paddleWidth = 120; }, 10000); } else if (type === 'slow') { ballSpeedMultiplier = 0.7; setTimeout(() => { ballSpeedMultiplier = 1; }, 5000); } } // Multi-ball support let balls = []; // Update game function update(deltaTime) { if (gameState !== 'playing') return; gameTime += deltaTime; // Move paddle if (keys['ArrowLeft'] || keys['a']) { paddleX -= 400 * deltaTime; } if (keys['ArrowRight'] || keys['d']) { paddleX += 400 * deltaTime; } paddleX = Math.max(paddleWidth / 2, Math.min(canvas.width - paddleWidth / 2, paddleX)); // Move balls if (ballLaunched) { ballX += ballDX * deltaTime * 60; ballY += ballDY * deltaTime * 60; } else { ballX = paddleX; ballY = canvas.height - 50; } // Move extra balls for (let i = balls.length - 1; i >= 0; i--) { const b = balls[i]; b.x += b.dx * deltaTime * 60; b.y += b.dy * deltaTime * 60; // Wall collisions for extra balls if (b.x - b.radius < 0) { b.x = b.radius; b.dx = -b.dx; } if (b.x + b.radius > canvas.width) { b.x = canvas.width - b.radius; b.dx = -b.dx; } if (b.y - b.radius < 0) { b.y = b.radius; b.dy = -b.dy; } // Paddle collision for extra balls if (b.y + b.radius > canvas.height - paddleHeight - 10 && b.y + b.radius < canvas.height - 5 && b.x > paddleX - paddleWidth / 2 && b.x < paddleX + paddleWidth / 2) { const hitPos = (b.x - paddleX) / (paddleWidth / 2); const angle = hitPos * Math.PI / 3; b.dx = Math.sin(angle) * ballSpeed * ballSpeedMultiplier; b.dy = -Math.cos(angle) * ballSpeed * ballSpeedMultiplier; b.y = canvas.height - paddleHeight - 10 - b.radius; playBounceSound(); } // Brick collisions for extra balls for (let j = 0; j < bricks.length; j++) { const brick = bricks[j]; if (!brick.alive) continue; if (b.x + b.radius > brick.x && b.x - b.radius < brick.x + brick.width && b.y + b.radius > brick.y && b.y - b.radius < brick.y + brick.height) { brick.alive = false; score += 10; createParticles(b.x, b.y, brick.color); playBrickSound(); const overlapLeft = b.x + b.radius - brick.x; const overlapRight = brick.x + brick.width - (b.x - b.radius); const overlapTop = b.y + b.radius - brick.y; const overlapBottom = brick.y + brick.height - (b.y - b.radius); const minOverlap = Math.min(overlapLeft, overlapRight, overlapTop, overlapBottom); if (minOverlap === overlapLeft || minOverlap === overlapRight) { b.dx = -b.dx; } else { b.dy = -b.dy; } break; } } // Remove balls that fall below if (b.y - b.radius > canvas.height) { balls.splice(i, 1); } } // Main ball below screen if (ballY - ballRadius > canvas.height) { lives--; if (lives <= 0) { gameState = 'gameover'; document.getElementById('finalScore').textContent = score; document.getElementById('finalLevel').textContent = level; gameOverScreen.style.display = 'flex'; playGameOverSound(); } else { resetBall(); balls = []; } } // Check win condition const remainingBricks = bricks.filter(b => b.alive).length; if (remainingBricks === 0) { level++; ballSpeed += 1; createBricks(); resetBall(); balls = []; playWinSound(); } // Update particles for (let i = particles.length - 1; i >= 0; i--) { const p = particles[i]; p.x += p.vx; p.y += p.vy; p.vy += 0.2; p.life -= 0.02; if (p.life <= 0) { particles.splice(i, 1); } } // Update power-ups for (let i = powerUps.length - 1; i >= 0; i--) { const p = powerUps[i]; p.y += p.vy; if (p.y > canvas.height) { powerUps.splice(i, 1); } } // Shake effect if (shakeAmount > 0) { shakeAmount *= 0.9; } } // Draw functions function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); // Background gradient const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height); gradient.addColorStop(0, '#0d0d2b'); gradient.addColorStop(1, '#1a1a3e'); ctx.fillStyle = gradient; ctx.fillRect(0, 0, canvas.width, canvas.height); // Grid pattern ctx.strokeStyle = 'rgba(255, 255, 255, 0.03)'; ctx.lineWidth = 1; for (let i = 0; i < canvas.width; i += 30) { ctx.beginPath(); ctx.moveTo(i, 0); ctx.lineTo(i, canvas.height); ctx.stroke(); } for (let i = 0; i < canvas.height; i += 30) { ctx.beginPath(); ctx.moveTo(0, i); ctx.lineTo(canvas.width, i); ctx.stroke(); } // Draw bricks for (const brick of bricks) { if (!brick.alive) continue; const gradient = ctx.createLinearGradient(brick.x, brick.y, brick.x, brick.y + brick.height); gradient.addColorStop(0, brick.color); gradient.addColorStop(1, shadeColor(brick.color, -30)); ctx.fillStyle = gradient; ctx.shadowColor = brick.color; ctx.shadowBlur = 10; ctx.fillRect(brick.x, brick.y, brick.width, brick.height); ctx.shadowBlur = 0; ctx.strokeStyle = 'rgba(255, 255, 255, 0.2)'; ctx.lineWidth = 1; ctx.strokeRect(brick.x, brick.y, brick.width, brick.height); } // Draw paddle const paddleGradient = ctx.createLinearGradient(paddleX - paddleWidth / 2, 0, paddleX + paddleWidth / 2, 0); paddleGradient.addColorStop(0, paddleColor); paddleGradient.addColorStop(1, shadeColor(paddleColor, -30)); ctx.fillStyle = paddleGradient; ctx.shadowColor = paddleColor; ctx.shadowBlur = 20; ctx.beginPath(); ctx.roundRect(paddleX - paddleWidth / 2, canvas.height - paddleHeight - 10, paddleWidth, paddleHeight, 8); ctx.fill(); ctx.shadowBlur = 0; // Draw main ball if (ballLaunched) { ctx.beginPath(); ctx.arc(ballX, ballY, ballRadius, 0, Math.PI * 2); ctx.fillStyle = '#ffffff'; ctx.shadowColor = '#00d4ff'; ctx.shadowBlur = 15; ctx.fill(); ctx.shadowBlur = 0; } else { // Draw ball on paddle ctx.beginPath(); ctx.arc(ballX, ballY, ballRadius, 0, Math.PI * 2); ctx.fillStyle = '#ffffff'; ctx.shadowColor = '#00d4ff'; ctx.shadowBlur = 15; ctx.fill(); ctx.shadowBlur = 0; } // Draw extra balls for (const b of balls) { ctx.beginPath(); ctx.arc(b.x, b.y, b.radius, 0, Math.PI * 2); ctx.fillStyle = '#ffffff'; ctx.shadowColor = '#ff6b6b'; ctx.shadowBlur = 15; ctx.fill(); ctx.shadowBlur = 0; } // Draw particles for (const p of particles) { ctx.globalAlpha = p.life; ctx.fillStyle = p.color; ctx.beginPath(); ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2); ctx.fill(); } ctx.globalAlpha = 1; // Draw power-ups for (const p of powerUps) { ctx.fillStyle = p.color; ctx.shadowColor = p.color; ctx.shadowBlur = 10; ctx.beginPath(); ctx.roundRect(p.x - p.width / 2, p.y - p.height / 2, p.width, p.height, 5); ctx.fill(); ctx.shadowBlur = 0; ctx.fillStyle = '#fff'; ctx.font = '12px Arial'; ctx.textAlign = 'center'; ctx.textBaseline = 'middle'; ctx.fillText(p.type[0].toUpperCase(), p.x, p.y); } // Draw HUD ctx.fillStyle = '#ffffff'; ctx.font = 'bold 20px "Segoe UI", Arial'; ctx.textAlign = 'left'; ctx.shadowColor = '#00d4ff'; ctx.shadowBlur = 10; ctx.fillText(`SCORE: ${score}`, 20, 35); ctx.shadowBlur = 0; ctx.textAlign = 'right'; ctx.shadowColor = '#ff6b6b'; ctx.shadowBlur = 10; ctx.fillText(`LEVEL: ${level}`, canvas.width - 20, 35); ctx.shadowBlur = 0; // Draw lives (hearts) ctx.textAlign = 'center'; ctx.font = '24px Arial'; for (let i = 0; i < lives; i++) { ctx.fillStyle = '#ff6b6b'; ctx.shadowColor = '#ff6b6b'; ctx.shadowBlur = 10; ctx.fillText('♥', canvas.width / 2 + (i - (lives - 1) / 2) * 30, 35); } ctx.shadowBlur = 0; // Draw launch indicator if (!ballLaunched && gameState === 'playing') { ctx.fillStyle = 'rgba(255, 255, 255, 0.7)'; ctx.font = '16px "Segoe UI", Arial'; ctx.textAlign = 'center'; ctx.fillText('Press SPACE to launch', canvas.width / 2, canvas.height - 80); } } function shadeColor(color, percent) { const num = parseInt(color.replace('#', ''), 16); const amt = Math.round(2.55 * percent); const R = (num >> 16) + amt; const G = (num >> 8 & 0x00FF) + amt; const B = (num & 0x0000FF) + amt; return '#' + (0x1000000 + (R < 255 ? (R < 1 ? 0 : R) : 255) * 0x10000 + (G < 255 ? (G < 1 ? 0 : G) : 255) * 0x100 + (B < 255 ? (B < 1 ? 0 : B) : 255)).toString(16).slice(1); } // Game loop let lastFrameTime = 0; function gameLoop(timestamp) { const deltaTime = Math.min((timestamp - lastFrameTime) / 1000, 0.05); lastFrameTime = timestamp; update(deltaTime); draw(); requestAnimationFrame(gameLoop); } // Event listeners document.addEventListener('keydown', (e) => { keys[e.key] = true; if (e.key === ' ') { e.preventDefault(); if (gameState === 'start') { resetGame(); } else if (gameState === 'playing') { launchBall(); } } if (e.key === 'p' || e.key === 'P') { if (gameState === 'playing') { gameState = 'paused'; pauseOverlay.style.display = 'flex'; } else if (gameState === 'paused') { gameState = 'playing'; pauseOverlay.style.display = 'none'; lastFrameTime = performance.now(); } } }); document.addEventListener('keyup', (e) => { keys[e.key] = false; }); document.addEventListener('mousemove', (e) => { const rect = canvas.getBoundingClientRect(); const scaleX = canvas.width / rect.width; paddleX = (e.clientX - rect.left) * scaleX; paddleX = Math.max(paddleWidth / 2, Math.min(canvas.width - paddleWidth / 2, paddleX)); }); canvas.addEventListener('click', () => { if (gameState === 'start') { resetGame(); } else if (gameState === 'playing') { launchBall(); } }); function restartGame() { resetGame(); } // Resize canvas function resizeCanvas() { const rect = container.getBoundingClientRect(); canvas.width = rect.width; canvas.height = rect.height; paddleX = canvas.width / 2; if (gameState === 'start') { ballX = canvas.width / 2; ballY = canvas.height - 50; } createBricks(); } window.addEventListener('resize', resizeCanvas); // Initialize resizeCanvas(); createBricks(); ballX = canvas.width / 2; ballY = canvas.height - 50; paddleX = canvas.width / 2; // Start game loop requestAnimationFrame(gameLoop); </script> </body> </html>

ログインして完全なプロンプトを表示

次で続行:

ログインすると、次に同意したことになります: 利用規約 プライバシーポリシー

使い方

このプロンプトは coding 向けに設計されています。上の内容をコピーして、お好みの AI ツールに貼り付けてください。

最良の結果を得るには、プレースホルダー(角括弧や大文字で示された部分)を具体的な要件に置き換えてください。

参考資料

カテゴリ:coding| twitter| breakout-game| html5-canvas

ノート