three实现三维3a级第一人称射击枪战游戏代码
代码语言:html
所属分类:游戏
代码描述:three实现三维3a级第一人称射击枪战游戏代码,由ai生成
代码标签: three 三维 3a 级 第一 人称 射击 枪战 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>SUBLEVEL 07</title>
<style>
*{box-sizing:border-box;margin:0;padding:0}
html,body{width:100%;height:100%;background:#000;overflow:hidden;color:#e8eef2;
font-family:"DIN Condensed","Avenir Next Condensed","Bahnschrift","Roboto Condensed","Arial Narrow",system-ui,sans-serif;
-webkit-font-smoothing:antialiased;user-select:none;-webkit-user-select:none}
#c{position:fixed;inset:0;width:100%;height:100%;display:block}
.layer{position:fixed;inset:0;pointer-events:none}
#hud{opacity:0;transition:opacity .5s}
#hud.on{opacity:1}
#xh{position:absolute;left:50%;top:50%;width:0;height:0}
#xh i{position:absolute;background:rgba(235,245,250,.92);box-shadow:0 0 2px rgba(0,0,0,.9)}
#xh .d{width:2px;height:2px;left:-1px;top:-1px;border-radius:50%}
#xh .t,#xh .b{width:2px;height:7px;left:-1px}
#xh .l,#xh .r{height:2px;width:7px;top:-1px}
#xh .t{top:calc(-7px - var(--g,6px))}#xh .b{top:var(--g,6px)}#xh .l{left:calc(-7px - var(--g,6px))}#xh .r{left:var(--g,6px)}
#hit{position:absolute;left:50%;top:50%;width:26px;height:26px;margin:-13px 0 0 -13px;opacity:0;transform:rotate(45deg)}
#hit:before,#hit:after{content:"";position:absolute;background:#fff;box-shadow:0 0 3px #000}
#hit:before{left:12px;top:0;width:2px;height:26px;clip-path:polygon(0 0,100% 0,100% 30%,0 30%,0 70%,100% 70%,100% 100%,0 100%)}
#hit:after{top:12px;left:0;height:2px;width:26px;clip-path:polygon(0 0,30% 0,30% 100%,0 100%,0 0,70% 0,100% 0,100% 100%,70% 100%,70% 0)}
#hit.kill:before,#hit.kill:after{background:#ff4a3a}
.panel{position:absolute;bottom:38px;display:flex;align-items:flex-end;gap:14px;text-shadow:0 1px 6px rgba(0,0,0,.8)}
#hp{left:46px}
#am{right:46px;text-align:right;flex-direction:row-reverse}
.big{font-size:64px;line-height:.82;font-weight:700;letter-spacing:1px}
.sm{font-size:17px;letter-spacing:3px;opacity:.72;line-height:1.25}
.bar{width:210px;height:5px;background:rgba(255,255,255,.14);margin-top:7px;position:relative;overflow:hidden}
.bar b{position:absolute;left:0;top:0;bottom:0;width:100%;background:#e8eef2;transition:width .15s}
#hp.low .big,#hp.low .bar b{color:#ff5a48;background-color:#ff5a48}#hp.low .big{background:none}
#am.low #amn{color:#ff5a48}
#top{position:absolute;top:26px;left:0;right:0;text-align:center;font-size:17px;letter-spacing:5px;opacity:.8;text-shadow:0 1px 6px #000}
#top b{font-weight:700;color:#fff}
#pips{display:inline-flex;gap:5px;margin-left:12px;vertical-align:middle}
#pips i{width:9px;height:9px;border:1px solid rgba(255,255,255,.7);transform:rotate(45deg)}
#pips i.x{background:#ff4a3a;border-color:#ff4a3a}
#banner{position:absolute;top:24%;left:0;right:0;text-align:center;opacity:0;transition:opacity .6s}
#banner h2{font-size:54px;letter-spacing:16px;font-weight:700;text-shadow:0 2px 18px #000}
#banner p{font-size:17px;letter-spacing:7px;opacity:.75;margin-top:4px}
#feed{position:absolute;right:46px;top:90px;text-align:right;font-size:17px;letter-spacing:3px}
#feed div{opacity:0;animation:fd 2.4s ease-out forwards}
@keyframes fd{0%{opacity:0;transform:translateX(12px)}10%{opacity:1;transform:none}75%{opacity:1}100%{opacity:0}}
#dmg{position:absolute;left:50%;top:50%;width:0;height:0}
#dmg i{position:absolute;left:-70px;top:-170px;width:140px;height:26px;border-top:5px solid #ff3a2a;border-radius:50%/100% 100% 0 0;
transform-origin:70px 170px;opacity:0;filter:blur(1px) drop-shadow(0 0 6px #ff2a1a)}
#hint{position:absolute;bottom:128px;left:0;right:0;text-align:center;font-size:17px;letter-spacing:4px;opacity:0;transition:opacity .3s;color:#ffd9a0}
#menu,#load{position:fixed;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;
background:radial-gradient(ellipse at center,rgba(4,7,10,.35) 0%,rgba(2,3,5,.9) 100%);transition:opacity .5s}
#load{background:#030507;z-index:5}
#load p{letter-spacing:8px;font-size:17px;opacity:.7}
#load .lb{width:240px;height:2px;background:#1a2228;margin-top:16px;overflow:hidden}
#load .lb b{display:block;height:100%;width:40%;background:#cfe6f2;animation:ld 1.1s infinite ease-in-out}
@keyframes ld{0%{transform:translateX(-100%)}100%{transform:translateX(260%)}}
#menu h1{font-size:112px;letter-spacing:22px;font-weight:700;line-height:.9;text-shadow:0 4px 40px rgba(0,0,0,.9);margin-left:22px}
#menu h1 span{color:#ff6a3c}
#menu .sub{font-size:19px;letter-spacing:11px;opacity:.7;margin:12px 0 44px}
#menu .go{pointer-events:auto;cursor:pointer;font:inherit;font-size:24px;letter-spacing:9px;color:#06090b;background:#e8eef2;border:0;padding:15px 44px 11px;font-weight:700;transition:background .15s,transform .15s}
#menu .go:hover{background:#ff8a4c;transform:scale(1.03)}
#menu .keys{margin-top:40px;font-size:15px;letter-spacing:3px;opacity:.62;line-height:2}
#menu .keys b{display:inline-block;border:1px solid rgba(255,255,255,.5);padding:1px 8px 0;margin:0 3px 0 12px;font-weight:400}
#menu .stat{font-size:21px;letter-spacing:6px;margin-bottom:30px;opacity:.9;white-space:pre-wrap;line-height:1.7}
#q{position:absolute;left:46px;top:26px;font-size:13px;letter-spacing:3px;opacity:.45}
.hide{opacity:0!important;pointer-events:none!important}
.hide *{pointer-events:none!important}
</style>
<script type="importmap">{"imports":{"three":"https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js","three/addons/":"https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"}}</script>
</head>
<body>
<canvas id="c"></canvas>
<div id="hud" class="layer">
<div id="q"></div>
<div id="top"><span id="wv">WAVE 1 / 3</span><span id="pips"></span></div>
<div id="feed"></div>
<div id="banner"><h2></h2><p></p></div>
<div id="xh"><i class="d"></i><i class="t"></i><i class="b"></i><i class="l"></i><i class="r"></i></div>
<div id="hit"></div>
<div id="dmg"></div>
<div id="hint"></div>
<div id="hp" class="panel"><div class="big" id="hpn">100</div><div><div class="sm">VITALS</div><div class="bar"><b id="hpb"></b></div></div></div>
<div id="am" class="panel"><div class="big" id="amn">30</div><div><div class="sm"><span id="amr">180</span> RES</div><div class="sm">VK-9 CARBINE</div></div></div>
</div>
<div id="menu" class="hide">
<h1 id="mt">SUBLEVEL <span>07</span></h1>
<div class="sub" id="ms">CONTAINMENT BREACH / COOLANT SUBSTATION</div>
<div class="stat" id="mstat" style="display:none"></div>
<button class="go" id="go">ENTER</button>
<div class="keys"><b>W A S D</b>MOVE<b>MOUSE</b>AIM<b>LMB</b>FIRE<b>RMB</b>SIGHTS<b>R</b>RELOAD<br><b>SHIFT</b>SPRINT<b>SPACE</b>JUMP<b>G</b>GRAPHICS<b>M</b>MUTE<b>ESC</b>PAUSE</div>
</div>
<div id="load"><p id="lt">BUILDING SUBLEVEL 07</p><div class="lb"><b></b></div></div>
<script type="module">
import * as THREE from 'three';
import { EffectComposer } from 'three/addons/postprocessing/EffectComposer.js';
import { UnrealBloomPass } from 'three/addons/postprocessing/UnrealBloomPass.js';
import { GTAOPass } from 'three/addons/postprocessing/GTAOPass.js';
import { OutputPass } from 'three/addons/postprocessing/OutputPass.js';
import { ShaderPass } from 'three/addons/postprocessing/ShaderPass.js';
import { Pass, FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
import { RoundedBoxGeometry } from 'three/addons/geometries/RoundedBoxGeometry.js';
import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
const $ = id => document.getElementById(id);
const URLP = new URLSearchParams(location.search);
await new Promise(r => setTimeout(r, 40));
/* ───────────────────────── utils ───────────────────────── */
const V3 = THREE.Vector3, PI = Math.PI, TAU = PI * 2;
const clamp = (x, a, b) => x < a ? a : x > b ? b : x;
const lerp = (a, b, t) => a + (b - a) * t;
const sstep = (a, b, x) => { const t = clamp((x - a) / (b - a), 0, 1); return t * t * (3 - 2 * t); };
const damp = (a, b, k, dt) => lerp(a, b, 1 - Math.exp(-k * dt));
function mulberry(a) { return () => { a |= 0; a = a + 0x6D2B79F5 | 0; let t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; }
const R = mulberry(20261110);
const rr = (a, b) => a + (b - a) * R();
const PERM = new Uint8Array(512), VAL = new Float32Array(256);
{ const r = mulberry(7); for (let i = 0; i < 256; i++) { PERM[i] = i; VAL[i] = r(); }
for (let i = 255; i > 0; i--) { const j = (r() * (i + 1)) | 0; const t = PERM[i]; PERM[i] = PERM[j]; PERM[j] = t; }
for (let i = 0; i < 256; i++) PERM[i + 256] = PERM[i]; }
function vn(x, y, px, py, s) {
const xi = Math.floor(x), yi = Math.floor(y), fx = x - xi, fy = y - yi;
const x0 = ((xi % px) + px) % px, x1 = (x0 + 1) % px, y0 = ((yi % py) + py) % py, y1 = (y0 + 1) % py;
const u = fx * fx * (3 - 2 * fx), v = fy * fy * (3 - 2 * fy);
const a = VAL[PERM[(PERM[x0 & 255] + y0 + s) & 255]], b = VAL[PERM[(PERM[x1 & 255] + y0 + s) & 255]];
const c = VAL[PERM[(PERM[x0 & 255] + y1 + s) & 255]], d = VAL[PERM[(PERM[x1 & 255] + y1 + s) & 255]];
return a + (b - a) * u + (c - a) * v + (a - b - c + d) * u * v;
}
function fbm(u, v, oct, px, py, s = 0) {
let a = .5, sum = 0, n = 0;
for (let i = 0; i < oct; i++) { sum += a * vn(u * px, v * py, px, py, s + i * 19); n += a; a *= .5; px *= 2; py *= 2; if (px > 256 || py > 256) break; }
return sum / n;
}
/* ───────────────────────── renderer ───────────────────────── */
const canvas = $('c');
const renderer = new THREE.WebGLRenderer({ canvas, antialias: false, powerPreference: 'high-performance', stencil: false });
const gl = renderer.getContext();
const dbgInfo = gl.getExtension('WEBGL_debug_renderer_info');
const GPU = dbgInfo ? gl.getParameter(dbgInfo.UNMASKED_RENDERER_WEBGL) : gl.getParameter(gl.RENDERER);
const SOFT = /swiftshader|llvmpipe|software/i.test(GPU);
const prFor = () => URLP.has('pr') ? parseFloat(URLP.get('pr')) : Math.min(window.devicePixelRatio || 1, 1.5, Math.max(.75, Math.sqrt(2.9e6 / (innerWidth * innerHeight))));
let PR = prFor();
renderer.setPixelRatio(PR);
renderer.setSize(innerWidth, innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap;
renderer.shadowMap.autoUpdate = false;
const MAXA = Math.min(8, renderer.capabilities.getMaxAnisotropy());
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x05080b);
scene.fog = new THREE.FogExp2(0x0a1016, 0.017);
const camera = new THREE.PerspectiveCamera(74, innerWidth / innerHeight, 0.03, 90);
camera.rotation.order = 'YXZ';
camera.layers.enable(1);
scene.add(camera);
/* ───────────────────────── procedural textures ───────────────────────── */
function mkCanvas(w, h) { const c = document.createElement('canvas'); c.width = w; c.height = h; return c; }
function texFrom(c, srgb, repeat = true) {
const t = new THREE.CanvasTexture(c);
if (srgb) t.colorSpace = THREE.SRGBColorSpace;
if (repeat) t.wrapS = t.wrapT = THREE.RepeatWrapping;
t.anisotropy = MAXA; return t;
}
function pbr(N, fn, ns = 2) {
const H = new Float32Array(N * N), ca = mkCanvas(N, N), co = mkCanvas(N, N), cn = mkCanvas(N, N);
const xa = ca.getContext('2d'), xo = co.getContext('2d'), xn = cn.getContext('2d');
const ia = xa.createImageData(N, N), io = xo.createImageData(N, N), im = xn.createImageData(N, N);
const o = { h: .5, r: .5, g: .5, b: .5, rough: .5, metal: 0 };
for (let y = 0, i = 0; y < N; y++) for (let x = 0; x < N; x++, i++) {
fn(x / N, y / N, o, x, y); H[i] = o.h; const j = i * 4;
ia.data[j] = o.r * 255; ia.data[j + 1] = o.g * 255; ia.data[j + 2] = o.b * 255; ia.data[j + 3] = 255;
io.data[j] = 255; io.data[j + 1] = o.rough * 255; io.data[j + 2] = o.metal * 255; io.data[j + 3] = 255;
}
const k = ns * N / 256;
for (let y = 0, i = 0; y < N; y++) for (let x = 0; x < N; x++, i++) {
const xl = (x + N - 1) % N, xr = (x + 1) % N, yu = (y + N - 1) % N, yd = (y + 1) % N;
let nx = -(H[y * N + xr] - H[y * N + xl]) * k, ny = (H[yd * N + x] - H[yu * N + x]) * k;
.........完整代码请登录后点击上方下载按钮下载查看















网友评论0