Skip to content
demo-zexuanPublic

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

⛏️ MC-JS — 网页版沙盒世界

基于 Three.js + TypeScript 的网页版 Minecraft 风格沙盒游戏。

Tech TS Vite License

✨ 特性

  • 🏞️ 程序化地形生成:基于种子化 fBm 值噪声生成起伏地形与沙滩、树木
  • 🧱 像素风纹理图集:Canvas 运行时程序化生成 16×16 像素纹理,零外部资源
  • ⛏️ 方块建造:鼠标左键破坏、右键放置,支持 7 种方块
  • 🚶 第一人称控制:WASD 移动、空格跳跃、Shift 疾跑、鼠标视角、指针锁定
  • 🕊️ 飞行模式:F 键切换飞行 / 生存模式
  • 📦 分块渲染:按 16×16 区块合并几何体,剔除被遮挡面,高性能渲染
  • 🌐 GitHub Pages 部署:内置 GitHub Actions 工作流,推送即部署

🚀 本地运行

# 安装依赖
npm install

# 开发模式
npm run dev

# 类型检查
npm run typecheck

# 生产构建
npm run build

# 预览构建产物
npm run preview

💡 通过 URL 参数 ?seed=xxx 复现特定世界地形。

🎮 操作说明

操作 按键
移动 W A S D
跳跃 / 飞行上升 Space
疾跑 / 飞行下降 Shift
破坏方块 鼠标左键
放置方块 鼠标右键
选择方块 1 - 9 或滚轮
切换飞行 / 生存 F
重新生成世界 R
释放鼠标 Esc

📦 部署到 GitHub Pages

项目已内置 .github/workflows/deploy.yml,推送到 main 分支后自动构建并部署。

首次配置

  1. 创建 GitHub 仓库并推送代码:

    git init
    git add .
    git commit -m "✨ feat: init mc-js sandbox game"
    git branch -M main
    git remote add origin git@github.com:<用户名>/<仓库名>.git
    git push -u origin main
  2. 开启 Pages:仓库 Settings → Pages,将 Source 设置为 GitHub Actions。

  3. 推送后,GitHub Actions 自动构建并部署,访问地址: https://<用户名>.github.io/<仓库名>/

🧱 方块一览

纹理 方块 说明
草方块 GRASS 世界地表主要方块
泥土 DIRT 地表之下 3 层
石头 STONE 深层基岩层
沙子 SAND 海平面以下沙滩
原木 LOG 树木树干
树叶 LEAVES 树冠,半透明
砖块 BRICK 建造用装饰方块

🗂️ 项目结构

mc-js/
├── .github/workflows/deploy.yml   # GitHub Pages 部署工作流
├── src/
│   ├── main.ts                    # 游戏主入口(场景、渲染循环、UI)
│   ├── style.css                  # 像素风界面样式
│   ├── utils/Noise.ts             # 种子化值噪声 / fBm
│   ├── world/
│   │   ├── BlockTypes.ts          # 方块类型定义
│   │   ├── TextureAtlas.ts        # 程序化纹理图集
│   │   ├── World.ts               # 世界数据与地形生成
│   │   └── ChunkMesh.ts           # 区块网格构建与面剔除
│   ├── player/Player.ts           # 玩家控制与 AABB 碰撞
│   └── game/Raycast.ts            # 体素 DDA 射线检测
├── index.html                     # 页面骨架(开始界面 / HUD)
├── vite.config.ts                 # Vite 配置(相对路径 base)
└── tsconfig.json                  # TypeScript 严格模式配置

📝 License

MIT © zexuan.peng

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages