three实现HDR级无限体素沙盒游戏代码

代码语言:html

所属分类:游戏

代码描述:浏览器中运行的HDR级无限体素沙盒游戏。你将探索由自定义“种子”随机生成的广阔世界,包含起伏的山脉、沙滩、森林与动态水域。 游戏核心玩法高度自由:使用 WASD 移动,鼠标控制视角;左键破坏方块,右键放置方块,中键可快速拾取准星对准的方块。通过 1-9 数字键或鼠标滚轮,可随时切换草、木、石、玻璃等9种基础建材。双击 Space 即可开启飞行模式(Space上升,C键下降),轻松搭建高空建筑。 本作最大特色在于卓越的视觉表现:内置完整的动态昼夜交替系统,包含逼真的日出日落、星空以及夜晚绚丽的极光效果。玩家

代码标签: three HDR 级 无限 体素 沙盒 游戏 代码

下面为部分代码预览,完整代码请点击下载或在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>FABLECRAFT - HDR Voxel Sandbox</title>
  <style>
    * { box-sizing: border-box; user-select: none; }
    html, body {
      margin: 0;
      padding: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      background: #0a0d14;
      font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
      color: #f3f5f8;
    }
    #game-canvas {
      display: block;
      width: 100%;
      height: 100%;
    }

    /* Menu Overlay */
    #menu-overlay {
      position: fixed;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      background: radial-gradient(circle at center, rgba(12, 16, 24, 0.45), rgba(6, 8, 14, 0.78));
      backdrop-filter: blur(4px);
      z-index: 20;
      transition: opacity 0.25s ease;
    }
    #menu-overlay.hidden {
      opacity: 0;
      pointer-events: none;
    }
    .menu-card {
      width: min(560px, 92vw);
      padding: 32px 36px 26px;
      border-radius: 18px;
      background: rgba(15, 18, 25, 0.84);
      border: 1px solid rgba(255, 255, 255, 0.12);
      box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
      text-align: center;
    }
    .title {
      margin: 0;
      font-size: clamp(34px, 5vw, 48px);
      font-weight: 900;
      letter-spacing: 5px;
      background: linear-gradient(180deg, #ffe29a 0%, #f59e38 65%, #d66d1b 100%);
      -webkit-background-clip: text;
      background-clip: text;
      color: transparent;
      text-shadow: 0 6px 24px rgba(245, 158, 56, 0.25);
    }
    .subtitle {
      margin: 6px 0 22px;
      font-size: 13px;
      color: #b7c0cf;
      letter-spacing: 0.4px;
    }
    #play-btn {
      width: 220px;
      height: 46px;
      border: 1px solid rgba(255, 215, 140, 0.5);
      border-radius: 8px;
      background: linear-gradient(180deg, #e0993e 0%, #b5681c 100%);
      color: #fff;
      font-size: 16px;
      font-weight: 700;
      cursor: pointer;
      box-shadow: 0 6px 20px rgba(209, 123, 36, 0.35);
      transition: transform 0.12s ease, filter 0.12s ease;
    }
    #play-btn:hover {
      filter: brightness(1.1);
      transform: translateY(-1px);
    }
    #play-btn:active {
      transform: translateY(1px);
    }

    .settings-grid {
      margin: 22px auto 18px;
      display: grid;
      grid-template-columns: 120px 1fr;
      gap: 12px 14px;
      align-items: center;
      text-align: left;
      font-size: 13px;
      color: #cbd5e1;
    }
    .seed-row {
      display: flex;
      gap: 8px;
    }
    input[type="text"], select {
      background: rgba(255, 255, 255, 0.08);
      border: 1px solid rgba(255, 255, 255, 0.16);
      border-radius: 6px;
      color: #fff;
      padding: 6px 10px;
      font-size: 13px;
      outline: none;
    }
    input[type="text"] { flex: 1; min-width: 0; }
    select { width: 100%; cursor: pointer; }
    select option { background: #161a24; color: #fff; }
    .small-btn {
      padding: 6px 12px;
      border-radius: 6px;
      border: 1px solid rgba(255, 255, 255, 0.2);
      background: rgba(255, 255, 255, 0.1);
      color: #fff;
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
    }
    .small-btn:hover { background: rgba(255, 255, 255, 0.18); }

    .range-row {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    input[type="range"] {
      flex: 1;
      accent-color: #f59e38;
      cursor: pointer;
    }
    #render-dist-label {
      min-width: 72px;
      text-align: right;
      font-weight: 600;
      color: #f1f5f9;
    }

    .controls-box {
      margin-top: 14px;
      padding-top: 14px;
      border-top: 1px solid rgba(255, 255, 255, 0.1);
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 5px 16px;
      text-align: left;
      font-size: 11.5px;
      color: #9aa5b8;
    }
    .controls-box b { color: #d6deeb; font-weight: 600; }

    /* HUD */
    #crosshair {
      position: fixed;
      top: 50%;
      left: 50%;
      width: 18px;
      height: 18px;
      transform: translate(-50%, -50%);
      pointer-events: none;
      z-index: 10;
      display: none;
    }
    #crosshair::before, #crosshair::after {
      content: "";
      position: absolute;
      background: rgba(255, 255, 255, 0.85);
      box-shadow: 0 0 2px rgba(0,0,0,0.9);
    }
    #crosshair::before { left: 8px; top: 1px; width: 2px; height: 16px; }
    #crosshair::after { top: 8px; left: 1px; width: 16px; height: 2px; }

    #block-label {
      position: fixed;
      bottom: 84px;
      left: 50%;
      transform: translateX(-50%);
      font-size: 13px;
      font-weight: 700;
      letter-spacing: 1.5px;
      text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
      color: #ffffff;
      pointer-events: none;
      z-index: 10;
      opacity: 0;
      transition: opacity 0.25s ease;
    }
    #block-label.visible { opacity: 1; }

    #hotbar {
      position: fixed;
      bottom: 18px;
      left: 50%;
      transform: translateX(-50%);
      display: flex;
      gap: 6px;
      padding: 6px;
      border-radius: 10px;
      background: rgba(12, 16, 24, 0.65);
      border: 1px solid rgba(255, 255, 255, 0.16);
      backdrop-filter: blur(6px);
      z-index: 15;
    }
    .hotbar-slot {
      position: relative;
      width: 48px;
      height: 48px;
      border-radius: 6px;
      background: rgba(255, 255, 255, 0.06);
      border: 2px solid transparent;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
    }
    .hotbar-slot.active {
      border-color: #ffffff;
      background: rgba(255, 255, 255, 0.18);
      box-shadow: 0 0 12px rgba(255, 255, 255, 0.25);
    }
    .hotbar-slot canvas {
      width: 34px;
      height: 34px;
      image-rendering: pixelated;
    }
    .slot-num {
      position: absolute;
      top: 2px;
      right: 4px;
      font-size: 9px;
      color: rgba(255, 255, 255, 0.65);
      font-weight: 700;
    }

    #debug-panel {
      position: fixed;
      top: 12px;
      left: 12px;
      padding: 10px 14px;
      border-radius: 8px;
      background: rgba(10, 14, 20, 0.72);
      border: 1px solid rgba(255, 255, 255, 0.12);
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
      font-size: 12px;
      line-height: 1.5;
      color: #e2e8f0;
      pointer-events: none;
      z-index: 15;
      display: none;
    }
  </style>
</head>
<body>
  <canvas id="game-canvas"></canvas>

  <div id="menu-overlay">
    <div class="menu-card">
      <h1 class="title">FABLECRAFT</h1>
      <p class="subtitle">HDR edition — an infinite voxel sandbox in a single HTML file</p>
      <button id="play-btn">Click to Play</button>

      <div class="settings-grid">
        <label for="seed-input">Seed</label>
        <div class=&.........完整代码请登录后点击上方下载按钮下载查看

网友评论0