three实现三维驾驶房车露营游戏代码
代码语言:html
所属分类:其他
代码由gemini-4 ai生成,可能有错误,仅供参考:点击查看提示词
代码描述:三维驾驶房车露营游戏
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>荒野星途 - Three.js 3D 房车公路旅行</title>
<style>
:root {
--glass: rgba(14, 19, 26, 0.68);
--border: rgba(255, 255, 255, 0.14);
--accent: #f59e0b;
--accent-warm: #fb923c;
--green: #22c55e;
--blue: #38bdf8;
--red: #ef4444;
--text: #f8fafc;
--dim: #94a3b8;
}
* {
box-sizing: border-box;
user-select: none;
-webkit-user-select: none;
}
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #090d14;
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
color: var(--text);
}
#canvas-container {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
cursor: grab;
}
#canvas-container:active {
cursor: grabbing;
}
/* HUD 界面 */
.hud {
position: fixed;
inset: 0;
pointer-events: none;
padding: 16px 20px;
display: flex;
flex-direction: column;
justify-content: space-between;
z-index: 10;
}
.hud-top {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 16px;
}
.panel {
pointer-events: auto;
background: var(--glass);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
border: 1px solid var(--border);
border-radius: 14px;
padding: 12px 16px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
/* 左上角时间与导航 */
.trip-info {
min-width: 255px;
}
.time-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
}
.time-badge {
display: inline-flex;
align-items: center;
gap: 7px;
font-size: 16px;
font-weight: 700;
letter-spacing: 0.4px;
}
.phase-tag {
font-size: 11px;
padding: 2px 8px;
border-radius: 999px;
background: rgba(245, 158, 11, 0.2);
color: #fcd34d;
border: 1px solid rgba(245, 158, 11, 0.35);
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px 14px;
font-size: 12px;
color: var(--dim);
}
.stats-grid b {
color: var(--text);
font-weight: 600;
}
.camp-radar {
margin-top: 9px;
padding: 7px 10px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.06);
font-size: 12px;
display: flex;
align-items: center;
gap: 7px;
color: #e2e8f0;
transition: all 0.25s;
}
.camp-radar.near {
background: rgba(245, 158, 11, 0.22);
border: 1px solid rgba(251, 146, 60, 0.55);
color: #fde68a;
}
/* 右上角状态条与快捷操作 */
.status-panel {
display: flex;
flex-direction: column;
gap: 10px;
min-width: 265px;
}
.bars {
display: flex;
flex-direction: column;
gap: 7px;
}
.bar-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
}
.bar-label {
width: 44px;
color: var(--dim);
}
.bar-track {
flex: 1;
height: 7px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.1);
overflow: hidden;
}
.bar-fill {
height: 100%;
border-radius: 999px;
transition: width 0.25s;
}
.bar-val {
width: 34px;
text-align: right;
font-variant-numeric: tabular-nums;
font-size: 11px;
}
.quick-actions {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.btn {
pointer-events: auto;
border: 1px solid rgba(255, 255, 255, 0.16);
background: rgba(255, 255, 255, 0.09);
color: var(--text);
font-size: 12px;
font-weight: 600;
padding: 6px 11px;
border-radius: 9px;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: 5px;
transition: all 0.16s;
}
.btn:hover {
background: rgba(255, 255, 255, 0.18);
transform: translateY(-1px);
}
.btn:active {
transform: translateY(0);
}
.btn.active {
background: rgba(245, 158, 11, 0.28);
border-color: rgba(245, 158, 11, 0.7);
color: #fde68a;
}
.btn.camp-ready {
background: linear-gradient(135deg, #ea580c, #f59e0b);
border-color: rgba(255, 255, 255, 0.35);
color: #fff;
box-shadow: 0 0 18px rgba(245, 158, 11, 0.45);
}
.btn.sleep-btn {
background: linear-gradient(135deg, #4f46e5, #7c3aed);
border-color: rgba(255, 255, 255, 0.3);
color: #fff;
}
/* 底部区域 */
.hud-bottom {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 16px;
}
.controls-guide {
font-size: 12px;
line-height: 1.65;
color: #cbd5e1;
max-width: 295px;
}
.controls-guide kbd {
display: inline-block;
padding: 1px 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.14);
border: 1px solid rgba(255, 255, 255, 0.2);
font-family: ui-monospace, monospace;
font-size: 11px;
color: #fff;
}
.center-actions {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.prompt-banner {
padding: 8px 16px;
border-radius: 999px;
background: rgba(15, 23, 42, 0.84);
border: 1px solid rgba(251, 191, 36, 0.5);
color: #fde68a;
font-size: 13px;
font-weight: 600;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
opacity: 0;
transform: translateY(6px);
transition: all 0.22s;
pointer-events: none;
}
.prompt-banner.show {
opacity: 1;
transform: translateY(0);
}
.action-dock {
display: flex;
gap: 8px;
padding: 8px 10px;
border-radius: 14px;
}
/* 车速表 */
.speedo {
min-width: 170px;
text-align: right;
}
.speed-val {
font-size: 34px;
font-weight: 800;
line-height: 1;
font-variant-numeric: tabular-nums;
letter-spacing: -1px;
}
.speed-unit {
font-size: 12px;
color: var(--dim);
margin-left: 3px;
}
.gear-row {
margin-top: 7px;
display: flex;
justify-content: flex-end;
align-items: center;
gap: 8px;
font-size: 12px;
color: var(--dim);
}
.gear-badge {
font-weight: 800;
padding: 2px 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.14);
color: #fff;
}
/* 睡觉/过夜黑屏渐变层 */
.sleep-overlay {
position: fixed;
inset: 0;
background: rgba(4, 7, 15, 0.94);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
z-index: 50;
opacity: 0;
pointer-events: none;
transition: opacity 0.8s ease;
}
.sleep-overlay.active {
opacity: 1;
pointer-events: auto;
}
.sleep-overlay h2 {
margin: 0;
font-size: 24px;
color: #fde68a;
}
.sleep-overlay p {
margin: 0;
color: #cbd5e1;
font-size: 14px;
}
/* 疲劳暗角 */
.drowsy-vignette {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
background: radial-gradient(circle, transparent 48%, rgba(0, 0, 0, 0.85) 100%);
opacity: 0;
transition: opacity 0.4s;
}
</style>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js"
}
}
</script>
</head>
<body>
<div id="canvas-container"></div>
<div class="drowsy-vignette" id="drowsyVignette"></div>
<div class="hud">
<div class="hud-top">
<!-- 左上:旅途时间与营地雷达 -->
<div class="panel trip-info">
<div class="time-row">
<div class="time-badge">
<span id="timeIcon">☀️</span>
<span id="clockText">第 1 天 · 09:00</span>
</div>
<span class="phase-tag" id="phaseTag">清晨出发</span>
</div>
<div .........完整代码请登录后点击上方下载按钮下载查看















网友评论0