three实现三维帆船海上航行避障游戏代码
代码语言:html
所属分类:游戏
代码描述:three实现三维帆船海上航行避障游戏代码
代码标签: three 三维 帆船 海上 航行 避障 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Pirate Run 3D</title>
<style>
body { margin: 0; overflow: hidden; background-color: #87CEEB; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
/* UI 覆盖层 */
#ui-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
padding: 20px;
box-sizing: border-box;
display: flex;
justify-content: space-between;
}
.hud-item {
font-size: 32px;
font-weight: bold;
color: #fff;
text-shadow: 2px 2px 0 #000;
display: flex;
align-items: center;
gap: 10px;
}
.coin-icon {
width: 30px;
height: 30px;
background: gold;
border-radius: 50%;
border: 2px solid #d4af37;
box-shadow: inset -2px -2px 5px rgba(0,0,0,0.2);
}
.heart { color: #ff3333; }
/* 游戏结束/开始 覆盖层 */
#overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.6);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: white;
pointer-events: auto;
z-index: 10;
}
h1 { font-size: 60px; margin: 0 0 20px 0; text-transform: uppercase; letter-spacing: 5px; }
p { font-size: 20px; margin-bottom: 40px; color: #ddd; }
button {
padding: 15px 40px;
font-size: 24px;
background: #ff9f43;
border: none;
border-radius: 8px;
color: white;
cursor: pointer;
font-weight: bold;
box-shadow: 0 5px #e58e26;
transition: transform 0.1s;
}
button:active { transform: translateY(4px); box-shadow: 0 1px #e58e26; }
button:hover { background: #ffaf40; }
.hidden { display: none !important; }
</style>
</head>
<body>
<!-- UI -->
<div id="ui-layer">
<div class="hud-item">
<div class="coin-icon"></div> <span id="score">0</span>
</div>
<div class="hud-item" id="lives">
<span class="heart">♥</span><span class="heart">♥</span><span class="heart">♥</span>
</div>
</div>
<!-- 菜单 -->
<div id="overlay">
<h1>Captain Run</h1>
<p>按 A / D 或 ← / → 移动,空格键跳跃</p>
<button id="start-btn">开始起航</button>
</div>
<script type="importmap">
{
"imports":{
"three":"//repo.bfw.wiki/bfwrepo/js/module/three/build/164/three.module.js",
"three/addons/":"//repo.bfw.wiki/bfwrepo/js/module/three/examples/164/jsm/"
}
}
</script>
<script type="module">
import * as THREE from 'three';
// --- 游戏配置 ---
const GAME_SPEED_START = 20;
const LANE_WIDTH = 6; // 航道宽度
const SHIP_SPEED = 15; // 左右移动速度
con.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0