I'll create a Rust-inspired survival game using Three.js from scratch. This will include first-person controls, procedural terrain, resource gathering, building mechanics, and AI entities.
Now I'll create the main game logic file with Three.js:
Let me check the existing project structure to understand what's expected:
I see there's an existing Vite + React + TypeScript setup. Let me adapt my approach to work within this structure:
Let me check the Vite entry point and main.tsx:
I need to restore the proper Vite index.html. Let me check the bottom of it first:
I need to restructure this to work with Vite's build system. Let me install three.js and reorganize:
Now let me create the proper Vite index.html with the correct entry point:
Now let me create the game logic as a separate module:
Let me fix the type errors:
Now let me create the App.tsx with the game UI:
Now let me build the project to verify everything works:
The project builds successfully. I've created a complete Rust-inspired survival game from scratch using Three.js. Here's what was built:
🎮 Game Features
Core Systems:
- Three.js engine with shadow mapping, fog, and dynamic lighting
- Procedural terrain generated with custom Perlin-style noise (no dependencies)
- First-person controls with pointer lock, WASD movement, jumping, and gravity
- Day/night cycle with dynamic sun position and sky color transitions
Gameplay:
- Resource gathering — chop trees (wood), mine rocks (stone), pick berries (food)
- Building system — place walls (20 wood) and floors (15 wood) with ghost preview (green = can build, red = cannot)
- 5-slot hotbar — Rock (1), Hatchet (2, does more damage), Wall (3), Floor (4), Food (5)
- Combat — attack hostile NPCs that chase and attack you when you get close
- Hunger/Health system — starvation drains health, eating restores hunger, well-fed regenerates health
- Death & respawn mechanics
World Generation:
- 80 trees, 60 rocks, 40 food bushes scattered across a 200×200 terrain
- Water plane at sea level
- 8 hostile NPCs that wander and chase on detection
- Resources respawn 15 seconds after being harvested
UI (React + Tailwind):
- Start screen with title and instructions
- Death screen with respawn button
- HUD with wood/stone/food counts, FPS counter, health/hunger bars, crosshair, hotbar
- Controls help panel
🎯 Controls
- WASD — Move
- Mouse — Look around
- Space — Jump
- Left Click — Attack/Gather
- E — Place building / Eat food (when Food slot selected)
- 1-5 — Select hotbar slot
- ESC — Release mouse
The game uses custom Perlin-style noise (no external noise libraries), built-in Three.js for rendering, and React for the UI overlay — all bundled into a single ~750KB file via Vite's singlefile plugin.
Files built: index.html, main.js, src/game/engine.ts, src/App.tsx