three实现同屏左右分割双人飞机空战射击游戏代码

代码语言:html

所属分类:游戏

代码描述:three实现同屏左右分割双人飞机空战射击游戏代码,双人分屏 左屏 - 玩家1视角,蓝色战斗机 右屏 - 玩家2视角,红色战斗机 各自独立的摄像机跟随 操控说明 玩家1 玩家2 俯仰/偏航 WASD 方向键 翻滚 Q/E ,/. 射击 空格 Enter 导弹 F / 加/减速 R/T [/] 游戏模式 PVP对战 - 双人1v1空战,先

代码标签: three 同屏 左右 分割 双人 飞机 空战 射击 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>双人分屏空战</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { overflow: hidden; background: #000; font-family: Arial, sans-serif; }
canvas { display: block; }
#ui {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 10;
}
.divider {
    position: absolute; top: 0; left: 50%; width: 3px; height: 100%;
    background: rgba(0,255,255,0.6); transform: translateX(-50%);
    box-shadow: 0 0 10px cyan;
}
.player-hud {
    position: absolute; top: 10px; padding: 10px 20px;
    color: #0f0; font-size: 14px; text-shadow: 0 0 5px #0f0;
}
.player-hud.left { left: 10px; }
.player-hud.right { right: 10px; text-align: right; }
.health-bar {
    width: 200px; height: 12px; background: rgba(255,0,0,0.3);
    border: 1px solid #0f0; margin-top: 5px; position: relative;
}
.health-fill {
    height: 100%; background: linear-gradient(90deg, #f00, #0f0);
    transition: width 0.3s;
}
.crosshair {
    position: absolute; width: 40px; height: 40px;
    transform: translate(-50%, -50%); pointer-events: none;
}
.crosshair::before, .crosshair::after {
    content: ''; position: absolute; background: rgba(0,255,0,0.8);
}
.crosshair::before {
    width: 2px; height: 100%; left: 50%; transform: translateX(-50%);
}
.crosshair::after {
    width: 100%; height: 2px; top: 50%; transform: translateY(-50%);
}
.crosshair-dot {
    position: absolute; width: 4px; height: 4px; background: #0f0;
    border-radius: 50%; top: 50%; left: 50%; transform: translate(-50%, -50%);
}
#menu {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,20,0.95); display: flex; flex-direction: column;
    justify-content: center; align-items: center; z-index: 100;
}
#menu h1 {
    color: cyan; font-size: 48px; margin-bottom: 30px;
    text-shadow: 0 0 20px cyan, 0 0 40px blue;
}
#menu .subtitle {
    color: #aaa; margin-bottom: 40px; font-size: 16px;
}
#menu button {
    padding: 15px 50px; margin: 10px; font-size: 20px;
    background: linear-gradient(180deg, #004, #008); color: cyan;
    border: 2px solid cyan; cursor: pointer; pointer-events: all;
    transition: all 0.3s; border-radius: 5px;
}
#menu button:hover {
    background: linear-gradient(180deg, #006, #00c);
    box-shadow: 0 0 20px cyan;
}
.controls-info {
    color: #888; font-size: 13px; margin-top: 30px; text-align: center;
    line-height: 2;
}
.score { font-size: 24px; color: cyan; text-shadow: 0 0 10px cyan; }
.ammo { color: #ff0; margin-top: 5px; }
.speed-indicator { color: #0ff; margin-top: 3px; }
.warning { color: #f00; animation: blink 0.5s infinite; font-weight: bold; }
@keyframes blink { 50% { opacity: 0; } }
.missile-lock {
    position: absolute; width: 60px; height: 60px; border: 2px solid red;
    transform: translate(-50%, -50%) rotate(45deg);
    animation: lockPulse 0.5s infinite;
}
@keyframes lockPulse { 50% { border-color: yellow; transform: translate(-50%, -50%) rotate(45deg) scale(1.2); } }
#gameOver {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8); display: none; flex-direction: column;
    justify-content: center; align-items: center; z-index: 100;
}
#gameOver h1 { color: #f00; font-size: 48px; text-shadow: 0 0 20px red; }
#gameOver p { color: #fff; font-size: 24px; margin: 20px; }
#gameOver button {
    padding: 15px 40px; font-size: 20px; background: #800; color: #fff;
    border: 2px solid #f00; cursor: pointer; pointer-events: all; border-radius: 5px;
}
.radar {
    position: absolute; bottom: 20px; width: 120px; height: 120px;
    border: 2px solid rgba(0,255,0,0.5); border-radius: 50%;
    background: rgba(0,20,0,0.5);
}
.radar.left { left: 20px; }
.radar.right { right: 20px; }
.radar-sweep {
    position: absolute; width: 50%; height: 2px; background: linear-gradient(90deg, transparent, #0f0);
    top: 50%; left: 50%; transform-origin: left center;
    animation: sweep 2s linear infinite;
}
@keyframes sweep { 100% { transform: rotate(360deg); } }
.altitude-indicator {
    position: absolute; bottom: 150px; width: 30px; height: 150px;
    border: 1px solid rgba(0,255,0,0.5); background: rgba(0,20,0,0.3);
}
.altitude-indicator.left { left: 60px; }
.altitude-indicator.right { right: 60px; }
.alt-fill {
    position: absolute; bottom: 0; width: 100%;
    background: linear-gradient(0deg, #0a0, #0f0);
    transition: height 0.2s;
}
.alt-label { color: #0f0; font-size: 10px; text-align: center; margin-top: 2px; }
</style>
</head>
<body>
<div id="menu">
    <h1>⚔️ 空战对决 ⚔️</h1>
    <div class="subtitle">双人分屏战斗机空战模拟</div>
    <button onclick="startGame('pvp')">🔥 双人对战 (PVP)</button>
    <button onclick="startGame('coop')">🤝 组队合作 (VS AI)</button>
    <div class="controls-info">
        <strong style="color:cyan">玩家1 (左屏)</strong><br>
        WASD - 飞行控制 | Q/E - 翻滚 | Space - 射击 | F - 导弹<br><br>
        <strong style="color:cyan">玩家2 (右屏)</strong><br>
        方向键 - 飞行控制 | ,/. - 翻滚 | Enter - 射击 | / - 导弹<br><br>
        <span style="color:#666">R/T - 加减速(P1) | [/] - .........完整代码请登录后点击上方下载按钮下载查看

网友评论0