three三维学校场景操控角色走路驾驶汽车与其他人互动代码

代码语言:html

所属分类:三维

代码描述:three三维学校场景操控角色走路驾驶汽车与其他人互动代码

代码标签: 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>3D校园探索</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; background: #000; font-family: 'Microsoft YaHei', sans-serif; }
canvas { display: block; }

#ui-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

#minimap {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 200px;
    height: 200px;
    background: rgba(0,0,0,0.6);
    border: 2px solid #4fc3f7;
    border-radius: 10px;
    pointer-events: auto;
}

#info-panel {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 15px 30px;
    border-radius: 12px;
    border: 1px solid #4fc3f7;
    font-size: 16px;
    text-align: center;
    transition: opacity 0.3s;
    backdrop-filter: blur(10px);
}

#controls-help {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(0,0,0,0.75);
    color: #fff;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #4fc3f7;
    font-size: 13px;
    line-height: 1.8;
    backdrop-filter: blur(10px);
    pointer-events: auto;
}

#location-name {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(79,195,247,0.8), rgba(33,150,243,0.8));
    color: #fff;
    padding: 8px 25px;
    border-radius: 20px;
    font-size: 18px;
    font-weight: bold;
    backdrop-filter: blur(10px);
}

#dialogue-box {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    max-width: 90%;
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 20px;
    border-radius: 15px;
    border: 2px solid #ff9800;
    display: none;
    backdrop-filter: blur(10px);
}

#dialogue-box .npc-name {
    color: #ff9800;
    font-weight: bold;
    font-size: 16px;
    margin-bottom: 8px;
}

#dialogue-box .dialogue-text {
    font-size: 14px;
    line-height: 1.6;
}

#dialogue-box .dialogue-hint {
    color: #999;
    font-size: 12px;
    margin-top: 10px;
    text-align: right;
}

#crosshair {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    pointer-events: none;
}

#crosshair::before, #crosshair::after {
    content: '';
    position: absolute;
    background: rgba(255,255,255,0.7);
}

#crosshair::before {
    width: 2px;
    height: 20px;
    left: 9px;
    top: 0;
}

#crosshair::after {
    width: 20px;
    height: 2px;
    left: 0;
    top: 9px;
}

#speed-indicator {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: rgba(0,0,0,0.75);
    color: #4fc3f7;
    padding: 10px 15px;
    border-radius: 10px;
    border: 1px solid #4fc3f7;
    font-size: 14px;
    display: none;
}

#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a237e, #0d47a1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
}

#loading-screen h1 {
    font-size: 48px;
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(79,195,247,0.8);
}

#loading-screen p {
    font-size: 18px;
    opacity: 0.8;
}

#loading-bar {
    width: 300px;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    margin-top: 30px;
    overflow: hidden;
}

#loading-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #4fc3f7, #00e5ff);
    border-radius: 2px;
    transition: width 0.3s;
}

#start-btn {
    margin-top: 30px;
    padding: 12px 40px;
    font-size: 18px;
    background: linear-gradient(135deg, #4fc3f7, #0288d1);
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    display: none;
    transition: transform 0.2s;
}

#start-btn:hover {
    transform: scale(1.05);
}
</style>
</head>
<body>

<div id="loading-screen">
    <h1>🏫 校园探索</h1>
    <p>3D Campus Explorer</p>
    <div id="loading-bar"><div id="loading-bar-fill"></div></div>
    <button id="start-btn" onclick="startGame()">开始探索</button>
</div>

<div id="ui-overlay">
    <div id="crosshair"></div>
    <div id="location-name">校园入口</div>
    <div id="controls-help">
        <strong>🎮 操作指南</strong><br>
        WASD - 移动<br>
        鼠标 - 视角<br>
        Shift - 奔跑<br>
        Space - 跳跃<br>
        E - 交互/对话<br>
        F - 上/下车<br>
        ESC - 释放鼠标
    </div>
    <canvas id="minimap"></canvas>
    <div id="info-panel">欢迎来到校园!使用WASD移动,鼠标控制视角</div>
    <div id="dialogue-box">
        <div class="npc-name"></div>
        <div class="dialogue-text"></div>
        <div class="dialogue-hint">按 E 继续 / 按 Q 关闭</div>
    </div>
    <div id="speed-indicator">🚗 速度: <span id="speed-val">0</span> km/h</div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
// ==================== GAME ENGINE ====================

let scene, camera, renderer, clock;
let player, playerMixer, playerActions = {};
let npcs = [], buildings = [], interactables = [];
let car = null, isInCar = false, carSpeed = 0;
let keys = {};
let mouseX = 0, mouseY = 0;
let yaw = 0, pitch = 0;
let isPointerLocked = false;
let velocity = new THREE.Vector3();
let playerOnGround = true;
let currentLocation = '校园入口';
let dialogueActive = false;
let currentDialogue = null;
let dialogueIndex = 0;
let playerSpeed = 8;
let sprintMultiplier = 1.8;

// Physics
const GRAVITY = -25;
const JUMP_FORCE = 10;
const PLAYER_HEIGHT = 1.8;
const PLAYER_RADIUS = 0.4;

// ==================== INITIALIZATION ====================

function init() {
    clock = new THREE.Clock();
    
    // Scene
    scene = new THREE.Scene();
    scene.background = n.........完整代码请登录后点击上方下载按钮下载查看

网友评论0