three实现三维孤岛求生游戏代码
代码语言:html
所属分类:其他
代码由gemini-4-hydrogen ai生成,可能有错误,仅供参考:点击查看提示词
代码描述:three实现三维孤岛求生游戏代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>孤岛余生 · CASTAWAY SURVIVAL</title>
<style>
:root {
--sand: #e8c987;
--grass: #5ca34d;
--ocean: #1e7fa8;
--wood: #8b5a2b;
--fire: #ff7b29;
--night: #0f1829;
--panel: rgba(15, 24, 41, 0.82);
--panel-border: rgba(232, 201, 135, 0.35);
--warn: #e74c3c;
--ok: #2ecc71;
--text: #f6efe0;
--muted: #b8b09c;
}
* { box-sizing: border-box; user-select: none; -webkit-user-select: none; }
html, body {
margin: 0; padding: 0; width: 100%; height: 100%;
overflow: hidden; background: var(--night); color: var(--text);
font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
touch-action: none;
}
#game-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
/* Custom Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(15,24,41,0.5); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: var(--wood); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--sand); }
/* Screen Flash & Vignette */
#damage-flash {
position: fixed; inset: 0; pointer-events: none; z-index: 15;
background: radial-gradient(circle, transparent 45%, rgba(231, 76, 60, 0.65) 100%);
opacity: 0; transition: opacity 0.12s ease-out;
}
#night-vignette {
position: fixed; inset: 0; pointer-events: none; z-index: 5;
background: radial-gradient(circle, transparent 58%, rgba(8, 15, 32, 0.55) 100%);
opacity: 0; transition: opacity 1s ease;
}
/* Floating Damage Text */
#floating-layer {
position: fixed; inset: 0; pointer-events: none; z-index: 18; overflow: hidden;
}
.dmg-float {
position: absolute; font-weight: 800; font-size: 16px;
text-shadow: 0 2px 4px rgba(0,0,0,0.85);
transform: translate(-50%, -50%); white-space: nowrap;
will-change: transform, opacity;
}
/* Crosshair for Aiming */
#crosshair {
position: fixed; left: 50%; top: 50%; width: 22px; height: 22px;
transform: translate(-50%, -50%); pointer-events: none; z-index: 16;
display: none;
}
#crosshair::before, #crosshair::after {
content: ""; position: absolute; background: rgba(255, 240, 200, 0.9);
box-shadow: 0 0 4px rgba(0,0,0,0.8);
}
#crosshair::before { left: 10px; top: 2px; width: 2px; height: 18px; }
#crosshair::after { top: 10px; left: 2px; width: 18px; height: 2px; }
/* HUD Layout */
#hud {
position: fixed; inset: 0; pointer-events: none; z-index: 20;
display: none;
}
.hud-card {
background: var(--panel); border: 1px solid var(--panel-border);
backdrop-filter: blur(6px); border-radius: 10px;
box-shadow: 0 4px 16px rgba(0,0,0,0.4); pointer-events: auto;
}
/* Top Bar */
#hud-top {
position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
display: flex; align-items: center; gap: 10px; padding: 6px 14px;
pointer-events: auto; max-width: calc(100vw - 20px); flex-wrap: wrap; justify-content: center;
}
.day-badge {
font-weight: 800; font-size: 15px; color: var(--sand);
display: flex; align-items: center; gap: 6px;
}
.phase-pill {
padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
background: rgba(232,201,135,0.18); color: var(--sand);
}
.phase-pill.night { background: rgba(30, 127, 168, 0.35); color: #8fd3ff; }
.phase-pill.dusk { background: rgba(255, 123, 41, 0.35); color: #ffb37a; }
#time-bar-wrap {
width: 110px; height: 8px; background: rgba(255,255,255,0.12);
border-radius: 4px; overflow: hidden;
}
#time-bar { height: 100%; width: 0%; background: var(--sand); transition: width 0.2s linear; }
#wave-info { font-size: 12px; color: #ff9c8a; font-weight: 700; display: none; }
.top-btns { display: flex; gap: 6px; }
.icon-btn {
background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.18);
color: var(--text); border-radius: 6px; padding: 4px 8px; cursor: pointer;
font-size: 12px; font-weight: 600; transition: 0.15s;
}
.icon-btn:hover { background: rgba(232,201,135,0.22); border-color: var(--sand); }
/* Top Left Vitals */
#hud-vitals {
position: absolute; top: 10px; left: 10px; padding: 8px 12px;
width: 190px; display: flex; flex-direction: column; gap: 6px;
}
.bar-row { display: flex; flex-direction: column; gap: 2px; }
.bar-label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); font-weight: 600; }
.bar-track {
height: 10px; background: rgba(0,0,0,0.45); border-radius: 5px; overflow: hidden;
border: 1px solid rgba(255,255,255,0.08);
}
.bar-fill { height: 100%; transition: width 0.18s ease; }
#hp-fill { background: linear-gradient(90deg, #c0392b, #e74c3c); }
#hunger-fill { background: linear-gradient(90deg, #d35400, #f39c12); }
#hut-status { font-size: 11px; color: var(--sand); display: flex; justify-content: space-between; }
/* Top Right Resources */
#hud-res {
position: absolute; top: 10px; right: 10px; padding: 8px 12px;
display: grid; grid-template-columns: repeat(3, auto); gap: 6px 12px;
font-size: 13px; font-weight: 700;
}
.res-item { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
/* Center Warnings & Prompts */
#warning-banner {
position: absolute; top: 68px; left: 50%; transform: translateX(-50%);
background: rgba(231, 76, 60, 0.88); color: #fff; padding: 7px 18px;
border-radius: 999px; font-weight: 800; font-size: 14px;
box-shadow: 0 4px 20px rgba(231,76,60,0.5); display: none;
animation: pulseWarn 1.1s infinite ease-in-out; text-align: center;
}
@keyframes pulseWarn {
0%,100% { transform: translateX(-50%) scale(1); }
50% { transform: translateX(-50%) scale(1.04); }
}
#interact-prompt {
position: absolute; bottom: 96px; left: 50%; transform: translateX(-50%);
background: rgba(15, 24, 41, 0.88); border: 1px solid var(--sand);
color: var(--sand); padding: 7px 16px; border-radius: 8px;
font-size: 13px; font-weight: 700; display: none; white-space: nowrap;
pointer-events: auto; cursor: pointer;
}
#fishing-bar-box {
position: absolute; bottom: 142px; left: 50%; transform: translateX(-50%);
background: rgba(15, 24, 41, 0.92); border: 2px solid var(--ocean);
padding: 10px 18px; border-radius: 10px; display: none; text-align: center;
min-width: 220px;
}
#fishing-status { font-size: 14px; font-weight: 800; color: #8fd3ff; margin-bottom: 6px; }
#fishing-progress-wrap { width: 100%; height: 8px; background: rgba(255,255,255,0.12); border-radius: 4px; overflow: hidden; }
#fishing-progress { width: 0%; height: 100%; background: var(--ok); }
/* Structure HP Tooltip */
#target-hp-box {
position: absolute; top: 105px; left: 50%; transform: translateX(-50%);
background: rgba(15,24,41,0.85); border: 1px solid rgba(255,255,255,0.2);
padding: 4px 12px; border-radius: 6px; font-size: 12px; display: none;
min-width: 150px; text-align: center;
}
#target-hp-bar { height: 5px; background: rgba(255,255,255,0.15); border-radius: 3px; margin-top: 3px; overflow: hidden; }
#target-hp-fill { height: 100%; background: var(--ok); width: 100%; }
/* Bottom Hotbar */
#hud-bottom {
position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
display: flex; flex-direction: column; align-items: center; gap: 6px;
max-width: calc(100vw - 16px);
}
#tool-hint {
font-size: 12px; color: var(--sand); background: rgba(15,24,41,0.75);
padding: 3px 10px; border-radius: 999px; border: 1px solid rgba(232,201,135,0.25);
}
#hotbar {
display: flex; gap: 6px; padding: 6px; overflow-x: auto; max-width: 100%;
}
.slot {
width: 56px; height: 56px; border-radius: 8px; flex-shrink: 0;
background: rgba(15,24,41,0.85); border: 2px solid rgba(232,201,135,0.25);
display: flex; flex-direction: column; align-items: center; justify-content: center;
cursor: pointer; position: relative; transition: 0.12s; color: var(--text);
}
.slot:hover { border-color: var(--sand); transform: translateY(-2px); }
.slot.active { border-color: var(--fire); background: rgba(255,123,41,0.2); box-shadow: 0 0 12px rgba(255,123,41,0.35); }
.slot.disabled { opacity: 0.4; }
.slot-key { position: absolute; top: 2px; left: 4px; font-size: 10px; color: var(--muted); font-weight: 700; }
.slot-count { position: absolute; bottom: 2px; right: 4px; font-size: 10px; color: var(--sand); font-weight: 800; }
.slot-ico { font-size: 20px; line-height: 1; }
.slot-name { font-size: 10px; margin-top: 2px; }
/* Build Placement Bar */
#build-place-bar {
position: absolute; bottom: 138px; left: 50%; transform: translateX(-50%);
padding: 8px 14px; display: none; align-items: center; gap: 10px; font-size: 13px;
}
/* Modal / Overlay Panels */
.overlay {
position: fixed; inset: 0; background: rgba(8, 14, 26, 0.78);
backdrop-filter: blur(6px); z-index: 40; display: none;
align-items: center; justify-content: center; padding: 16px;
}
.overlay.open { display: flex; }
.modal {
background: linear-gradient(160deg, rgba(22, 34, 56, 0.96), rgba(13, 21, 36, 0.98));
border: 1px solid var(--panel-border); border-radius: 14px;
max-width: 680px; width: 100%; max-height: 88vh; overflow-y: auto;
padding: 20px 22px; box-shadow: 0 16px 48px rgba(0,0,0,0.65);
}
.modal-header {
display: flex; justify-content: space-between; align-items: center;
border-bottom: 1px solid rgba(232,201,135,0.2); padding-bottom: 10px; margin-bottom: 14px;
}
.modal-title { font-size: 20px; font-weight: 800; color: var(--sand); margin: 0; }
.close-btn {
background: rgba(255,255,255,0.1); border: none; color: var(--text);
width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 16px;
}
.close-btn:hover { background: var(--warn); }
.recipe-grid {
display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px;
}
.recipe-card {
background: rgba(255,255,255,0.04); border: 1px solid rgba(232,201,135,0.2);
border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px;
}
.recipe-head { display: flex; justify-content: space-between; align-items: center; font-weight: 800; color: var(--sand); }
.recipe-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.recipe-cost { font-size: 12px; color: #f6d58e; font-weight: 700; }
.btn-primary {
background: linear-gradient(135deg, var(--fire), #d95d18); color: #fff;
border: none; border-radius: 8px; padding: 8px 14px; font-weight: 800;
cursor: pointer; transition: 0.15s; font-size: 13px;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.6); }
.btn-secondary {
background: rgba(232,201,135,0.15); color: var(--sand);
border: 1px solid rgba(232,201,135,0.35); border-radius: 8px; padding: 8px 14px;
font-weight: 700; cursor: pointer; font-size: 13px;
}
.btn-secondary:hover { background: rgba(232,201,135,0.26); }
/* Title Screen */
#title-screen { z-index: 50; }
.title-logo {
text-align: center; margin-bottom: 14px;
}
.title-logo h1 {
margin: 0; font-size: clamp(26px, 5vw, 38px); color: var(--sand);
text-shadow: 0 3px 16px rgba(255,123,41,0.45); letter-spacing: 2px;
}
.title-logo p { margin: 4px 0 0; color: #8fd3ff; font-size: 13px; letter-spacing: 3px; font-weight: 700; }
.guide-box {
background: rgba(0,0,0,0.28); border-radius: 10px; padding: 12px 14px;
font-size: 12.5px; line-height: 1.65; color: #ddd5c3; margin-bottom: 14px;
border: 1px solid rgba(255,255,255,0.08);
}
.guide-box b { color: var(--sand); }
.diff-row { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.diff-btn {
flex: 1; min-width: 90px; padding: 9px; border-radius: 8px; cursor: pointer;
background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.18);
color: var(--text); font-weight: 700; text-align: center; transition: 0.15s;
}
.diff-btn.selected { border-color: var(--fire); background: rgba(255,123,41,0.25); color: #fff; }
.diff-sub { display: block; font-size: 11px; color: var(--muted); font-weight: 400; margin-top: 2px; }
/* Dawn Banner */
#dawn-banner {
.........完整代码请登录后点击上方下载按钮下载查看















网友评论0