Make a space combat game where you can pick between different spaceships and fight a bot
- User
Make a space combat game where you can pick between different spaceships and fight a bot
Assistant
I'll create a space combat game for you! This will be a browser-based game with ship selection and bot combat.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Space Combat Arena</title> <style> body { margin: 0; padding: 0; background: #000; color: #fff; font-family: 'Courier New', monospace; overflow: hidden; } #gameCanvas { border: 2px solid #333; background: radial-gradient(circle, #001122 0%, #000000 100%); } #ui { position: absolute; top: 10px; left: 10px; z-index: 10; } #shipSelect { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 20, 40, 0.9); padding: 30px; border: 2px solid #00ffff; border-radius: 10px; text-align: center; } .ship-option { margin: 15px; padding: 15px; border: 1px solid #666; cursor: pointer; transition: all 0.3s; } .ship-option:hover { border-color: #00ffff; background: rgba(0, 255, 255, 0.1); } #gameOver { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.8); padding: 30px; border: 2px solid #ff0000; text-align: center; display: none; } button { background: #003366; color: #fff; border: 1px solid #00ffff; padding: 10px 20px; cursor: pointer; margin: 5px; } button:hover { background: #004488; } </style> </head> <body> <canvas id="gameCanvas" width="800" height="600"></canvas> <div id="ui"> <div>Health: <span id="playerHealth">100</span></div> <div>Bot Health: <span id="botHealth">100</span></div> <div>Score: <span id="score">0</span></div> </div> <div id="shipSelect"> <h2>Choose Your Spaceship</h2> <div class="ship-option" onclick="selectShip('fighter')"> <h3>🚀 Fighter</h3> <p>Fast and agile<br>High speed, medium damage</p> </div> <div class="ship-option" onclick="selectShip('cruiser')"> <h3>🛸 Cruiser</h3> <p>Balanced combat ship<br>Medium speed, medium damage</p> </div> <div class="ship-option" onclick="selectShip('destroyer')"> <h3>🚁 Destroyer</h3> <p>Heavy assault ship<br>Slow but high damage</p> </div> </div> <div id="gameOver"> <h2 id="gameOverText">Game Over</h2> <button onclick="restartGame()">Play Again</button> <button onclick="showShipSelect()">Choose Different Ship</button> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); let gameState = 'shipSelect'; let player, bot, bullets = [], botBullets = []; let keys = {}; let score = 0; let stars = []; // Ship configurations const shipTypes = { fighter: { speed: 5, health: 80, damage: 15, fireRate: 8, size: 15, color: '#00ff00' }, cruiser: { speed: 3, health: 100, damage: 20, fireRate: 6, size: 20, color: '#0088ff' }, destroyer: { speed: 2, health: 150, damage: 30, fireRate: 4, size: 25, color: '#ff4400' } }; // 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, size: Math.random() * 2, speed: Math.random() * 0.5 + 0.1 }); } } function selectShip(type) { const shipConfig = shipTypes[type]; player = { x: 100, y: canvas.height / 2, ...shipConfig, maxHealth: shipConfig.health, lastShot: 0, type: type }; // Create bot with random ship type const botTypes = Object.keys(shipTypes); const botType = botTypes[Math.floor(Math.random() * botTypes.length)]; const botConfig = shipTypes[botType]; bot = { x: canvas.width - 100, y: canvas.height / 2, ...botConfig, maxHealth: botConfig.health, lastShot: 0, type: botType, direction: 1, lastDirectionChange: 0 }; document.getElementById('shipSelect').style.display = 'none'; gameState = 'playing'; initStars(); gameLoop(); } function drawStars() { ctx.fillStyle = '#ffffff'; stars.forEach(star => { ctx.beginPath(); ctx.arc(star.x, star.y, star.size, 0, Math.PI * 2); ctx.fill(); star.x -= star.speed; if (star.x < 0) { star.x = canvas.width; star.y = Math.random() * canvas.height; } }); } function drawShip(ship, isPlayer = true) { ctx.save(); ctx.translate(ship.x, ship.y); // Ship body ctx.fillStyle = ship.color; ctx.beginPath(); if (isPlayer) { ctx.moveTo(ship.size, 0); ctx.lineTo(-ship.size, -ship.size/2); ctx.lineTo(-ship.size/2, 0); ctx.lineTo(-ship.size, ship.size/2); } else { ctx.moveTo(-ship.size, 0); ctx.lineTo(ship.size, -ship.size/2); ctx.lineTo(ship.size/2, 0); ctx.lineTo(ship.size, ship.size/2); } ctx.closePath(); ctx.fill(); // Engine glow ctx.fillStyle = isPlayer ? '#ff6600' : '#6600ff'; ctx.beginPath(); if (isPlayer) { ctx.arc(-ship.size, 0, ship.size/3, 0, Math.PI * 2); } else { ctx.arc(ship.size, 0, ship.size/3, 0, Math.PI * 2); } ctx.fill(); ctx.restore(); // Health bar const barWidth = ship.size * 2; const barHeight = 4; const healthPercent = ship.health / ship.maxHealth; ctx.fillStyle = '#333'; ctx.fillRect(ship.x - barWidth/2, ship.y - ship.size - 10, barWidth, barHeight); ctx.fillStyle = healthPercent > 0.5 ? '#00ff00' : healthPercent > 0.25 ? '#ffff00' : '#ff0000'; ctx.fillRect(ship.x - barWidth/2, ship.y - ship.size - 10, barWidth * healthPercent, barHeight); } function updatePlayer() { if (keys['ArrowUp'] && player.y > player.size) player.y -= player.speed; if (keys['ArrowDown'] && player.y < canvas.height - player.size) player.y += player.speed; if (keys['ArrowLeft'] && player.x > player.size) player.x -= player.speed; if (keys['ArrowRight'] && player.x < canvas.width - player.size) player.x += player.speed; if (keys[' '] && Date.now() - player.lastShot > 1000 / player.fireRate) { bullets.push({ x: player.x + player.size, y: player.y, speed: 8, damage: player.damage }); player.lastShot = Date.now(); } } function updateBot() { const now = Date.now(); // Simple AI movement if (now - bot.lastDirectionChange > 2000) { bot.direction = Math.random() > 0.5 ? 1 : -1; bot.lastDirectionChange = now; } bot.y += bot.direction * bot.speed * 0.5; if (bot.y <= bot.size || bot.y >= canvas.height - bot.size) { bot.direction *= -1; } // Bot shooting if (now - bot.lastShot > 1000 / bot.fireRate) { botBullets.push({ x: bot.x - bot.size, y: bot.y, speed: -6, damage: bot.damage }); bot.lastShot = now; } } function updateBullets() { // Player bullets bullets = bullets.filter(bullet => { bullet.x += bullet.speed; // Check collision with bot const dx = bullet.x - bot.x; const dy = bullet.y - bot.y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < bot.size) { bot.health -= bullet.damage; score += 10; return false; } return bullet.x < canvas.width; }); // Bot bullets botBullets = botBullets.filter(bullet => { bullet.x += bullet.speed; // Check collision with player const dx = bullet.x - player.x; const dy = bullet.y - player.y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance < player.size) { player.health -= bullet.damage; return false; } return bullet.x > 0; }); } function drawBullets() { ctx.fillStyle = '#00ffff'; bullets.forEach(bullet => { ctx.beginPath(); ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2); ctx.fill(); }); ctx.fillStyle = '#ff00ff'; botBullets.forEach(bullet => { ctx.beginPath(); ctx.arc(bullet.x, bullet.y, 3, 0, Math.PI * 2); ctx.fill(); }); } function updateUI() { document.getElementById('playerHealth').textContent = Math.max(0, player.health); document.getElementById('botHealth').textContent = Math.max(0, bot.health); document.getElementById('score').textContent = score; } function checkGameOver() { if (player.health <= 0) { gameState = 'gameOver'; document.getElementById('gameOverText').textContent = 'You Lost!'; document.getElementById('gameOver').style.display = 'block'; } else if (bot.health <= 0) { // Spawn new bot const botTypes = Object.keys(shipTypes); const botType = botTypes[Math.floor(Math.random() * botTypes.length)]; const botConfig = shipTypes[botType]; bot = { x: canvas.width - 100, y: Math.random() * (canvas.height - 200) + 100, ...botConfig, maxHealth: botConfig.health, lastShot: 0, type: botType, direction: 1, lastDirectionChange: 0 }; score += 100; } } function gameLoop() { if (gameState !== 'playing') return; ctx.clearRect(0, 0, canvas.width, canvas.height); drawStars(); updatePlayer(); updateBot(); updateBullets(); drawShip(player, true); drawShip(bot, false); drawBullets(); updateUI(); checkGameOver(); requestAnimationFrame(gameLoop); } function restartGame() { player.health = player.maxHealth; bot.health = bot.maxHealth; bullets = []; botBullets = []; score = 0; gameState = 'playing'; document.getElementById('gameOver').style.display = 'none'; gameLoop(); } function showShipSelect() { gameState = 'shipSelect'; document.getElementById('gameOver').style.display = 'none'; document.getElementById('shipSelect').style.display = 'block'; score = 0; } // Event listeners document.addEventListener('keydown', (e) => { keys[e.key] = true; if (e.key === ' ') e.preventDefault(); }); document.addEventListener('keyup', (e) => { keys[e.key] = false; }); // Initialize initStars(); </script> </body> </html>This space combat game features:
Ship Selection:
- Fighter: Fast and agile with medium damage
- Cruiser: Balanced stats for versatile combat
- Destroyer: Slow but powerful heavy hitter
Gameplay:
- Use arrow keys to move your ship
- Press spacebar to shoot
- Fight against AI bots that spawn with random ship types
- Each destroyed bot spawns a new one and increases your score
- Health bars show damage for both ships
Features:
- Animated starfield background
- Different ship designs and colors
- Collision detection for bullets and ships
- Score tracking
- Game over screen with restart options
- Responsive AI that moves and shoots automatically
The bot AI uses simple movement patterns and shoots at regular intervals based on the ship's fire rate. When you destroy a bot, a new one spawns with a randomly selected ship type, keeping the combat fresh and challenging!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.