Faça o jogo do dinossauro de quando a internet cai
- User
Faça o jogo do dinossauro de quando a internet cai
Assistant
Vou criar uma versão do jogo do dinossauro do Chrome para você! Este é um jogo completo que você pode jogar no navegador:
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Jogo do Dinossauro</title> <style> body { margin: 0; padding: 20px; display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #f7f7f7; font-family: Arial, sans-serif; } #gameContainer { background-color: white; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.1); padding: 20px; } #gameCanvas { border: 2px solid #333; display: block; background-color: #fff; } #score { text-align: center; font-size: 24px; margin-bottom: 10px; color: #333; } #gameOver { text-align: center; font-size: 20px; color: #666; margin-top: 10px; display: none; } #startMessage { text-align: center; color: #666; margin-top: 10px; } </style> </head> <body> <div id="gameContainer"> <div id="score">Pontuação: 0</div> <canvas id="gameCanvas" width="800" height="200"></canvas> <div id="gameOver">Game Over! Pressione espaço para reiniciar</div> <div id="startMessage">Pressione espaço para começar!</div> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); // Variáveis do jogo let isGameRunning = false; let score = 0; let gameSpeed = 6; // Dinossauro const dino = { x: 50, y: 150, width: 40, height: 50, jumping: false, jumpVelocity: 0, gravity: 0.8 }; // Obstáculos (cactos) let obstacles = []; let obstacleTimer = 0; // Nuvens let clouds = []; // Chão const ground = { y: 150 }; // Função para desenhar o dinossauro function drawDino() { ctx.fillStyle = '#525252'; ctx.fillRect(dino.x, dino.y - dino.height, dino.width, dino.height); // Olho ctx.fillStyle = 'white'; ctx.fillRect(dino.x + 30, dino.y - dino.height + 10, 5, 5); // Pernas ctx.fillStyle = '#525252'; if (Math.floor(score / 5) % 2 === 0) { ctx.fillRect(dino.x + 10, dino.y, 5, 10); ctx.fillRect(dino.x + 25, dino.y, 5, 10); } else { ctx.fillRect(dino.x + 15, dino.y, 5, 10); ctx.fillRect(dino.x + 20, dino.y, 5, 10); } } // Função para desenhar cactos function drawObstacles() { ctx.fillStyle = '#525252'; obstacles.forEach(obstacle => { ctx.fillRect(obstacle.x, ground.y - obstacle.height, obstacle.width, obstacle.height); }); } // Função para desenhar nuvens function drawClouds() { ctx.fillStyle = '#e0e0e0'; clouds.forEach(cloud => { ctx.beginPath(); ctx.arc(cloud.x, cloud.y, 15, 0, Math.PI * 2); ctx.arc(cloud.x + 15, cloud.y, 20, 0, Math.PI * 2); ctx.arc(cloud.x + 30, cloud.y, 15, 0, Math.PI * 2); ctx.fill(); }); } // Função para desenhar o chão function drawGround() { ctx.strokeStyle = '#525252'; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(0, ground.y + 10); ctx.lineTo(canvas.width, ground.y + 10); ctx.stroke(); // Detalhes do chão for (let i = 0; i < canvas.width; i += 20) { if (Math.random() > 0.5) { ctx.fillStyle = '#525252'; ctx.fillRect(i, ground.y + 12, 3, 1); } } } // Função para atualizar o jogo function update() { if (!isGameRunning) return; // Atualizar dinossauro if (dino.jumping) { dino.jumpVelocity += dino.gravity; dino.y += dino.jumpVelocity; if (dino.y >= ground.y) { dino.y = ground.y; dino.jumping = false; dino.jumpVelocity = 0; } } // Criar novos obstáculos obstacleTimer--; if (obstacleTimer <= 0) { obstacles.push({ x: canvas.width, width: 20 + Math.random() * 20, height: 30 + Math.random() * 40 }); obstacleTimer = 60 + Math.random() * 60; } // Criar nuvens if (Math.random() < 0.005) { clouds.push({ x: canvas.width, y: 30 + Math.random() * 50, speed: 1 + Math.random() }); } // Mover obstáculos obstacles = obstacles.filter(obstacle => { obstacle.x -= gameSpeed; return obstacle.x + obstacle.width > 0; }); // Mover nuvens clouds = clouds.filter(cloud => { cloud.x -= cloud.speed; return cloud.x + 50 > 0; }); // Verificar colisões obstacles.forEach(obstacle => { if (dino.x < obstacle.x + obstacle.width && dino.x + dino.width > obstacle.x && dino.y > ground.y - obstacle.height) { gameOver(); } }); // Aumentar pontuação e velocidade score++; if (score % 100 === 0) { gameSpeed += 0.5; } document.getElementById('score').textContent = `Pontuação: ${Math.floor(score / 10)}`; } // Função para desenhar tudo function draw() { // Limpar canvas ctx.clearRect(0, 0, canvas.width, canvas.height); // Desenhar elementos drawClouds(); drawGround(); drawDino(); drawObstacles(); } // Loop do jogo function gameLoop() { update(); draw(); requestAnimationFrame(gameLoop); } // Função para pular function jump() { if (!dino.jumping && isGameRunning) { dino.jumping = true; dino.jumpVelocity = -15; } } // Função para iniciar o jogo function startGame() { isGameRunning = true; score = 0; gameSpeed = 6; obstacles = []; clouds = []; document.getElementById('gameOver').style.display = 'none'; document.getElementById('startMessage').style.display = 'none'; } // Função para game over function gameOver() { isGameRunning = false; document.getElementById('gameOver').style.display = 'block'; } // Controles document.addEventListener('keydown', (e) => { if (e.code === 'Space') { e.preventDefault(); if (!isGameRunning) { startGame(); } else { jump(); } } }); // Controle por toque (mobile) canvas.addEventListener('click', () => { if (!isGameRunning) { startGame(); } else { jump(); } }); // Iniciar o loop do jogo gameLoop(); </script> </body> </html>Este jogo funciona assim:
Como jogar:
- Pressione a barra de espaço (ou clique na tela em dispositivos móveis) para pular
- Evite colidir com os cactos
- A velocidade aumenta gradualmente conforme sua pontuação sobe
- Quando perder, pressione espaço novamente para reiniciar
Características do jogo:
- Dinossauro pixelado que se move as pernas enquanto corre
- Cactos de tamanhos variados como obstáculos
- Nuvens decorativas no fundo
- Sistema de pontuação
- Aumento progressivo da dificuldade
- Visual similar ao jogo original do Chrome
Você pode copiar este código, salvar como um arquivo
.htmle abrir no navegador para jogar. O jogo está completamente funcional e pronto para ser jogado!- User
faça em um arquivo html só
Assistant
Aqui está o jogo completo 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>Jogo do Dinossauro</title> <style> body { margin: 0; padding: 20px; display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: #f7f7f7; font-family: Arial, sans-serif; } #gameContainer { background-color: white; border-radius: 10px; box-shadow: 0 0 20px rgba(0,0,0,0.1); padding: 20px; } #gameCanvas { border: 2px solid #333; display: block; background-color: #fff; } #score { text-align: center; font-size: 24px; margin-bottom: 10px; color: #333; } #gameOver { text-align: center; font-size: 20px; color: #666; margin-top: 10px; display: none; } #startMessage { text-align: center; color: #666; margin-top: 10px; } </style> </head> <body> <div id="gameContainer"> <div id="score">Pontuação: 0</div> <canvas id="gameCanvas" width="800" height="200"></canvas> <div id="gameOver">Game Over! Pressione espaço para reiniciar</div> <div id="startMessage">Pressione espaço para começar!</div> </div> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); // Variáveis do jogo let isGameRunning = false; let score = 0; let gameSpeed = 6; // Dinossauro const dino = { x: 50, y: 150, width: 40, height: 50, jumping: false, jumpVelocity: 0, gravity: 0.8 }; // Obstáculos (cactos) let obstacles = []; let obstacleTimer = 0; // Nuvens let clouds = []; // Chão const ground = { y: 150 }; // Função para desenhar o dinossauro function drawDino() { ctx.fillStyle = '#525252'; ctx.fillRect(dino.x, dino.y - dino.height, dino.width, dino.height); // Olho ctx.fillStyle = 'white'; ctx.fillRect(dino.x + 30, dino.y - dino.height + 10, 5, 5); // Pernas ctx.fillStyle = '#525252'; if (Math.floor(score / 5) % 2 === 0) { ctx.fillRect(dino.x + 10, dino.y, 5, 10); ctx.fillRect(dino.x + 25, dino.y, 5, 10); } else { ctx.fillRect(dino.x + 15, dino.y, 5, 10); ctx.fillRect(dino.x + 20, dino.y, 5, 10); } } // Função para desenhar cactos function drawObstacles() { ctx.fillStyle = '#525252'; obstacles.forEach(obstacle => { ctx.fillRect(obstacle.x, ground.y - obstacle.height, obstacle.width, obstacle.height); }); } // Função para desenhar nuvens function drawClouds() { ctx.fillStyle = '#e0e0e0'; clouds.forEach(cloud => { ctx.beginPath(); ctx.arc(cloud.x, cloud.y, 15, 0, Math.PI * 2); ctx.arc(cloud.x + 15, cloud.y, 20, 0, Math.PI * 2); ctx.arc(cloud.x + 30, cloud.y, 15, 0, Math.PI * 2); ctx.fill(); }); } // Função para desenhar o chão function drawGround() { ctx.strokeStyle = '#525252'; ctx.lineWidth = 2; ctx.beginPath(); ctx.moveTo(0, ground.y + 10); ctx.lineTo(canvas.width, ground.y + 10); ctx.stroke(); // Detalhes do chão for (let i = 0; i < canvas.width; i += 20) { if (Math.random() > 0.5) { ctx.fillStyle = '#525252'; ctx.fillRect(i, ground.y + 12, 3, 1); } } } // Função para atualizar o jogo function update() { if (!isGameRunning) return; // Atualizar dinossauro if (dino.jumping) { dino.jumpVelocity += dino.gravity; dino.y += dino.jumpVelocity; if (dino.y >= ground.y) { dino.y = ground.y; dino.jumping = false; dino.jumpVelocity = 0; } } // Criar novos obstáculos obstacleTimer--; if (obstacleTimer <= 0) { obstacles.push({ x: canvas.width, width: 20 + Math.random() * 20, height: 30 + Math.random() * 40 }); obstacleTimer = 60 + Math.random() * 60; } // Criar nuvens if (Math.random() < 0.005) { clouds.push({ x: canvas.width, y: 30 + Math.random() * 50, speed: 1 + Math.random() }); } // Mover obstáculos obstacles = obstacles.filter(obstacle => { obstacle.x -= gameSpeed; return obstacle.x + obstacle.width > 0; }); // Mover nuvens clouds = clouds.filter(cloud => { cloud.x -= cloud.speed; return cloud.x + 50 > 0; }); // Verificar colisões obstacles.forEach(obstacle => { if (dino.x < obstacle.x + obstacle.width && dino.x + dino.width > obstacle.x && dino.y > ground.y - obstacle.height) { gameOver(); } }); // Aumentar pontuação e velocidade score++; if (score % 100 === 0) { gameSpeed += 0.5; } document.getElementById('score').textContent = `Pontuação: ${Math.floor(score / 10)}`; } // Função para desenhar tudo function draw() { // Limpar canvas ctx.clearRect(0, 0, canvas.width, canvas.height); // Desenhar elementos drawClouds(); drawGround(); drawDino(); drawObstacles(); } // Loop do jogo function gameLoop() { update(); draw(); requestAnimationFrame(gameLoop); } // Função para pular function jump() { if (!dino.jumping && isGameRunning) { dino.jumping = true; dino.jumpVelocity = -15; } } // Função para iniciar o jogo function startGame() { isGameRunning = true; score = 0; gameSpeed = 6; obstacles = []; clouds = []; document.getElementById('gameOver').style.display = 'none'; document.getElementById('startMessage').style.display = 'none'; } // Função para game over function gameOver() { isGameRunning = false; document.getElementById('gameOver').style.display = 'block'; } // Controles document.addEventListener('keydown', (e) => { if (e.code === 'Space') { e.preventDefault(); if (!isGameRunning) { startGame(); } else { jump(); } } }); // Controle por toque (mobile) canvas.addEventListener('click', () => { if (!isGameRunning) { startGame(); } else { jump(); } }); // Iniciar o loop do jogo gameLoop(); </script> </body> </html>Para usar:
- Copie todo o código acima
- Cole em um novo arquivo de texto
- Salve o arquivo com a extensão
.html(exemplo:dinossauro.html) - Abra o arquivo no seu navegador
- Pressione espaço para jogar!
O arquivo contém tudo que você precisa - HTML, CSS e JavaScript - em um único arquivo!
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.