game / index.html
claveryaka's picture
undefined - Initial Deployment
b6f8964 verified
Raw History Blame Contribute Delete
11.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reaction Time Game</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
min-height: 100vh;
overflow: hidden;
}
.target {
transition: transform 0.1s ease-out;
cursor: pointer;
user-select: none;
}
.target:hover {
transform: scale(1.1);
}
.target:active {
transform: scale(0.9);
}
.timer-bar {
transition: width 1s linear;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
.pulse {
animation: pulse 1.5s infinite;
}
</style>
</head>
<body class="flex flex-col items-center justify-center p-4">
<div class="w-full max-w-3xl bg-white rounded-2xl shadow-xl overflow-hidden">
<div class="p-6 bg-indigo-600 text-white">
<h1 class="text-3xl font-bold text-center">⚡ Reaction Time Game</h1>
<p class="text-center text-indigo-100 mt-2">Click the targets as fast as you can!</p>
</div>
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<div class="text-center">
<p class="text-gray-500 text-sm">Time Left</p>
<p id="time" class="text-2xl font-bold">30s</p>
</div>
<div class="text-center">
<p class="text-gray-500 text-sm">Score</p>
<p id="score" class="text-2xl font-bold">0</p>
</div>
<div class="text-center">
<p class="text-gray-500 text-sm">Best</p>
<p id="best-score" class="text-2xl font-bold">0</p>
</div>
</div>
<div class="h-2 bg-gray-200 rounded-full mb-6 overflow-hidden">
<div id="timer-bar" class="h-full bg-indigo-500 timer-bar" style="width: 100%"></div>
</div>
<div id="game-area" class="relative h-96 bg-gray-50 rounded-xl border-2 border-dashed border-gray-300 flex items-center justify-center overflow-hidden">
<div id="start-screen" class="text-center p-6">
<h2 class="text-2xl font-bold mb-4">Ready to test your reflexes?</h2>
<p class="text-gray-600 mb-6">Click the targets as they appear. The faster you click, the more points you get!</p>
<button id="start-btn" class="px-8 py-3 bg-indigo-600 text-white rounded-full font-bold hover:bg-indigo-700 transition-all pulse">
START GAME
</button>
</div>
<div id="end-screen" class="text-center p-6 hidden">
<h2 class="text-2xl font-bold mb-4">Game Over!</h2>
<p class="text-gray-600 mb-2">Your score: <span id="final-score" class="font-bold text-indigo-600">0</span></p>
<p class="text-gray-600 mb-6">Best score: <span id="final-best" class="font-bold text-indigo-600">0</span></p>
<button id="restart-btn" class="px-8 py-3 bg-indigo-600 text-white rounded-full font-bold hover:bg-indigo-700 transition-all">
PLAY AGAIN
</button>
</div>
</div>
</div>
</div>
<audio id="click-sound" src="https://assets.mixkit.co/sfx/preview/mixkit-arcade-game-jump-coin-216.mp3" preload="auto"></audio>
<script>
// Game elements
const gameArea = document.getElementById('game-area');
const startScreen = document.getElementById('start-screen');
const endScreen = document.getElementById('end-screen');
const startBtn = document.getElementById('start-btn');
const restartBtn = document.getElementById('restart-btn');
const timeDisplay = document.getElementById('time');
const scoreDisplay = document.getElementById('score');
const bestScoreDisplay = document.getElementById('best-score');
const finalScoreDisplay = document.getElementById('final-score');
const finalBestDisplay = document.getElementById('final-best');
const timerBar = document.getElementById('timer-bar');
const clickSound = document.getElementById('click-sound');
// Game variables
let score = 0;
let bestScore = localStorage.getItem('bestScore') || 0;
let timeLeft = 30;
let gameInterval;
let timerInterval;
let targetInterval;
let targetSpeed = 1500; // Initial speed (ms between targets)
// Update best score display
bestScoreDisplay.textContent = bestScore;
// Start game
startBtn.addEventListener('click', startGame);
restartBtn.addEventListener('click', startGame);
function startGame() {
// Reset game state
score = 0;
timeLeft = 30;
targetSpeed = 1500;
// Update displays
scoreDisplay.textContent = score;
timeDisplay.textContent = `${timeLeft}s`;
timerBar.style.width = '100%';
// Hide/show appropriate screens
startScreen.classList.add('hidden');
endScreen.classList.add('hidden');
// Clear any existing intervals
clearInterval(gameInterval);
clearInterval(timerInterval);
clearInterval(targetInterval);
// Remove any existing targets
const existingTargets = document.querySelectorAll('.target');
existingTargets.forEach(target => target.remove());
// Start game timer
gameInterval = setInterval(updateGame, 1000);
// Start spawning targets
spawnTarget();
targetInterval = setInterval(spawnTarget, targetSpeed);
}
function updateGame() {
timeLeft--;
timeDisplay.textContent = `${timeLeft}s`;
// Update timer bar
const percentLeft = (timeLeft / 30) * 100;
timerBar.style.width = `${percentLeft}%`;
// Increase difficulty over time
if (timeLeft % 5 === 0 && targetSpeed > 500) {
targetSpeed -= 200;
clearInterval(targetInterval);
targetInterval = setInterval(spawnTarget, targetSpeed);
}
// End game when time runs out
if (timeLeft <= 0) {
endGame();
}
}
function spawnTarget() {
// Remove any existing targets (just in case)
const existingTargets = document.querySelectorAll('.target');
existingTargets.forEach(target => target.remove());
// Create new target
const target = document.createElement('div');
target.className = 'target absolute rounded-full bg-red-500 shadow-lg flex items-center justify-center text-white font-bold';
// Random size between 40px and 80px
const size = Math.floor(Math.random() * 40) + 40;
target.style.width = `${size}px`;
target.style.height = `${size}px`;
// Random position within game area (accounting for target size)
const gameAreaRect = gameArea.getBoundingClientRect();
const maxX = gameAreaRect.width - size;
const maxY = gameAreaRect.height - size;
const x = Math.floor(Math.random() * maxX);
const y = Math.floor(Math.random() * maxY);
target.style.left = `${x}px`;
target.style.top = `${y}px`;
// Add emoji to target (optional)
const emojis = ['🎯', '⭐', '🔴', '🎯', '🎯'];
const randomEmoji = emojis[Math.floor(Math.random() * emojis.length)];
target.textContent = randomEmoji;
// Add click event
target.addEventListener('click', () => {
// Play sound
clickSound.currentTime = 0;
clickSound.play();
// Calculate points based on target size (smaller = more points)
const points = Math.floor(100 - size);
score += points;
scoreDisplay.textContent = score;
// Remove target
target.remove();
// Show points animation
showPointsAnimation(x, y, points);
});
gameArea.appendChild(target);
}
function showPointsAnimation(x, y, points) {
const pointsElement = document.createElement('div');
pointsElement.className = 'absolute text-indigo-600 font-bold animate-bounce';
pointsElement.textContent = `+${points}`;
pointsElement.style.left = `${x}px`;
pointsElement.style.top = `${y - 30}px`;
gameArea.appendChild(pointsElement);
// Remove after animation
setTimeout(() => {
pointsElement.remove();
}, 1000);
}
function endGame() {
clearInterval(gameInterval);
clearInterval(timerInterval);
clearInterval(targetInterval);
// Remove any remaining targets
const existingTargets = document.querySelectorAll('.target');
existingTargets.forEach(target => target.remove());
// Update best score
if (score > bestScore) {
bestScore = score;
localStorage.setItem('bestScore', bestScore);
}
// Update final score displays
finalScoreDisplay.textContent = score;
finalBestDisplay.textContent = bestScore;
bestScoreDisplay.textContent = bestScore;
// Show end screen
endScreen.classList.remove('hidden');
}
</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=claveryaka/game" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>