Skip to content
The Chat Archive
claude-sonnet-4-20250514· Anthropic LMArena Human Preference 140K

faça um jogo 2d bonito divertido em html solte o codigo em um unico html.index não…

  1. User

    faça um jogo 2d bonito divertido em html solte o codigo em um unico html.index não separe o codigo

  2. Assistant

    Aqui está um jogo 2D completo e divertido em um único arquivo HTML:

    <!DOCTYPE html>
    <html lang="pt-BR">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Space Adventure - Aventura Espacial</title>
        <style>
            body {
                margin: 0;
                padding: 0;
                background: linear-gradient(135deg, #0c0c2e, #1a1a4a);
                display: flex;
                justify-content: center;
                align-items: center;
                min-height: 100vh;
                font-family: 'Arial', sans-serif;
                overflow: hidden;
            }
    
            #gameContainer {
                position: relative;
                border: 3px solid #00ffff;
                border-radius: 10px;
                box-shadow: 0 0 30px #00ffff;
                background: #000;
            }
    
            canvas {
                display: block;
                background: linear-gradient(180deg, #000428, #004e92);
            }
    
            #ui {
                position: absolute;
                top: 10px;
                left: 10px;
                color: #00ffff;
                font-size: 18px;
                font-weight: bold;
                text-shadow: 0 0 10px #00ffff;
            }
    
            #gameOver {
                position: absolute;
                top: 50%;
                left: 50%;
                transform: translate(-50%, -50%);
                color: #ff0066;
                font-size: 32px;
                font-weight: bold;
                text-align: center;
                text-shadow: 0 0 20px #ff0066;
                display: none;
            }
    
            #instructions {
                position: absolute;
                bottom: 10px;
                left: 50%;
                transform: translateX(-50%);
                color: #ffffff;
                font-size: 14px;
                text-align: center;
                opacity: 0.8;
            }
        </style>
    </head>
    <body>
        <div id="gameContainer">
            <canvas id="gameCanvas" width="800" height="600"></canvas>
            <div id="ui">
                <div>Pontos: <span id="score">0</span></div>
                <div>Vidas: <span id="lives">3</span></div>
            </div>
            <div id="gameOver">
                <div>GAME OVER</div>
                <div style="font-size: 18px; margin-top: 10px;">Pressione ESPAÇO para reiniciar</div>
            </div>
            <div id="instructions">
                Use WASD ou setas para mover • ESPAÇO para atirar • Desvie dos asteroides!
            </div>
        </div>
    
        <script>
            const canvas = document.getElementById('gameCanvas');
            const ctx = canvas.getContext('2d');
            const scoreElement = document.getElementById('score');
            const livesElement = document.getElementById('lives');
            const gameOverElement = document.getElementById('gameOver');
    
            // Estado do jogo
            let gameState = 'playing'; // 'playing' ou 'gameOver'
            let score = 0;
            let lives = 3;
    
            // Jogador
            const player = {
                x: canvas.width / 2,
                y: canvas.height - 80,
                width: 40,
                height: 40,
                speed: 5,
                color: '#00ffff'
            };
    
            // Arrays para objetos do jogo
            const bullets = [];
            const asteroids = [];
            const stars = [];
            const particles = [];
    
            // Controles
            const keys = {};
    
            // Inicializar estrelas de fundo
            for (let i = 0; i < 100; i++) {
                stars.push({
                    x: Math.random() * canvas.width,
                    y: Math.random() * canvas.height,
                    size: Math.random() * 2 + 1,
                    speed: Math.random() * 2 + 1
                });
            }
    
            // Event listeners
            document.addEventListener('keydown', (e) => {
                keys[e.key.toLowerCase()] = true;
                if (e.key === ' ') {
                    e.preventDefault();
                    if (gameState === 'playing') {
                        shoot();
                    } else if (gameState === 'gameOver') {
                        restartGame();
                    }
                }
            });
    
            document.addEventListener('keyup', (e) => {
                keys[e.key.toLowerCase()] = false;
            });
    
            // Função para atirar
            function shoot() {
                bullets.push({
                    x: player.x + player.width / 2,
                    y: player.y,
                    width: 4,
                    height: 10,
                    speed: 8,
                    color: '#ffff00'
                });
            }
    
            // Função para criar asteroides
            function createAsteroid() {
                asteroids.push({
                    x: Math.random() * (canvas.width - 40),
                    y: -40,
                    width: 30 + Math.random() * 20,
                    height: 30 + Math.random() * 20,
                    speed: 2 + Math.random() * 3,
                    rotation: 0,
                    rotationSpeed: (Math.random() - 0.5) * 0.2,
                    color: '#ff6600'
                });
            }
    
            // Função para criar partículas de explosão
            function createExplosion(x, y, color) {
                for (let i = 0; i < 10; i++) {
                    particles.push({
                        x: x,
                        y: y,
                        vx: (Math.random() - 0.5) * 10,
                        vy: (Math.random() - 0.5) * 10,
                        life: 30,
                        maxLife: 30,
                        color: color
                    });
                }
            }
    
            // Função para detectar colisão
            function checkCollision(rect1, rect2) {
                return rect1.x < rect2.x + rect2.width &&
                       rect1.x + rect1.width > rect2.x &&
                       rect1.y < rect2.y + rect2.height &&
                       rect1.y + rect1.height > rect2.y;
            }
    
            // Função para desenhar o jogador
            function drawPlayer() {
                ctx.save();
                ctx.translate(player.x + player.width / 2, player.y + player.height / 2);
                
                // Corpo da nave
                ctx.fillStyle = player.color;
                ctx.beginPath();
                ctx.moveTo(0, -player.height / 2);
                ctx.lineTo(-player.width / 3, player.height / 2);
                ctx.lineTo(0, player.height / 3);
                ctx.lineTo(player.width / 3, player.height / 2);
                ctx.closePath();
                ctx.fill();
                
                // Propulsores
                ctx.fillStyle = '#ff4444';
                ctx.fillRect(-8, player.height / 3, 4, 8);
                ctx.fillRect(4, player.height / 3, 4, 8);
                
                ctx.restore();
            }
    
            // Função para desenhar asteroides
            function drawAsteroid(asteroid) {
                ctx.save();
                ctx.translate(asteroid.x + asteroid.width / 2, asteroid.y + asteroid.height / 2);
                ctx.rotate(asteroid.rotation);
                
                ctx.fillStyle = asteroid.color;
                ctx.beginPath();
                const sides = 8;
                for (let i = 0; i < sides; i++) {
                    const angle = (i / sides) * Math.PI * 2;
                    const radius = asteroid.width / 2 * (0.8 + Math.sin(angle * 3) * 0.2);
                    const x = Math.cos(angle) * radius;
                    const y = Math.sin(angle) * radius;
                    if (i === 0) ctx.moveTo(x, y);
                    else ctx.lineTo(x, y);
                }
                ctx.closePath();
                ctx.fill();
                
                ctx.restore();
            }
    
            // Função principal de atualização
            function update() {
                if (gameState !== 'playing') return;
    
                // Movimento do jogador
                if (keys['a'] || keys['arrowleft']) {
                    player.x = Math.max(0, player.x - player.speed);
                }
                if (keys['d'] || keys['arrowright']) {
                    player.x = Math.min(canvas.width - player.width, player.x + player.speed);
                }
                if (keys['w'] || keys['arrowup']) {
                    player.y = Math.max(0, player.y - player.speed);
                }
                if (keys['s'] || keys['arrowdown']) {
                    player.y = Math.min(canvas.height - player.height, player.y + player.speed);
                }
    
                // Atualizar balas
                for (let i = bullets.length - 1; i >= 0; i--) {
                    bullets[i].y -= bullets[i].speed;
                    if (bullets[i].y < 0) {
                        bullets.splice(i, 1);
                    }
                }
    
                // Atualizar asteroides
                for (let i = asteroids.length - 1; i >= 0; i--) {
                    asteroids[i].y += asteroids[i].speed;
                    asteroids[i].rotation += asteroids[i].rotationSpeed;
                    
                    if (asteroids[i].y > canvas.height) {
                        asteroids.splice(i, 1);
                        continue;
                    }
    
                    // Colisão com jogador
                    if (checkCollision(player, asteroids[i])) {
                        createExplosion(asteroids[i].x + asteroids[i].width / 2, 
                                      asteroids[i].y + asteroids[i].height / 2, '#ff0066');
                        asteroids.splice(i, 1);
                        lives--;
                        livesElement.textContent = lives;
                        
                        if (lives <= 0) {
                            gameState = 'gameOver';
                            gameOverElement.style.display = 'block';
                        }
                        continue;
                    }
    
                    // Colisão com balas
                    for (let j = bullets.length - 1; j >= 0; j--) {
                        if (checkCollision(bullets[j], asteroids[i])) {
                            createExplosion(asteroids[i].x + asteroids[i].width / 2, 
                                          asteroids[i].y + asteroids[i].height / 2, '#ffff00');
                            asteroids.splice(i, 1);
                            bullets.splice(j, 1);
                            score += 10;
                            scoreElement.textContent = score;
                            break;
                        }
                    }
                }
    
                // Atualizar partículas
                for (let i = particles.length - 1; i >= 0; i--) {
                    const particle = particles[i];
                    particle.x += particle.vx;
                    particle.y += particle.vy;
                    particle.life--;
                    
                    if (particle.life <= 0) {
                        particles.splice(i, 1);
                    }
                }
    
                // Atualizar estrelas
                stars.forEach(star => {
                    star.y += star.speed;
                    if (star.y > canvas.height) {
                        star.y = 0;
                        star.x = Math.random() * canvas.width;
                    }
                });
    
                // Criar novos asteroides
                if (Math.random() < 0.02 + score * 0.00001) {
                    createAsteroid();
                }
            }
    
            // Função de renderização
            function render() {
                // Limpar canvas
                ctx.clearRect(0, 0, canvas.width, canvas.height);
    
                // Desenhar estrelas
                ctx.fillStyle = '#ffffff';
                stars.forEach(star => {
                    ctx.globalAlpha = 0.8;
                    ctx.fillRect(star.x, star.y, star.size, star.size);
                });
                ctx.globalAlpha = 1;
    
                // Desenhar partículas
                particles.forEach(particle => {
                    ctx.globalAlpha = particle.life / particle.maxLife;
                    ctx.fillStyle = particle.color;
                    ctx.fillRect(particle.x - 2, particle.y - 2, 4, 4);
                });
                ctx.globalAlpha = 1;
    
                if (gameState === 'playing') {
                    // Desenhar jogador
                    drawPlayer();
    
                    // Desenhar balas
                    ctx.fillStyle = '#ffff00';
                    bullets.forEach(bullet => {
                        ctx.fillRect(bullet.x, bullet.y, bullet.width, bullet.height);
                    });
    
                    // Desenhar asteroides
                    asteroids.forEach(drawAsteroid);
                }
            }
    
            // Função para reiniciar o jogo
            function restartGame() {
                gameState = 'playing';
                score = 0;
                lives = 3;
                player.x = canvas.width / 2;
                player.y = canvas.height - 80;
                bullets.length = 0;
                asteroids.length = 0;
                particles.length = 0;
                
                scoreElement.textContent = score;
                livesElement.textContent = lives;
                gameOverElement.style.display = 'none';
            }
    
            // Loop principal do jogo
            function gameLoop() {
                update();
                render();
                requestAnimationFrame(gameLoop);
            }
    
            // Iniciar o jogo
            gameLoop();
        </script>
    </body>
    </html>
    

    Este é um jogo completo de aventura espacial com as seguintes características:

    Gameplay:

    • Controle uma nave espacial com WASD ou setas direcionais
    • Atire com a barra de espaço para destruir asteroides
    • Desvie dos asteroides para não perder vidas
    • Ganhe pontos destruindo asteroides

    Recursos visuais:

    • Gráficos 2D coloridos com gradientes
    • Efeitos de partículas para explosões
    • Estrelas animadas no fundo
    • Interface moderna com brilho neon
    • Animações suaves

    Mecânicas:

    • Sistema de pontuação
    • Sistema de vidas (3 vidas)
    • Dificuldade progressiva (mais asteroides com o tempo)
    • Tela de game over com opção de reiniciar

    O jogo é totalmente funcional e divertido, com controles responsivos e visual atrativo. Salve o código como um arquivo .html e abra no navegador para jogar!

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.