faça uma versao 3d desse jogo
- User
faça uma versao 3d desse jogo
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
faça uma versao 3d desse jogo
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Que desafio incrível! Criar um Pong 3D psicodélico envolve levar as cores vibrantes, rastros e brilhos para um ambiente tridimensional, o que requer uma biblioteca 3D. A melhor e mais comum para a web é o Three.js.
Vou integrar o Three.js via CDN diretamente no seu HTML para manter tudo em um único arquivo, assim como no exemplo 2D.
Características desta versão 3D:
emissive que os faz brilhar no escuro.Como Rodar:
pong_psicodelico_3d.html.Importante: Como o Three.js é uma biblioteca grande, o código JavaScript será mais extenso do que o da versão 2D.
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pong Psicodélico 3D</title>
<style>
body {
margin: 0;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #000; /* Fundo preto para o brilho */
font-family: 'Courier New', Courier, monospace;
color: white;
position: relative; /* Para posicionar o título e placar */
}
#score-board {
position: absolute;
top: 20px;
width: 100%;
text-align: center;
font-size: 4em;
text-shadow: 0 0 10px rgba(255, 0, 255, 0.8), 0 0 20px rgba(0, 255, 255, 0.8);
z-index: 10; /* Para ficar acima do canvas */
display: flex;
justify-content: space-around;
padding: 0 50px; /* Espaçamento das bordas */
box-sizing: border-box;
}
#score-player, #score-ai {
min-width: 100px; /* Garante que os scores não se sobreponham facilmente */
text-align: center;
}
#titulo {
position: absolute;
bottom: 20px;
font-size: 1.5em;
letter-spacing: 3px;
text-shadow: 0 0 5px rgba(255, 255, 0, 0.5);
z-index: 10;
}
canvas {
display: block; /* Remove o espaço extra abaixo do canvas */
}
</style>
</head>
<body>
<div id="score-board">
<span id="score-player">0</span>
<span id="score-ai">0</span>
</div>
<div id="titulo">PONG PSICODÉLICO 3D</div>
<!-- Incluir a biblioteca Three.js do CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/0.158.0/three.min.js"></script>
<script>
// --- SETUP BÁSICO DO THREE.JS ---
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ antialias: true });
// Configura o tamanho do renderizador para cobrir toda a janela
renderer.setSize(window.innerWidth, window.innerHeight);
// Habilita a transparência do renderizador para o efeito de rastro
renderer.setClearColor(0x000000, 0.1); // Cor preta com 10% de opacidade para o rastro
document.body.appendChild(renderer.domElement);
// Ajusta a câmera
camera.position.z = 70; // Distância da câmera
camera.position.y = 0; // Posição vertical da câmera
camera.lookAt(0, 0, 0); // Foco da câmera no centro da cena
// --- VARIÁVEIS DE JOGO E PSICODELIA ---
const FIELD_WIDTH = 100;
const FIELD_HEIGHT = 60;
const PADDLE_DEPTH = 5;
const PADDLE_WIDTH = 5;
const PADDLE_HEIGHT = 20;
const BALL_RADIUS = 3;
const INITIAL_BALL_SPEED = 0.8; // Velocidade inicial da bola
const MAX_BALL_SPEED = 2.5; // Velocidade máxima da bola
const AI_SPEED = 0.05; // Velocidade de reação da IA
let hue = 0; // Variável para controlar a cor HSL
let ballSpeed = INITIAL_BALL_SPEED;
// Elementos do placar
const playerScoreElement = document.getElementById('score-player');
const aiScoreElement = document.getElementById('score-ai');
// --- GEOMETRIAS E MATERIAIS REUTILIZÁVEIS ---
const paddleGeometry = new THREE.BoxGeometry(PADDLE_WIDTH, PADDLE_HEIGHT, PADDLE_DEPTH);
const ballGeometry = new THREE.SphereGeometry(BALL_RADIUS, 32, 32);
// Materiais para os objetos, usando MeshStandardMaterial para brilho
const playerMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff, emissive: 0xffffff, emissiveIntensity: 1.5 });
const aiMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff, emissive: 0xffffff, emissiveIntensity: 1.5 });
const ballMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff, emissive: 0xffffff, emissiveIntensity: 2.0 }); // Bola brilha mais
// --- OBJETOS DO JOGO 3D ---
// Raquete do Jogador
const playerPaddle = new THREE.Mesh(paddleGeometry, playerMaterial);
playerPaddle.position.x = -FIELD_WIDTH / 2 + PADDLE_WIDTH / 2 + 5; // Posição esquerda
scene.add(playerPaddle);
// Raquete da IA
const aiPaddle = new THREE.Mesh(paddleGeometry, aiMaterial);
aiPaddle.position.x = FIELD_WIDTH / 2 - PADDLE_WIDTH / 2 - 5; // Posição direita
scene.add(aiPaddle);
// Bola
const ball = new THREE.Mesh(ballGeometry, ballMaterial);
scene.add(ball);
// Placar
let playerScore = 0;
let aiScore = 0;
// --- LUZES ---
// Luz ambiente para que as cores dos materiais sejam visíveis
const ambientLight = new THREE.AmbientLight(0x404040, 5); // Cor branca suave, intensidade aumentada para psicodelia
scene.add(ambientLight);
// --- CAMPO DE JOGO (Linhas) ---
const lineMaterial = new THREE.LineBasicMaterial({ color: 0xffffff, linewidth: 2 });
const createLine = (points, color = 0xffffff) => {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({ color: color, linewidth: 2 });
return new THREE.Line(geometry, material);
};
// Linha superior
const topPoints = [new THREE.Vector3(-FIELD_WIDTH / 2, FIELD_HEIGHT / 2, 0), new THREE.Vector3(FIELD_WIDTH / 2, FIELD_HEIGHT / 2, 0)];
const topLine = createLine(topPoints);
scene.add(topLine);
// Linha inferior
const bottomPoints = [new THREE.Vector3(-FIELD_WIDTH / 2, -FIELD_HEIGHT / 2, 0), new THREE.Vector3(FIELD_WIDTH / 2, -FIELD_HEIGHT / 2, 0)];
const bottomLine = createLine(bottomPoints);
scene.add(bottomLine);
// Linha central pontilhada
const dashedLineMaterial = new THREE.LineDashedMaterial({ color: 0xffffff, dashSize: 5, gapSize: 3 });
const centerPoints = [];
for (let i = -FIELD_HEIGHT / 2; i <= FIELD_HEIGHT / 2; i += 8) {
centerPoints.push(new THREE.Vector3(0, i, 0));
centerPoints.push(new THREE.Vector3(0, i + 4, 0));
}
const centerLineGeometry = new THREE.BufferGeometry().setFromPoints(centerPoints);
const centerLine = new THREE.LineSegments(centerLineGeometry, dashedLineMaterial);
centerLine.computeLineDistances(); // Essencial para linhas tracejadas
scene.add(centerLine);
// --- LÓGICA DO JOGO ---
let ballDirection = new THREE.Vector3(
INITIAL_BALL_SPEED * (Math.random() > 0.5 ? 1 : -1),
0,
0
);
function resetBall() {
ball.position.set(0, 0, 0);
ballSpeed = INITIAL_BALL_SPEED;
ballDirection.x = INITIAL_BALL_SPEED * (Math.random() > 0.5 ? 1 : -1);
ballDirection.y = 0;
ballDirection.z = 0;
}
// Função para atualizar a cor psicodélica
function updatePsychedelicColors() {
hue = (hue + 1) % 360; // Incrementa o hue de 1 em 1
// Cores base HSL
const playerColor = new THREE.Color().setHSL(hue / 360, 1, 0.7); // Saturação e Luminosidade alta
const aiColor = new THREE.Color().setHSL((hue + 120) / 360, 1, 0.7); // Diferença de 120 graus para AI
const ballColor = new THREE.Color().setHSL((hue + 240) / 360, 1, 0.8); // Diferença de 240 para bola, mais luminosa
// Aplica as cores aos materiais (e emissive para o brilho)
playerMaterial.color.copy(playerColor);
playerMaterial.emissive.copy(playerColor);
aiMaterial.color.copy(aiColor);
aiMaterial.emissive.copy(aiColor);
ballMaterial.color.copy(ballColor);
ballMaterial.emissive.copy(ballColor);
// Cores para as linhas do campo
const lineColor = new THREE.Color().setHSL((hue + 60) / 360, 0.8, 0.6);
topLine.material.color.copy(lineColor);
bottomLine.material.color.copy(lineColor);
centerLine.material.color.copy(lineColor);
}
function updateGameLogic() {
// Movimento da bola
ball.position.add(ballDirection.clone().normalize().multiplyScalar(ballSpeed));
// Colisão com paredes superior e inferior
if (ball.position.y + BALL_RADIUS > FIELD_HEIGHT / 2 || ball.position.y - BALL_RADIUS < -FIELD_HEIGHT / 2) {
ballDirection.y *= -1;
}
// Lógica da IA (simplificada para seguir a bola)
const aiCenterY = aiPaddle.position.y;
if (ball.position.y > aiCenterY + PADDLE_HEIGHT / 4) { // Ponto de acionamento um pouco acima do centro da raquete da IA
aiPaddle.position.y += AI_SPEED * ballSpeed; // IA se move mais rápido com bola mais rápida
} else if (ball.position.y < aiCenterY - PADDLE_HEIGHT / 4) { // Ponto de acionamento um pouco abaixo
aiPaddle.position.y -= AI_SPEED * ballSpeed;
}
// Limita a raquete da IA
if (aiPaddle.position.y + PADDLE_HEIGHT / 2 > FIELD_HEIGHT / 2) aiPaddle.position.y = FIELD_HEIGHT / 2 - PADDLE_HEIGHT / 2;
if (aiPaddle.position.y - PADDLE_HEIGHT / 2 < -FIELD_HEIGHT / 2) aiPaddle.position.y = -FIELD_HEIGHT / 2 + PADDLE_HEIGHT / 2;
// Colisão com raquetes
const playerCollision = (
ball.position.x - BALL_RADIUS < playerPaddle.position.x + PADDLE_WIDTH / 2 &&
ball.position.x + BALL_RADIUS > playerPaddle.position.x - PADDLE_WIDTH / 2 &&
ball.position.y - BALL_RADIUS < playerPaddle.position.y + PADDLE_HEIGHT / 2 &&
ball.position.y + BALL_RADIUS > playerPaddle.position.y - PADDLE_HEIGHT / 2
);
const aiCollision = (
ball.position.x + BALL_RADIUS > aiPaddle.position.x - PADDLE_WIDTH / 2 &&
ball.position.x - BALL_RADIUS < aiPaddle.position.x + PADDLE_WIDTH / 2 &&
ball.position.y - BALL_RADIUS < aiPaddle.position.y + PADDLE_HEIGHT / 2 &&
ball.position.y + BALL_RADIUS > aiPaddle.position.y - PADDLE_HEIGHT / 2
);
if (playerCollision || aiCollision) {
let paddle = playerCollision ? playerPaddle : aiPaddle;
// Calcula o ponto de colisão na raquete (normalizado de -1 a 1)
let collidePoint = (ball.position.y - paddle.position.y) / (PADDLE_HEIGHT / 2);
// Ângulo de rebote máximo de 45 graus (PI/4 radianos)
let angleRad = (Math.PI / 4) * collidePoint;
// Inverte a direção X e ajusta Y com base no ângulo
ballDirection.x *= -1;
ballDirection.y = Math.sin(angleRad);
ballDirection.z = 0; // Garante que a bola permaneça no plano XY
// Aumenta a velocidade da bola a cada batida
if (ballSpeed < MAX_BALL_SPEED) {
ballSpeed += 0.1;
}
}
// Pontuação
if (ball.position.x - BALL_RADIUS < -FIELD_WIDTH / 2) {
// Ponto para AI
aiScore++;
aiScoreElement.textContent = aiScore;
resetBall();
} else if (ball.position.x + BALL_RADIUS > FIELD_WIDTH / 2) {
// Ponto para o jogador
playerScore++;
playerScoreElement.textContent = playerScore;
resetBall();
}
}
// --- LOOP DE ANIMAÇÃO ---
function animate() {
requestAnimationFrame(animate);
updatePsychedelicColors();
updateGameLogic();
renderer.render(scene, camera);
}
// Inicia a animação
animate();
// --- CONTROLES (Mouse) ---
document.addEventListener('mousemove', (event) => {
// Converte a posição Y do mouse para as coordenadas do mundo Three.js
// O mouse Y vai de 0 (topo) a window.innerHeight (base)
// As coordenadas Y do mundo vão de FIELD_HEIGHT/2 (topo) a -FIELD_HEIGHT/2 (base)
let normalizedMouseY = (event.clientY / window.innerHeight) * 2 - 1; // De -1 (bottom) a 1 (top)
// Inverte para corresponder ao layout do Pong (mouseY alto = raquete alta)
let worldY = -normalizedMouseY * (FIELD_HEIGHT / 2);
// Limita a raquete do jogador para não sair do campo
if (worldY + PADDLE_HEIGHT / 2 > FIELD_HEIGHT / 2) {
playerPaddle.position.y = FIELD_HEIGHT / 2 - PADDLE_HEIGHT / 2;
} else if (worldY - PADDLE_HEIGHT / 2 < -FIELD_HEIGHT / 2) {
playerPaddle.position.y = -FIELD_HEIGHT / 2 + PADDLE_HEIGHT / 2;
} else {
playerPaddle.position.y = worldY;
}
});
// --- RESPONSIVIDADE ---
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
</script>
</body>
</html>