A simple 3D game made with Three.js where you control a blocky character in a world with trees.
block/
├── index.html # Original version (single file)
├── index-modular.html # Modular version (recommended)
├── css/
│ └── styles.css # UI styles
├── js/
│ ├── config.js # Global configuration
│ ├── utils.js # Utility functions
│ ├── scene.js # Three.js scene management
│ ├── character.js # Character and animations
│ ├── world.js # World, trees, collisions
│ ├── inventory.js # Inventory system
│ ├── camera.js # Camera control
│ ├── controls.js # Keyboard/mouse input
│ └── game.js # Main loop
└── README.md
Centralized game settings. Change values here to adjust:
- Movement speed
- Physics (gravity, jump)
- Camera (distance, height, FOV)
- World colors
- Tree positions
Shared utility functions:
addEdges()- Adds edges to meshesclamp()- Clamps valuesnormalizeAngle()- Normalizes anglesdistance2D()- Calculates 2D distancelerp()- Linear interpolation
Manages the Three.js scene:
- Renderer creation
- Camera setup
- Lighting
- Resizing
Player character:
- 3D model (head, body, limbs)
- Walking animation
- Physics (gravity, jump)
- Smooth rotation
Game environment:
- Ground and grid
- Trees made of blocks
- Collision system
- Collectible blocks
Inventory system:
- Item counting
- UI updates
- Types: wood and leaves
Camera control:
- First-person mode
- Third-person mode
- Zoom and rotation
Player input:
- Keyboard (WASD, arrows, space)
- Mouse (drag, click, scroll)
- Raycasting for collection
Main loop:
- Initialization
- Game loop
- Coordination between modules
| Key | Action |
|---|---|
| ←→ or AD | Move left/right |
| ↑↓ or WS | Move forward/backward |
| Q/E | Rotate character |
| Space | Jump |
| R | Reset position |
| F1 | Toggle 1st/3rd person |
| Left Click | Collect block |
| Middle Btn | Drag character |
| Scroll | Zoom |
| Right Click | Rotate camera |
- Open
index-modular.htmlin a local web server - Or use the Live Server extension in VS Code
Note: Due to script loading, an HTTP server is required.
Edit js/config.js - all constants are centralized there.
- Add the color in
config.js - Modify
world.jsto create the new type - Update
inventory.jsto track the new item
- Create a new file in
js/ - Add the script in
index-modular.html(order matters!) - Integrate in
game.js
Edit character.js - each body part is separated.
Edit controls.js - input handlers are organized by type.
- Singleton objects for modules (e.g.,
Character,World) - Public methods documented with JSDoc
- Settings centralized in
config.js - Descriptive names in Portuguese for UI, English for code
This project is licensed under the MIT License.
