build me an html-based web browser fps trainer. it should resemble a shooting range with…
- User
build me an html-based web browser fps trainer. it should resemble a shooting range with a sign that acts as a control panel for changing the speed of the targets, clearing and resetting them, and changing the size. it should maintain total hit count and accuracy. give it a dark and gritty feel like doom.
Assistant
Of course! Here is a complete, self-contained HTML file for a Doom-themed FPS trainer. Just copy the code, save it as an
.htmlfile, and open it in your web browser.Features:
- Doom-inspired Aesthetics: Dark theme, red accents, a gritty feel, and a custom crosshair.
- Interactive Control Panel: A "sign" at the bottom lets you:
- Adjust the speed at which new targets appear.
- Change the size of the targets.
- Reset the score and clear all targets.
- Gameplay Mechanics:
- Targets appear randomly within the shooting range.
- Clicking a target destroys it and counts as a hit.
- Clicking the background counts as a miss.
- A "screen shake" effect happens on a miss for extra feedback.
- A hit marker appears on successful hits.
- Persistent Stats:
- Tracks total hits and total shots fired.
- Calculates and displays your accuracy percentage.
The Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>UAC FPS Training Facility</title> <style> /* --- FONT & ROOT VARIABLES --- */ @import url('https://fonts.googleapis.com/css2?family=Russo+One&display=swap'); :root { --primary-bg: #1a1a1a; --secondary-bg: #0d0d0d; --border-color: #444; --text-color: #e0e0e0; --accent-red: #c00; --accent-red-glow: #ff4444; --accent-orange: #d98d00; } /* --- GENERAL & BODY STYLES --- */ * { box-sizing: border-box; user-select: none; } html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background-color: var(--primary-bg); font-family: 'Russo One', sans-serif; color: var(--text-color); } /* --- GAME CONTAINER & SHOOTING RANGE --- */ #game-container { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; } #shooting-range { width: 95%; height: 80%; max-width: 1200px; background-color: var(--secondary-bg); background-image: radial-gradient(circle at 1px 1px, #333 1px, transparent 0), radial-gradient(circle at 10px 10px, #2a2a2a 1px, transparent 0); background-size: 20px 20px; border: 4px solid var(--border-color); border-bottom: none; position: relative; overflow: hidden; /* The custom crosshair! */ cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" style="font-size:32px;fill:rgb(255,0,0);"><text x="50%" y="50%" dominant-baseline="central" text-anchor="middle">+</text></svg>') 16 16, auto; } @keyframes screenShake { 0% { transform: translate(0, 0); } 25% { transform: translate(-2px, 2px); } 50% { transform: translate(2px, -2px); } 75% { transform: translate(-2px, -2px); } 100% { transform: translate(0, 0); } } .screen-shake { animation: screenShake 0.1s linear; } /* --- CONTROL PANEL SIGN --- */ #control-panel-sign { width: 95%; max-width: 1200px; background: #3a2d1a; background-image: linear-gradient(rgba(0,0,0,0.2) 0%, transparent 100%); border: 4px solid var(--border-color); padding: 15px 20px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; align-items: center; box-shadow: inset 0px 5px 15px rgba(0,0,0,0.5); } .control-group { display: flex; flex-direction: column; align-items: center; justify-content: center; } .control-group label { text-transform: uppercase; letter-spacing: 1px; font-size: 14px; margin-bottom: 8px; color: var(--accent-orange); text-shadow: 1px 1px 2px #000; } /* --- STATS DISPLAY --- */ #stats-panel { text-align: center; font-size: 24px; } #stats-panel span { color: white; margin: 0 5px; } #accuracy-display { color: var(--accent-red-glow); } /* --- SLIDERS & BUTTONS --- */ input[type="range"] { -webkit-appearance: none; width: 80%; height: 8px; background: #111; border: 1px solid #000; border-radius: 5px; outline: none; } input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: var(--accent-red); border: 2px solid #fff; border-radius: 50%; cursor: pointer; box-shadow: 0 0 10px var(--accent-red-glow); } input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: var(--accent-red); border: 2px solid #fff; border-radius: 50%; cursor: pointer; box-shadow: 0 0 10px var(--accent-red-glow); } #reset-button { padding: 10px 20px; background-color: var(--accent-red); border: 2px solid #ff5555; color: white; font-family: 'Russo One', sans-serif; text-transform: uppercase; font-size: 16px; cursor: pointer; transition: all 0.2s ease-in-out; box-shadow: inset 0px 0px 10px rgba(0,0,0,0.5); } #reset-button:hover { background-color: #ff3333; box-shadow: 0 0 15px var(--accent-red-glow); } #reset-button:active { transform: scale(0.95); } /* --- TARGET STYLES --- */ .target { position: absolute; background: radial-gradient(circle, #ff6a00 0%, #ff2a00 40%, #a00 100%); border-radius: 50%; box-shadow: 0 0 15px 5px rgba(255, 0, 0, 0.5); transition: transform 0.1s ease-out; border: 2px solid rgba(255, 255, 255, 0.3); } .target:hover { transform: scale(1.1); box-shadow: 0 0 25px 8px rgba(255, 100, 100, 0.7); } /* --- HIT MARKER --- */ .hit-marker { position: absolute; color: var(--accent-red-glow); font-size: 40px; font-weight: bold; pointer-events: none; animation: fadeOut 0.3s forwards; text-shadow: 0 0 10px var(--accent-red-glow); transform: translate(-50%, -50%); /* Center on cursor */ } @keyframes fadeOut { from { opacity: 1; transform: translate(-50%, -50%) scale(1); } to { opacity: 0; transform: translate(-50%, -50%) scale(1.5); } } </style> </head> <body> <div id="game-container"> <div id="shooting-range"></div> <div id="control-panel-sign"> <div class="control-group"> <label for="speed-slider">Target Spawn Speed</label> <input type="range" id="speed-slider" min="300" max="2000" value="1200" step="100"> </div> <div class="control-group"> <label for="size-slider">Target Size</label> <input type="range" id="size-slider" min="20" max="100" value="50" step="5"> </div> <div class="control-group" id="stats-and-reset"> <div id="stats-panel"> Hits: <span id="hits-display">0</span> | Shots: <span id="shots-display">0</span> | Accuracy: <span id="accuracy-display">0.0%</span> </div> <button id="reset-button">Reset Session</button> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', () => { // DOM Elements const shootingRange = document.getElementById('shooting-range'); const speedSlider = document.getElementById('speed-slider'); const sizeSlider = document.getElementById('size-slider'); const resetButton = document.getElementById('reset-button'); const hitsDisplay = document.getElementById('hits-display'); const shotsDisplay = document.getElementById('shots-display'); const accuracyDisplay = document.getElementById('accuracy-display'); // Game State let hits = 0; let totalShots = 0; let targetSize = parseInt(sizeSlider.value, 10); let spawnInterval = parseInt(speedSlider.value, 10); let spawnTimeoutId = null; // --- FUNCTIONS --- const updateStats = () => { hitsDisplay.textContent = hits; shotsDisplay.textContent = totalShots; const accuracy = totalShots > 0 ? ((hits / totalShots) * 100).toFixed(1) : '0.0'; accuracyDisplay.textContent = `${accuracy}%`; }; const createHitMarker = (x, y) => { const marker = document.createElement('div'); marker.textContent = 'X'; marker.className = 'hit-marker'; marker.style.left = `${x}px`; marker.style.top = `${y}px`; shootingRange.appendChild(marker); setTimeout(() => { marker.remove(); }, 300); // Duration of the fadeOut animation }; const handleHit = (target, event) => { hits++; totalShots++; // Get click position relative to the range const rect = shootingRange.getBoundingClientRect(); const x = event.clientX - rect.left; const y = event.clientY - rect.top; createHitMarker(x, y); target.remove(); updateStats(); // Optional: Play a hit sound // new Audio('path/to/hit-sound.wav').play(); }; const handleMiss = (event) => { // Ensure the click was on the background, not a target if (event.target === shootingRange) { totalShots++; updateStats(); shootingRange.classList.add('screen-shake'); // Remove the class after the animation ends setTimeout(() => shootingRange.classList.remove('screen-shake'), 100); // Optional: Play a miss sound // new Audio('path/to/miss-sound.wav').play(); } }; const spawnTarget = () => { const target = document.createElement('div'); target.className = 'target'; target.style.width = `${targetSize}px`; target.style.height = `${targetSize}px`; const rangeWidth = shootingRange.offsetWidth; const rangeHeight = shootingRange.offsetHeight; // Ensure target spawns fully within the bounds const maxLeft = rangeWidth - targetSize; const maxHeight = rangeHeight - targetSize; target.style.left = `${Math.random() * maxLeft}px`; target.style.top = `${Math.random() * maxHeight}px`; target.addEventListener('mousedown', (e) => handleHit(target, e)); shootingRange.appendChild(target); // Target disappears after a time (related to spawn speed) setTimeout(() => { if (target.parentElement) { target.remove(); } }, spawnInterval * 1.5 + 500); }; const startGame = () => { if (spawnTimeoutId) clearInterval(spawnTimeoutId); // The slider value is inverse to speed, so we reverse it const invertedSpeed = 2300 - spawnInterval; spawnTimeoutId = setInterval(spawnTarget, invertedSpeed); }; const resetGame = () => { hits = 0; totalShots = 0; // Clear all existing targets document.querySelectorAll('.target').forEach(t => t.remove()); updateStats(); startGame(); }; // --- EVENT LISTENERS --- shootingRange.addEventListener('mousedown', handleMiss); speedSlider.addEventListener('input', (e) => { spawnInterval = parseInt(e.target.value, 10); startGame(); // Restart the game loop with the new speed }); sizeSlider.addEventListener('input', (e) => { targetSize = parseInt(e.target.value, 10); }); resetButton.addEventListener('click', resetGame); // --- INITIALIZATION --- updateStats(); startGame(); }); </script> </body> </html>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.