JSFiddle - React, Tailwind, and code Playground
by Sharxxy
JavaScript
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mini 3D Shooter (three.js)</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<style>
html,body { height:100%; margin:0; background:#111; color:#ddd; font-family:Inter,system-ui,Arial; }
#overlay {
position: absolute; left: 12px; top: 12px; z-index: 10;
background: rgba(0,0,0,0.35); padding:8px 12px; border-radius:8px;
backdrop-filter: blur(4px);
}
#overlay div { margin:6px 0; font-size:14px; }
#instructions {
position:absolute; left:50%; top:50%; transform:translate(-50%,-50%);
width:60%; max-width:560px; padding:20px; text-align:center; z-index:20;
background: rgba(0,0,0,0.6); border-radius:12px;
}
canvas { display:block; }
button { padding:8px 12px; border-radius:6px; border: none; background:#2b8; color:#012; cursor:pointer; }
</style>
</head>
<body>
<div id="overlay">
<div>Score: <span id="score">0</span></div>
<div>Health: <span id="health">100</span></div>
<div>Ammo: <span id="ammo">12</span> / <span id="mag">12</span></div>
<div>Enemies: <span id="enemies">0</span></div>
</div>
<div id="instructions">
<h2>Mini 3D Shooter</h2>
<p>WASD to move, mouse to look, click to shoot. Press <strong>Play</strong> to lock pointer.</p>
<p>Reload with <strong>R</strong>. Survive and score high — customise it later!</p>
<button id="startBtn">Play</button>
</div>
<script type="module">
import * as THREE from 'https://cdn.jsdelivr.net/npm/[email protected]/build/three.module.js';
import { PointerLockControls } from 'https://cdn.jsdelivr.net/npm/[email protected]/examples/jsm/controls/PointerLockControls.js';
// --- Basic scene setup ---
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0a0a0a);
const camera = new THREE.PerspectiveCamera(75, innerWidth/innerHeight, 0.1,...