Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-mini-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

vc pode cria um jogo em .html 2d

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Kimikimi-k2-0711-preview’s answer.
  1. User

    vc pode cria um jogo em .html 2d

  2. Assistant

    Claro! Posso criar um exemplo simples de um jogo 2D em HTML usando JavaScript e a tag <canvas>. Vou fazer um joguinho básico onde você controla um quadrado que pode se mover para cima, baixo, esquerda e direita com as setas do teclado.

    Aqui está o código completo:

    <!DOCTYPE html>
    <html lang="pt-BR">
    <head>
      <meta charset="UTF-8" />
      <title>Jogo 2D Simples</title>
      <style>
        body {
          margin: 0;
          background: #222;
          display: flex;
          justify-content: center;
          align-items: center;
          height: 100vh;
          color: white;
          font-family: Arial, sans-serif;
        }
        canvas {
          background: #333;
          display: block;
          border: 2px solid #555;
        }
      </style>
    </head>
    <body>
      <canvas id="game" width="400" height="400"></canvas>
    
      <script>
        const canvas = document.getElementById('game');
        const ctx = canvas.getContext('2d');
    
        const player = {
          x: 180,
          y: 180,
          width: 40,
          height: 40,
          speed: 5,
          color: 'lime'
        };
    
        const keys = {
          ArrowUp: false,
          ArrowDown: false,
          ArrowLeft: false,
          ArrowRight: false
        };
    
        window.addEventListener('keydown', (e) => {
          if (keys.hasOwnProperty(e.key)) {
            keys[e.key] = true;
          }
        });
    
        window.addEventListener('keyup', (e) => {
          if (keys.hasOwnProperty(e.key)) {
            keys[e.key] = false;
          }
        });
    
        function update() {
          if (keys.ArrowUp) player.y -= player.speed;
          if (keys.ArrowDown) player.y += player.speed;
          if (keys.ArrowLeft) player.x -= player.speed;
          if (keys.ArrowRight) player.x += player.speed;
    
          // Limitar o jogador dentro do canvas
          if (player.x < 0) player.x = 0;
          if (player.y < 0) player.y = 0;
          if (player.x + player.width > canvas.width) player.x = canvas.width - player.width;
          if (player.y + player.height > canvas.height) player.y = canvas.height - player.height;
        }
    
        function draw() {
          ctx.clearRect(0, 0, canvas.width, canvas.height);
    
          // Desenhar jogador
          ctx.fillStyle = player.color;
          ctx.fillRect(player.x, player.y, player.width, player.height);
        }
    
        function gameLoop() {
          update();
          draw();
          requestAnimationFrame(gameLoop);
        }
    
        gameLoop();
      </script>
    </body>
    </html>
    

    Como funciona:

    • Um quadrado verde (o jogador) aparece no centro do canvas.
    • Você pode mover o quadrado usando as setas do teclado.
    • O quadrado não sai da área do canvas.

    Se quiser, posso ajudar a adicionar mais funcionalidades, como inimigos, pontuação, ou colisões. Quer?

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