three实现兔子登月攀爬跳跃类游戏代码
代码语言:html
所属分类:游戏
代码描述:three实现兔子登月攀爬跳跃类游戏代码 ,WASD移动,空格跳跃,躲避滚石!不要掉下去!往上爬。
代码标签: three 兔子 登月 攀爬 跳跃类 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>登月攀爬 - 萌兔空格跳跃版</title>
<style>
body { margin: 0; overflow: hidden; background-color: #87CEEB; font-family: "Microsoft YaHei", Arial, sans-serif; }
#instructions {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: rgba(255, 255, 255, 0.9);
color: #333;
cursor: pointer;
z-index: 999;
text-align: center;
user-select: none;
}
h1 { font-size: 3rem; margin-bottom: 10px; color: #000; }
p { font-size: 1.2rem; font-weight: bold; margin: 10px 0;}
.key-highlight {
background: #333;
color: #fff;
padding: 2px 8px;
border-radius: 4px;
font-family: monospace;
}
.danger { color: #ff0000; font-size: 1.4rem; margin-top: 20px; animation: blink 1s infinite; }
#score {
position: absolute;
top: 20px;
left: 20px;
color: #000;
font-size: 24px;
font-weight: bold;
pointer-events: none;
text-shadow: 2px 2px 0px #fff;
}
#fail-msg {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
color: red;
font-weight: bold;
display: none;
text-shadow: 2px 2px 0 white;
text-align: center;
z-index: 1000;
}
@keyframes blink {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
</style>
<script type="importmap">
{
"imports": {
"three": "https://unpkg.com/three@0.160.0/build/three.module.js",
"three/addons/": "https://unpkg.com/three@0.160.0/examples/jsm/",
"cannon-es": "https://unpkg.com/cannon-es@0.20.0/dist/cannon-es.js"
}
}
</script>
</head>
<body>
<div id="instructions">
<h1>萌兔登月 (空格跳跃版)</h1>
<p>点击此处开始游戏</p>
<!-- 修改了这里的提示文字 -->
<p><span class="key-highlight">WASD</span> 移动 | <span class="key-highlight">空格 (Space)</span> 跳跃</p>
<p>🖱️ <b>鼠标左键拖拽</b> 旋转视角 | <b>滚轮</b> 缩放</p>
<p class="danger">躲避滚石!不要掉下去!</p>
</div>
<div id="score">高度: 0m</div>
<div id="fail-msg">兔子晕倒了!<br><span style="font-size: 20px; color: #333">刷新页面或点击重试</span></div>
<script type="module">
import * as THREE from 'three';
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
import * as CANNON from 'cannon-es';
// --- 全局变量 ---
let camera, scene, renderer, controls;
let world, physicsMaterial, playerBody;
let playerMesh; // 兔子的视觉模型
let platforms = [];
l.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0