Create a retro-themed, bug arcade game in Pygame. The game design looks like it could…
- User
Create a retro-themed, bug arcade game in Pygame. The game design looks like it could have been played in an arcade back in the 80's. Do not rely on external file uploads and instead create your own assets and designs.
Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bug Blaster - Retro Arcade</title> <style> @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap'); body { margin: 0; padding: 0; background: #000; display: flex; justify-content: center; align-items: center; min-height: 100vh; font-family: 'Press Start 2P', monospace; background: linear-gradient(45deg, #000, #111); } #gameContainer { position: relative; border: 3px solid #0f0; box-shadow: 0 0 20px #0f0, inset 0 0 20px #0f0; background: #000; padding: 10px; } #gameCanvas { display: block; image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; } #ui { position: absolute; top: 10px; left: 10px; color: #0f0; font-size: 12px; text-shadow: 0 0 5px #0f0; } #gameOver { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #f00; font-size: 20px; text-align: center; display: none; text-shadow: 0 0 10px #f00; } #startScreen { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: #0f0; font-size: 16px; text-align: center; text-shadow: 0 0 10px #0f0; } .blink { animation: blink 1s infinite; } @keyframes blink { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } } </style> </head> <body> <div id="gameContainer"> <canvas id="gameCanvas" width="800" height="600"></canvas> <div id="ui"> <div>SCORE: <span id="score">0</span></div> <div>LIVES: <span id="lives">3</span></div> <div>LEVEL: <span id="level">1</span></div> </div> <div id="gameOver"> <div>GAME OVER</div> <div style="font-size: 12px; margin-top: 20px;">PRESS SPACE TO RESTART</div> </div> <div id="startScreen"> <div style="font-size: 24px; margin-bottom: 20px;">BUG BLASTER</div> <div style="font-size: 10px; margin-bottom: 30px;"> USE ARROW KEYS TO MOVE<br> SPACE TO FIRE<br> DESTROY ALL BUGS! </div> <div class="blink">PRESS SPACE TO START</div> </div> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); // Game state let gameState = 'start'; // 'start', 'playing', 'gameOver' let score = 0; let lives = 3; let level = 1; let bugs = []; let bullets = []; let particles = []; let stars = []; // Player const player = { x: canvas.width / 2 - 20, y: canvas.height - 60, width: 40, height: 30, speed: 5, color: '#0f0' }; // Controls const keys = {}; // Initialize stars for background function initStars() { stars = []; for (let i = 0; i < 100; i++) { stars.push({ x: Math.random() * canvas.width, y: Math.random() * canvas.height, speed: Math.random() * 2 + 0.5, brightness: Math.random() }); } } // Create bug formation function createBugs() { bugs = []; const rows = 5 + Math.floor(level / 2); const cols = 8 + Math.floor(level / 3); const bugWidth = 30; const bugHeight = 20; const spacing = 10; for (let row = 0; row < rows; row++) { for (let col = 0; col < cols; col++) { bugs.push({ x: col * (bugWidth + spacing) + 100, y: row * (bugHeight + spacing) + 50, width: bugWidth, height: bugHeight, speed: 1 + level * 0.2, direction: 1, type: row % 3, alive: true, animFrame: 0 }); } } } // Draw retro pixel art function drawPixelRect(x, y, w, h, color) { ctx.fillStyle = color; ctx.fillRect(Math.floor(x), Math.floor(y), w, h); } // Draw player ship function drawPlayer() { // Ship body drawPixelRect(player.x + 15, player.y, 10, 30, '#0f0'); drawPixelRect(player.x + 10, player.y + 25, 20, 5, '#0f0'); drawPixelRect(player.x + 5, player.y + 20, 30, 5, '#0f0'); drawPixelRect(player.x, player.y + 15, 40, 5, '#0f0'); // Cockpit drawPixelRect(player.x + 17, player.y + 5, 6, 10, '#000'); drawPixelRect(player.x + 18, player.y + 6, 4, 8, '#0ff'); // Engine glow const glow = Math.sin(Date.now() * 0.01) * 0.5 + 0.5; drawPixelRect(player.x + 17, player.y + 30, 2, 5 + glow * 3, '#ff0'); drawPixelRect(player.x + 21, player.y + 30, 2, 5 + glow * 3, '#ff0'); } // Draw bug function drawBug(bug) { if (!bug.alive) return; const anim = Math.floor(bug.animFrame / 10) % 2; const colors = ['#f00', '#ff0', '#f0f']; const color = colors[bug.type]; // Bug body drawPixelRect(bug.x + 5, bug.y, 20, 15, color); drawPixelRect(bug.x + 2, bug.y + 5, 26, 10, color); drawPixelRect(bug.x, bug.y + 10, 30, 10, color); // Legs const legOffset = anim * 2; drawPixelRect(bug.x - 3, bug.y + 8 + legOffset, 3, 2, color); drawPixelRect(bug.x - 3, bug.y + 12 - legOffset, 3, 2, color); drawPixelRect(bug.x + 30, bug.y + 8 + legOffset, 3, 2, color); drawPixelRect(bug.x + 30, bug.y + 12 - legOffset, 3, 2, color); // Eyes drawPixelRect(bug.x + 8, bug.y + 3, 3, 3, '#000'); drawPixelRect(bug.x + 19, bug.y + 3, 3, 3, '#000'); drawPixelRect(bug.x + 9, bug.y + 4, 1, 1, '#fff'); drawPixelRect(bug.x + 20, bug.y + 4, 1, 1, '#fff'); bug.animFrame++; } // Draw bullet function drawBullet(bullet) { drawPixelRect(bullet.x, bullet.y, 3, 10, '#0ff'); drawPixelRect(bullet.x - 1, bullet.y - 2, 5, 2, '#fff'); } // Draw particle function drawParticle(particle) { const alpha = particle.life / particle.maxLife; ctx.fillStyle = `rgba(${particle.color}, ${alpha})`; ctx.fillRect(particle.x, particle.y, particle.size, particle.size); } // Create explosion particles function createExplosion(x, y, color) { for (let i = 0; i < 8; i++) { particles.push({ x: x, y: y, vx: (Math.random() - 0.5) * 8, vy: (Math.random() - 0.5) * 8, size: Math.random() * 4 + 2, life: 30, maxLife: 30, color: color }); } } // Update game function update() { if (gameState !== 'playing') return; // Update stars stars.forEach(star => { star.y += star.speed; if (star.y > canvas.height) { star.y = 0; star.x = Math.random() * canvas.width; } }); // Player movement if (keys['ArrowLeft'] && player.x > 0) { player.x -= player.speed; } if (keys['ArrowRight'] && player.x < canvas.width - player.width) { player.x += player.speed; } // Fire bullets if (keys[' '] && !keys.spacePressed) { bullets.push({ x: player.x + player.width / 2 - 1, y: player.y, speed: 10 }); keys.spacePressed = true; } // Update bullets bullets = bullets.filter(bullet => { bullet.y -= bullet.speed; return bullet.y > -10; }); // Update bugs let moveDown = false; bugs.forEach(bug => { if (bug.alive) { bug.x += bug.speed * bug.direction; if (bug.x <= 0 || bug.x >= canvas.width - bug.width) { moveDown = true; } } }); if (moveDown) { bugs.forEach(bug => { bug.direction *= -1; bug.y += 20; }); } // Update particles particles = particles.filter(particle => { particle.x += particle.vx; particle.y += particle.vy; particle.life--; return particle.life > 0; }); // Check collisions bullets.forEach((bullet, bulletIndex) => { bugs.forEach((bug, bugIndex) => { if (bug.alive && bullet.x < bug.x + bug.width && bullet.x + 3 > bug.x && bullet.y < bug.y + bug.height && bullet.y + 10 > bug.y) { bug.alive = false; bullets.splice(bulletIndex, 1); score += 10 * (bug.type + 1); createExplosion(bug.x + bug.width/2, bug.y + bug.height/2, '255,255,0'); } }); }); // Check if bugs reached bottom bugs.forEach(bug => { if (bug.alive && bug.y + bug.height > player.y) { lives--; createExplosion(player.x + player.width/2, player.y + player.height/2, '0,255,0'); resetLevel(); } }); // Check if all bugs destroyed if (bugs.every(bug => !bug.alive)) { level++; createBugs(); } // Check game over if (lives <= 0) { gameState = 'gameOver'; document.getElementById('gameOver').style.display = 'block'; } // Update UI document.getElementById('score').textContent = score; document.getElementById('lives').textContent = lives; document.getElementById('level').textContent = level; } // Reset level function resetLevel() { player.x = canvas.width / 2 - 20; bullets = []; if (lives > 0) { createBugs(); } } // Draw everything function draw() { // Clear with scanline effect ctx.fillStyle = '#000'; ctx.fillRect(0, 0, canvas.width, canvas.height); // Draw stars stars.forEach(star => { const brightness = star.brightness * 255; ctx.fillStyle = `rgb(${brightness}, ${brightness}, ${brightness})`; ctx.fillRect(star.x, star.y, 1, 1); }); if (gameState === 'playing') { // Draw player drawPlayer(); // Draw bugs bugs.forEach(drawBug); // Draw bullets bullets.forEach(drawBullet); // Draw particles particles.forEach(drawParticle); // Draw scanlines ctx.fillStyle = 'rgba(0, 255, 0, 0.03)'; for (let i = 0; i < canvas.height; i += 4) { ctx.fillRect(0, i, canvas.width, 1); } } } // Game loop function gameLoop() { update(); draw(); requestAnimationFrame(gameLoop); } // Event listeners window.addEventListener('keydown', (e) => { keys[e.key] = true; if (e.key === ' ') { e.preventDefault(); if (gameState === 'start') { gameState = 'playing'; document.getElementById('startScreen').style.display = 'none'; } else if (gameState === 'gameOver') { gameState = 'playing'; score = 0; lives = 3; level = 1; document.getElementById('gameOver').style.display = 'none'; resetLevel(); } } }); window.addEventListener('keyup', (e) => { keys[e.key] = false; if (e.key === ' ') { keys.spacePressed = false; } }); // Initialize game initStars(); createBugs(); gameLoop(); </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.