billar / index.html
pruebas2000's picture
Add 2 files
179c2c6 verified
Raw History Blame Contribute Delete
45 kB
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simulador de Billar Tres Bandas - Fuerza Mejorada</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
canvas {
display: block;
margin: 0 auto;
background-color: #1a5c1a;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
border-radius: 2px;
}
.power-meter {
height: 5px;
background: linear-gradient(to right, #4ade80, #f59e0b, #ef4444);
transition: width 0.05s;
box-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
}
.diamond {
width: 6px;
height: 6px;
background-color: white;
position: absolute;
transform: rotate(45deg);
}
.instructions {
background: rgba(0, 0, 0, 0.7);
border-left: 4px solid #3b82f6;
}
.cue-line {
position: absolute;
height: 2px;
background-color: rgba(255, 255, 255, 0.7);
transform-origin: left center;
}
.power-indicator {
position: absolute;
width: 30px;
height: 30px;
background-color: rgba(255, 0, 0, 0.7);
border-radius: 50%;
pointer-events: none;
transform: translate(-50%, -50%);
display: none;
transition: transform 0.1s, opacity 0.2s;
}
.impact-wave {
position: absolute;
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.5);
transform: translate(-50%, -50%);
pointer-events: none;
opacity: 0;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-3px); }
75% { transform: translateX(3px); }
}
.shake-effect {
animation: shake 0.15s linear 3;
}
</style>
</head>
<body class="bg-gray-900 text-white font-sans">
<div class="container mx-auto px-4 py-8">
<div class="flex flex-col lg:flex-row gap-8">
<!-- Juego -->
<div class="flex-1">
<h1 class="text-3xl font-bold mb-6 text-center">Simulador de Billar Tres Bandas <span class="text-yellow-400 animate-pulse">(Fuerza EXTREMA)</span></h1>
<div class="relative">
<canvas id="billiardCanvas" width="800" height="400"></canvas>
<div id="powerIndicator" class="power-indicator"></div>
<div id="impactWave" class="impact-wave"></div>
<!-- Indicador de fuerza mejorado -->
<div class="mt-4">
<div class="flex justify-between mb-1">
<span class="text-sm font-bold">POTENCIA DEL TACO <i class="fas fa-bolt text-yellow-400 ml-1"></i></span>
<span id="powerValue" class="text-sm font-bold">0%</span>
</div>
<div class="w-full bg-gray-700 rounded-full h-3 relative overflow-hidden">
<div id="powerMeter" class="power-meter h-3 rounded-full" style="width: 0%">
<div class="absolute right-0 top-0 h-full w-1 bg-white opacity-70"></div>
</div>
<div class="absolute inset-0 flex items-center">
<div class="w-full h-1 bg-gradient-to-r from-transparent via-white/20 to-transparent"></div>
</div>
</div>
<div class="flex justify-between mt-1 text-xs text-gray-400">
<span>SUAVE</span>
<span class="text-yellow-400 font-bold">M脕XIMA POTENCIA (200%)</span>
</div>
<p class="text-sm text-gray-300 mt-2">
<i class="fas fa-lightbulb text-yellow-400 mr-1"></i> Mant茅n <span class="font-bold">BARRA ESPACIADORA</span> para cargar FUERZA EXTREMA
</p>
</div>
<!-- Contador de bandas -->
<div class="mt-6 bg-gray-800 p-4 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-lg font-semibold mb-2 flex items-center">
<i class="fas fa-wave-square text-blue-400 mr-2"></i> ESTAD脥STICAS
</h3>
<div class="grid grid-cols-2 gap-4">
<div class="bg-gray-700 p-3 rounded">
<div class="text-gray-400">Bandas tocadas:</div>
<div id="cushionCount" class="text-2xl font-bold text-blue-300">0</div>
</div>
<div class="bg-gray-700 p-3 rounded">
<div class="text-gray-400">Golpes:</div>
<div id="shotCount" class="text-2xl font-bold text-green-300">0</div>
</div>
<div class="bg-gray-700 p-3 rounded col-span-2">
<div class="text-gray-400">M谩xima fuerza alcanzada:</div>
<div id="maxPowerAchieved" class="text-xl font-bold text-yellow-300">0%</div>
</div>
</div>
</div>
</div>
</div>
<!-- Instrucciones -->
<div class="lg:w-80">
<div class="instructions p-6 rounded-lg mb-6">
<h2 class="text-xl font-bold mb-4 flex items-center">
<i class="fas fa-info-circle mr-2 text-blue-400"></i> CONTROLES DE FUERZA
</h2>
<ul class="space-y-3 text-gray-300">
<li class="flex items-start">
<div class="bg-blue-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-mouse-pointer text-xs"></i>
</div>
<span>Haz clic y arrastra para apuntar</span>
</li>
<li class="flex items-start">
<div class="bg-yellow-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-keyboard text-xs"></i>
</div>
<span><strong class="text-yellow-300">BARRA ESPACIADORA:</strong> Mant茅n para cargar FUERZA EXTREMA</span>
</li>
<li class="flex items-start">
<div class="bg-red-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-bolt text-xs"></i>
</div>
<span>Suelta para golpear con la potencia acumulada</span>
</li>
<li class="flex items-start">
<div class="bg-green-500 rounded-full w-5 h-5 flex items-center justify-center mr-2 mt-0.5">
<i class="fas fa-redo text-xs"></i>
</div>
<span><strong>R:</strong> Reiniciar posici贸n</span>
</li>
</ul>
</div>
<div class="bg-gray-800 p-6 rounded-lg border border-gray-700 shadow-lg">
<h3 class="text-xl font-bold mb-4 flex items-center">
<i class="fas fa-tachometer-alt mr-2 text-purple-400"></i> SISTEMA DE POTENCIA
</h3>
<div class="space-y-4">
<div class="flex items-start">
<div class="bg-yellow-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
<i class="fas fa-fire text-xs"></i>
</div>
<div>
<h4 class="font-semibold text-yellow-300">NUEVO RANGO DE FUERZA</h4>
<p class="text-sm text-gray-400">Ahora puedes cargar hasta <strong class="text-yellow-300">200%</strong> de potencia normal para golpes extremos.</p>
</div>
</div>
<div class="flex items-start">
<div class="bg-blue-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
<i class="fas fa-chart-line text-xs"></i>
</div>
<div>
<h4 class="font-semibold text-blue-300">CARGA R脕PIDA</h4>
<p class="text-sm text-gray-400">La potencia se acumula m谩s r谩pido al principio y luego gradualmente.</p>
</div>
</div>
<div class="flex items-start">
<div class="bg-red-500 rounded-full w-6 h-6 flex items-center justify-center mr-3 mt-0.5">
<i class="fas fa-eye text-xs"></i>
</div>
<div>
<h4 class="font-semibold text-red-300">EFECTOS VISUALES</h4>
<p class="text-sm text-gray-400">Indicadores de impacto, ondas de choque y vibraci贸n para golpes potentes.</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const canvas = document.getElementById('billiardCanvas');
const ctx = canvas.getContext('2d');
const powerMeter = document.getElementById('powerMeter');
const powerValue = document.getElementById('powerValue');
const cushionCount = document.getElementById('cushionCount');
const shotCount = document.getElementById('shotCount');
const powerIndicator = document.getElementById('powerIndicator');
const impactWave = document.getElementById('impactWave');
const maxPowerAchieved = document.getElementById('maxPowerAchieved');
// Configuraci贸n del juego MEJORADA
const config = {
tableWidth: 800,
tableHeight: 400,
cushionWidth: 20,
ballRadius: 15,
friction: 0.992, // Reducida la fricci贸n para que rueden m谩s
cushionRestitution: 0.75, // Aumentado el rebote en bandas
ballRestitution: 0.95, // Aumentado el rebote entre bolas
basePower: 15, // Potencia base (100%)
maxPower: 30, // Potencia m谩xima (200%)
powerIncrementBase: 0.5, // Incremento base
powerIncrementDecay: 0.02, // Reducci贸n gradual del incremento
maxPowerPercentage: 200, // Permite cargar hasta 200%
minSpeed: 0.05 // Velocidad m铆nima para detener las bolas (reducida)
};
// Estado del juego
const state = {
balls: [
{ x: 200, y: 200, vx: 0, vy: 0, color: 'white', number: 1 }, // Bola jugadora (blanca)
{ x: 500, y: 200, vx: 0, vy: 0, color: 'yellow', number: 2 }, // Bola 2 (amarilla)
{ x: 600, y: 300, vx: 0, vy: 0, color: 'red', number: 3 } // Bola 3 (roja)
],
cue: {
angle: 0,
power: 0,
charging: false,
maxPowerReached: false,
powerIncrement: config.powerIncrementBase,
x: 0,
y: 0
},
cushionsHit: 0,
shotsTaken: 0,
gameStarted: false,
diamonds: [],
maxPowerRecorded: 0
};
// Inicializar diamantes
function initDiamonds() {
const diamondCount = 8; // Diamantes por banda larga
const shortDiamondCount = 4; // Diamantes por banda corta
const offset = 20;
// Bandas largas (superior e inferior)
for (let i = 0; i < diamondCount; i++) {
// Banda superior
state.diamonds.push({
x: offset + (i * (config.tableWidth - 2 * offset) / (diamondCount - 1)),
y: offset
});
// Banda inferior
state.diamonds.push({
x: offset + (i * (config.tableWidth - 2 * offset) / (diamondCount - 1)),
y: config.tableHeight - offset
});
}
// Bandas cortas (izquierda y derecha)
for (let i = 0; i < shortDiamondCount; i++) {
// Banda izquierda
state.diamonds.push({
x: offset,
y: offset + (i * (config.tableHeight - 2 * offset) / (shortDiamondCount - 1))
});
// Banda derecha
state.diamonds.push({
x: config.tableWidth - offset,
y: offset + (i * (config.tableHeight - 2 * offset) / (shortDiamondCount - 1))
});
}
}
// Dibujar mesa de billar
function drawTable() {
// Color del pa帽o con textura
ctx.fillStyle = '#1a5c1a';
ctx.fillRect(0, 0, config.tableWidth, config.tableHeight);
// Crear textura sutil
ctx.fillStyle = 'rgba(0, 0, 0, 0.05)';
for (let i = 0; i < 100; i++) {
const x = Math.random() * config.tableWidth;
const y = Math.random() * config.tableHeight;
const size = Math.random() * 3 + 1;
ctx.fillRect(x, y, size, size);
}
// Bandas (bordes)
ctx.fillStyle = '#5d4037';
// Banda superior
ctx.fillRect(0, 0, config.tableWidth, config.cushionWidth);
// Banda inferior
ctx.fillRect(0, config.tableHeight - config.cushionWidth, config.tableWidth, config.cushionWidth);
// Banda izquierda
ctx.fillRect(0, 0, config.cushionWidth, config.tableHeight);
// Banda derecha
ctx.fillRect(config.tableWidth - config.cushionWidth, 0, config.cushionWidth, config.tableHeight);
// Dibujar diamantes
ctx.fillStyle = 'white';
state.diamonds.forEach(diamond => {
ctx.save();
ctx.translate(diamond.x, diamond.y);
ctx.rotate(Math.PI/4);
ctx.fillRect(-3, -3, 6, 6);
ctx.restore();
});
// Marcas de posici贸n (puntos de inicio)
ctx.fillStyle = 'rgba(255, 255, 255, 0.3)';
// Punto de inicio bola blanca
ctx.beginPath();
ctx.arc(200, 200, 5, 0, Math.PI * 2);
ctx.fill();
// Punto de inicio bola amarilla
ctx.beginPath();
ctx.arc(500, 200, 5, 0, Math.PI * 2);
ctx.fill();
// Punto de inicio bola roja
ctx.beginPath();
ctx.arc(600, 300, 5, 0, Math.PI * 2);
ctx.fill();
}
// Dibujar bolas con sombra y reflejo
function drawBalls() {
state.balls.forEach(ball => {
// Sombra
ctx.beginPath();
ctx.ellipse(ball.x, ball.y + config.ballRadius * 0.4,
config.ballRadius * 0.8, config.ballRadius * 0.3,
0, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(0, 0, 0, 0.3)';
ctx.fill();
// Bola
ctx.beginPath();
ctx.arc(ball.x, ball.y, config.ballRadius, 0, Math.PI * 2);
// Degradado para efecto 3D
const gradient = ctx.createRadialGradient(
ball.x - config.ballRadius * 0.3,
ball.y - config.ballRadius * 0.3,
config.ballRadius * 0.1,
ball.x, ball.y, config.ballRadius);
if (ball.color === 'white') {
gradient.addColorStop(0, '#ffffff');
gradient.addColorStop(1, '#e0e0e0');
} else if (ball.color === 'yellow') {
gradient.addColorStop(0, '#ffff00');
gradient.addColorStop(1, '#ccaa00');
} else { // red
gradient.addColorStop(0, '#ff3333');
gradient.addColorStop(1, '#cc0000');
}
ctx.fillStyle = gradient;
ctx.fill();
ctx.strokeStyle = 'rgba(0, 0, 0, 0.3)';
ctx.stroke();
// Reflejo
ctx.beginPath();
ctx.arc(ball.x + config.ballRadius * 0.3,
ball.y - config.ballRadius * 0.3,
config.ballRadius * 0.2, 0, Math.PI * 2);
ctx.fillStyle = 'rgba(255, 255, 255, 0.4)';
ctx.fill();
// N煤mero de la bola (excepto la blanca)
if (ball.number !== 1) {
ctx.fillStyle = 'white';
ctx.font = 'bold 12px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(ball.number.toString(), ball.x, ball.y);
}
});
}
// Dibujar taco con efecto de fuerza mejorado
function drawCue() {
if (!state.gameStarted || ballsMoving()) return;
const ball = state.balls[0]; // Bola blanca
const cueLength = 150 + (state.cue.power / config.basePower * 50); // El taco se alarga con m谩s fuerza
const endX = ball.x + Math.cos(state.cue.angle) * cueLength;
const endY = ball.y + Math.sin(state.cue.angle) * cueLength;
// Grosor del taco seg煤n la fuerza
const cueWidth = 3 + (state.cue.power / config.basePower * 3);
// Degradado para el taco
const powerRatio = state.cue.power / config.maxPower;
const gradient = ctx.createLinearGradient(ball.x, ball.y, endX, endY);
if (powerRatio < 0.5) {
gradient.addColorStop(0, 'rgba(255, 255, 255, 0.9)');
gradient.addColorStop(1, 'rgba(200, 200, 200, 0.7)');
} else if (powerRatio < 0.8) {
gradient.addColorStop(0, 'rgba(255, 255, 200, 0.9)');
gradient.addColorStop(1, 'rgba(255, 200, 100, 0.7)');
} else {
gradient.addColorStop(0, 'rgba(255, 150, 150, 0.9)');
gradient.addColorStop(1, 'rgba(255, 100, 100, 0.7)');
}
ctx.beginPath();
ctx.moveTo(ball.x, ball.y);
ctx.lineTo(endX, endY);
ctx.lineWidth = cueWidth;
ctx.strokeStyle = gradient;
ctx.stroke();
// Punto de impacto en la bola (m谩s grande con m谩s fuerza)
const impactSize = 3 + (state.cue.power / config.basePower * 5);
const impactX = ball.x + Math.cos(state.cue.angle + Math.PI) * config.ballRadius;
const impactY = ball.y + Math.sin(state.cue.angle + Math.PI) * config.ballRadius;
ctx.beginPath();
ctx.arc(impactX, impactY, impactSize, 0, Math.PI * 2);
// Color del impacto seg煤n la fuerza
if (powerRatio < 0.5) {
ctx.fillStyle = `rgba(255, 255, 255, ${0.7 + powerRatio * 0.3})`;
} else if (powerRatio < 0.8) {
ctx.fillStyle = `rgba(255, 200, 100, ${0.7 + powerRatio * 0.3})`;
} else {
ctx.fillStyle = `rgba(255, 100, 100, ${0.7 + powerRatio * 0.3})`;
}
ctx.fill();
// Mostrar indicador de fuerza cerca del punto de impacto
if (state.cue.charging) {
const indicatorX = impactX + Math.cos(state.cue.angle + Math.PI) * 30;
const indicatorY = impactY + Math.sin(state.cue.angle + Math.PI) * 30;
powerIndicator.style.left = `${indicatorX}px`;
powerIndicator.style.top = `${indicatorY}px`;
powerIndicator.style.display = 'block';
powerIndicator.style.transform = `translate(-50%, -50%) scale(${1 + powerRatio * 1.5})`;
// Color del indicador seg煤n la fuerza
if (powerRatio < 0.5) {
powerIndicator.style.backgroundColor = `rgba(255, 255, 255, ${0.5 + powerRatio * 0.5})`;
} else if (powerRatio < 0.8) {
powerIndicator.style.backgroundColor = `rgba(255, 200, 100, ${0.5 + powerRatio * 0.5})`;
} else {
powerIndicator.style.backgroundColor = `rgba(255, 100, 100, ${0.5 + powerRatio * 0.5})`;
powerIndicator.style.boxShadow = `0 0 15px rgba(255, 50, 50, ${powerRatio})`;
}
} else {
powerIndicator.style.display = 'none';
}
}
// Verificar si las bolas est谩n en movimiento
function ballsMoving() {
return state.balls.some(ball => Math.abs(ball.vx) > config.minSpeed || Math.abs(ball.vy) > config.minSpeed);
}
// Actualizar f铆sica del juego con efectos mejorados
function updatePhysics() {
state.balls.forEach(ball => {
// Aplicar fricci贸n (dependiendo de la velocidad)
const speed = Math.sqrt(ball.vx * ball.vx + ball.vy * ball.vy);
const friction = speed > 5 ? config.friction * 0.995 : config.friction;
ball.vx *= friction;
ball.vy *= friction;
// Detener bolas cuando sean muy lentas
if (Math.abs(ball.vx) < config.minSpeed) ball.vx = 0;
if (Math.abs(ball.vy) < config.minSpeed) ball.vy = 0;
// Actualizar posici贸n
ball.x += ball.vx;
ball.y += ball.vy;
// Detecci贸n de colisi贸n con bandas
// Banda superior
if (ball.y - config.ballRadius < config.cushionWidth) {
ball.y = config.ballRadius + config.cushionWidth;
ball.vy = -ball.vy * config.cushionRestitution;
if (ball.number === 1) {
state.cushionsHit++;
createImpactEffect(ball.x, config.cushionWidth);
}
}
// Banda inferior
if (ball.y + config.ballRadius > config.tableHeight - config.cushionWidth) {
ball.y = config.tableHeight - config.ballRadius - config.cushionWidth;
ball.vy = -ball.vy * config.cushionRestitution;
if (ball.number === 1) {
state.cushionsHit++;
createImpactEffect(ball.x, config.tableHeight - config.cushionWidth);
}
}
// Banda izquierda
if (ball.x - config.ballRadius < config.cushionWidth) {
ball.x = config.ballRadius + config.cushionWidth;
ball.vx = -ball.vx * config.cushionRestitution;
if (ball.number === 1) {
state.cushionsHit++;
createImpactEffect(config.cushionWidth, ball.y);
}
}
// Banda derecha
if (ball.x + config.ballRadius > config.tableWidth - config.cushionWidth) {
ball.x = config.tableWidth - config.ballRadius - config.cushionWidth;
ball.vx = -ball.vx * config.cushionRestitution;
if (ball.number === 1) {
state.cushionsHit++;
createImpactEffect(config.tableWidth - config.cushionWidth, ball.y);
}
}
});
// Detecci贸n de colisi贸n entre bolas con efectos mejorados
for (let i = 0; i < state.balls.length; i++) {
for (let j = i + 1; j < state.balls.length; j++) {
const ball1 = state.balls[i];
const ball2 = state.balls[j];
const dx = ball2.x - ball1.x;
const dy = ball2.y - ball1.y;
const distance = Math.sqrt(dx * dx + dy * dy);
if (distance < config.ballRadius * 2) {
// Colisi贸n detectada
const angle = Math.atan2(dy, dx);
const sin = Math.sin(angle);
const cos = Math.cos(angle);
// Rotar velocidades
const vx1 = ball1.vx * cos + ball1.vy * sin;
const vy1 = ball1.vy * cos - ball1.vx * sin;
const vx2 = ball2.vx * cos + ball2.vy * sin;
const vy2 = ball2.vy * cos - ball2.vx * sin;
// Conservaci贸n del momento con efecto de potencia
const speed1 = Math.sqrt(ball1.vx * ball1.vx + ball1.vy * ball1.vy);
const speed2 = Math.sqrt(ball2.vx * ball2.vx + ball2.vy * ball2.vy);
const restitution = speed1 > 10 || speed2 > 10 ? config.ballRestitution * 0.95 : config.ballRestitution;
const finalVx1 = (restitution * (vx1 - vx2) + vx1 + vx2) / 2;
const finalVx2 = vx1 + vx2 - finalVx1;
// Actualizar velocidades
ball1.vx = finalVx1 * cos - vy1 * sin;
ball1.vy = vy1 * cos + finalVx1 * sin;
ball2.vx = finalVx2 * cos - vy2 * sin;
ball2.vy = vy2 * cos + finalVx2 * sin;
// Separar bolas para evitar superposici贸n
const overlap = config.ballRadius * 2 - distance;
const moveX = overlap * cos * 0.5;
const moveY = overlap * sin * 0.5;
ball1.x -= moveX;
ball1.y -= moveY;
ball2.x += moveX;
ball2.y += moveY;
// Efecto visual de colisi贸n
createBallImpactEffect(ball1.x, ball1.y);
// Verificar si es la bola 1 golpeando a la bola 3
if ((ball1.number === 1 && ball2.number === 3) || (ball1.number === 3 && ball2.number === 1)) {
if (state.cushionsHit >= 3) {
// Carambola v谩lida
setTimeout(() => {
alert(`隆Carambola v谩lida! Tocaste ${state.cushionsHit} bandas antes de golpear la bola 3.`);
resetBalls();
}, 100);
} else if (state.cushionsHit > 0) {
setTimeout(() => {
alert(`Solo tocaste ${state.cushionsHit} bandas. Necesitas tocar 3 bandas antes de golpear la bola 3.`);
resetBalls();
}, 100);
}
}
}
}
}
// Actualizar UI
cushionCount.textContent = state.cushionsHit;
}
// Crear efecto visual de impacto en bandas
function createImpactEffect(x, y) {
const rect = canvas.getBoundingClientRect();
const wave = document.createElement('div');
wave.className = 'impact-wave';
wave.style.left = `${x + rect.left}px`;
wave.style.top = `${y + rect.top}px`;
wave.style.width = '0px';
wave.style.height = '0px';
wave.style.opacity = '0.8';
document.body.appendChild(wave);
// Animaci贸n de la onda
let size = 0;
const grow = () => {
size += 5;
wave.style.width = `${size}px`;
wave.style.height = `${size}px`;
wave.style.opacity = `${0.8 - size/100}`;
if (size < 100) {
requestAnimationFrame(grow);
} else {
wave.remove();
}
};
grow();
}
// Crear efecto visual de colisi贸n entre bolas
function createBallImpactEffect(x, y) {
const rect = canvas.getBoundingClientRect();
const wave = document.createElement('div');
wave.className = 'impact-wave';
wave.style.left = `${x + rect.left}px`;
wave.style.top = `${y + rect.top}px`;
wave.style.width = '0px';
wave.style.height = '0px';
wave.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
document.body.appendChild(wave);
// Animaci贸n de la onda
let size = 0;
const grow = () => {
size += 8;
wave.style.width = `${size}px`;
wave.style.height = `${size}px`;
wave.style.opacity = `${0.7 - size/80}`;
if (size < 80) {
requestAnimationFrame(grow);
} else {
wave.remove();
}
};
grow();
}
// Golpear la bola blanca con efectos mejorados
function hitBall() {
if (ballsMoving()) return;
const ball = state.balls[0]; // Bola blanca
const power = state.cue.power;
// Calcular porcentaje de potencia
const powerPercent = Math.min(
config.maxPowerPercentage,
(power / config.basePower) * 100
);
// Registrar m谩xima potencia si es mayor
if (powerPercent > state.maxPowerRecorded) {
state.maxPowerRecorded = Math.round(powerPercent);
maxPowerAchieved.textContent = `${state.maxPowerRecorded}%`;
// Efecto visual para nuevo r茅cord
if (powerPercent > 150) {
maxPowerAchieved.classList.add('animate-pulse');
setTimeout(() => {
maxPowerAchieved.classList.remove('animate-pulse');
}, 1000);
}
}
// Aplicar fuerza (el 100% es config.basePower)
const actualPower = power > config.basePower ?
config.basePower + (power - config.basePower) * 1.5 :
power;
ball.vx = Math.cos(state.cue.angle) * actualPower;
ball.vy = Math.sin(state.cue.angle) * actualPower;
state.shotsTaken++;
shotCount.textContent = state.shotsTaken;
state.gameStarted = true;
// Efecto visual del golpe
const rect = canvas.getBoundingClientRect();
const impactX = ball.x + Math.cos(state.cue.angle + Math.PI) * config.ballRadius + rect.left;
const impactY = ball.y + Math.sin(state.cue.angle + Math.PI) * config.ballRadius + rect.top;
// Onda de impacto grande
impactWave.style.left = `${impactX}px`;
impactWave.style.top = `${impactY}px`;
impactWave.style.width = '0px';
impactWave.style.height = '0px';
impactWave.style.opacity = '0.8';
// Color seg煤n la potencia
if (powerPercent > 150) {
impactWave.style.backgroundColor = 'rgba(255, 100, 100, 0.7)';
} else if (powerPercent > 80) {
impactWave.style.backgroundColor = 'rgba(255, 200, 100, 0.7)';
} else {
impactWave.style.backgroundColor = 'rgba(255, 255, 255, 0.7)';
}
// Animaci贸n de la onda
let size = 0;
const maxSize = 100 + (powerPercent / 100 * 50);
const grow = () => {
size += 5;
impactWave.style.width = `${size}px`;
impactWave.style.height = `${size}px`;
impactWave.style.opacity = `${0.8 - size/maxSize}`;
if (size < maxSize) {
requestAnimationFrame(grow);
} else {
impactWave.style.opacity = '0';
}
};
grow();
// Efecto de sacudida para golpes potentes
if (powerPercent > 120) {
canvas.classList.add('shake-effect');
setTimeout(() => {
canvas.classList.remove('shake-effect');
}, 500);
}
// Sonido (simulado con cambio visual)
powerIndicator.style.transform = `translate(-50%, -50%) scale(${2 + powerPercent/100})`;
powerIndicator.style.opacity = '0';
setTimeout(() => {
powerIndicator.style.display = 'none';
}, 200);
}
// Reiniciar posici贸n de las bolas
function resetBalls() {
state.balls[0].x = 200;
state.balls[0].y = 200;
state.balls[0].vx = 0;
state.balls[0].vy = 0;
state.balls[1].x = 500;
state.balls[1].y = 200;
state.balls[1].vx = 0;
state.balls[1].vy = 0;
state.balls[2].x = 600;
state.balls[2].y = 300;
state.balls[2].vx = 0;
state.balls[2].vy = 0;
state.cushionsHit = 0;
cushionCount.textContent = '0';
state.cue.power = 0;
powerMeter.style.width = '0%';
powerValue.textContent = '0%';
}
// Cargar fuerza del taco con sistema mejorado
function chargePower() {
if (state.cue.charging && !state.cue.maxPowerReached) {
// Incremento de potencia que disminuye gradualmente
state.cue.power += state.cue.powerIncrement;
state.cue.powerIncrement = Math.max(0.1, state.cue.powerIncrement - config.powerIncrementDecay);
// Calcular porcentaje (permite hasta 200%)
const powerPercent = Math.min(
config.maxPowerPercentage,
(state.cue.power / config.basePower) * 100
);
powerMeter.style.width = (powerPercent / config.maxPowerPercentage * 100) + '%';
powerValue.textContent = Math.round(powerPercent) + '%';
// Cambiar color del texto y la barra seg煤n la fuerza
if (powerPercent > 150) {
powerValue.className = 'text-sm font-bold text-red-400';
powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b, #ef4444, #dc2626)';
} else if (powerPercent > 80) {
powerValue.className = 'text-sm font-bold text-yellow-400';
powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b, #ef4444)';
} else {
powerValue.className = 'text-sm font-bold text-green-400';
powerMeter.style.background = 'linear-gradient(to right, #4ade80, #f59e0b)';
}
// Parpadear cuando se acerca al m谩ximo
if (powerPercent > 180) {
powerValue.classList.toggle('text-red-400');
powerValue.classList.toggle('text-white');
}
if (state.cue.power >= config.maxPower) {
state.cue.maxPowerReached = true;
powerValue.textContent = '200% MAX';
powerValue.className = 'text-sm font-bold text-red-400 animate-pulse';
}
}
}
// Posicionar el canvas correctamente para los efectos
function positionCanvas() {
const rect = canvas.getBoundingClientRect();
powerIndicator.style.position = 'absolute';
powerIndicator.style.left = `${rect.left}px`;
powerIndicator.style.top = `${rect.top}px';
}
// Bucle principal del juego
function gameLoop() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawTable();
drawBalls();
drawCue();
updatePhysics();
requestAnimationFrame(gameLoop);
}
// Inicializar juego
initDiamonds();
positionCanvas();
resetBalls();
setInterval(chargePower, 30); // Intervalo m谩s r谩pido para carga m谩s sensible
// Iniciar bucle del juego
gameLoop();
// Eventos de control
canvas.addEventListener('mousedown', (e) => {
const rect = canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const ball = state.balls[0];
const dx = mouseX - ball.x;
const dy = mouseY - ball.y;
state.cue.angle = Math.atan2(dy, dx) + Math.PI;
state.cue.charging = true;
state.cue.powerIncrement = config.powerIncrementBase;
});
document.addEventListener('keydown', (e) => {
if (e.code === 'Space' && !ballsMoving()) {
state.cue.charging = true;
state.cue.powerIncrement = config.powerIncrementBase;
} else if (e.key.toLowerCase() === 'r') {
resetBalls();
}
});
document.addEventListener('keyup', (e) => {
if (e.code === 'Space' && state.cue.charging) {
state.cue.charging = false;
hitBall();
state.cue.maxPowerReached = false;
}
});
canvas.addEventListener('mouseup', () => {
if (state.cue.charging) {
state.cue.charging = false;
hitBall();
state.cue.maxPowerReached = false;
}
});
canvas.addEventListener('mousemove', (e) => {
if (state.cue.charging) {
const rect = canvas.getBoundingClientRect();
const mouseX = e.clientX - rect.left;
const mouseY = e.clientY - rect.top;
const ball = state.balls[0];
const dx = mouseX - ball.x;
const dy = mouseY - ball.y;
state.cue.angle = Math.atan2(dy, dx) + Math.PI;
}
});
// Reposicionar en redimensionamiento
window.addEventListener('resize', positionCanvas);
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 馃К <a href="https://enzostvs-deepsite.hf.space?remix=pruebas2000/billar" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>