three实现三维开放城市汽车行驶场景代码
代码语言:html
所属分类:其他
代码描述:三维开放城市汽车驾驶碰撞
代码标签: 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">
<title>开放世界城市 - Three.js</title>
<style>
:root {
--bg: #1a1a2e;
--panel-bg: rgba(0, 0, 0, 0.75);
--text: #e0e0e0;
--accent: #4fc3f7;
--danger: #ef5350;
--warning: #ffb74d;
--success: #66bb6a;
--font: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #000;
font-family: var(--font);
overflow: hidden;
height: 100vh;
width: 100vw;
user-select: none;
-webkit-user-select: none;
-webkit-tap-highlight-color: transparent;
}
#gameCanvas {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
}
/* HUD覆盖层 */
#hud {
position: fixed;
z-index: 10;
pointer-events: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* 小地图 */
#minimap-container {
position: absolute;
top: 16px;
right: 16px;
width: 180px;
height: 180px;
border-radius: 50%;
overflow: hidden;
border: 3px solid rgba(255, 255, 255, 0.4);
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
background: rgba(0, 0, 0, 0.6);
pointer-events: auto;
}
#minimap {
width: 100%;
height: 100%;
border-radius: 50%;
}
#minimap-label {
position: absolute;
top: 4px;
left: 50%;
transform: translateX(-50%);
font-size: 0.6rem;
color: #fff;
font-weight: 700;
letter-spacing: 0.08em;
text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
pointer-events: none;
}
/* 速度表 */
#speedometer {
position: absolute;
bottom: 30px;
right: 30px;
background: var(--panel-bg);
border-radius: 16px;
padding: 14px 20px;
color: #fff;
text-align: center;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
pointer-events: auto;
}
#speed-value {
font-size: 2.6rem;
font-weight: 700;
letter-spacing: -0.02em;
line-height: 1;
}
#speed-unit {
font-size: 0.7rem;
color: #aaa;
letter-spacing: 0.05em;
}
#gear-indicator {
font-size: 0.8rem;
font-weight: 600;
margin-top: 2px;
padding: 2px 10px;
border-radius: 10px;
display: inline-block;
}
.gear-forward {
background: rgba(102, 187, 106, 0.4);
color: #66bb6a;
}
.gear-reverse {
background: rgba(239, 83, 80, 0.4);
color: #ef5350;
}
.gear-neutral {
background: rgba(255, 255, 255, 0.2);
color: #ccc;
}
/* 信息面板 */
#info-panel {
position: absolute;
top: 16px;
left: 16px;
background: var(--panel-bg);
border-radius: 12px;
padding: 12px 16px;
color: #fff;
font-size: 0.75rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
pointer-events: auto;
display: flex;
flex-direction: column;
gap: 4px;
}
#info-panel span {
display: flex;
align-items: center;
gap: 6px;
}
.info-dot {
width: 8px;
height: 8px;
border-radius: 50%;
display: inline-block;
flex-shrink: 0;
}
.dot-sun {
background: #ffd54f;
box-shadow: 0 0 8px #ffd54f;
}
.dot-rain {
background: #64b5f6;
box-shadow: 0 0 8px #64b5f6;
}
.dot-fog {
background: #bdbdbd;
box-shadow: 0 0 8px #bdbdbd;
}
/* 控制提示 */
#controls-hint {
position: absolute;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
background: var(--panel-bg);
border-radius: 20px;
padding: 8px 18px;
color: #ccc;
font-size: 0.7rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.15);
pointer-events: auto;
display: flex;
gap: 12px;
flex-wrap: wrap;
justify-content: center;
}
#controls-hint .key {
background: rgba(255, 255, 255, 0.15);
border-radius: 4px;
padding: 2px 7px;
font-weight: 600;
color: #fff;
font-size: 0.65rem;
letter-spacing: 0.04em;
}
/* 天气切换按钮 */
#weather-btns {
position: absolute;
top: 200px;
right: 16px;
display: flex;
flex-direction: column;
gap: 6px;
pointer-events: auto;
z-index: 11;
}
#weather-btns button {
width: 40px;
height: 40px;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.3);
background: rgba(0, 0, 0, 0.5);
color: #fff;
cursor: pointer;
font-size: 1.1rem;
transition: all 0.2s;
ba.........完整代码请登录后点击上方下载按钮下载查看















网友评论0