Skip to content

A simple 3D game made with Three.js where you control a blocky character in a world with trees.

License

Notifications You must be signed in to change notification settings

ReinaldoMT/block

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3D Game - Movable Block 🎮

A simple 3D game made with Three.js where you control a blocky character in a world with trees.

📁 Project Structure

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

🎯 Modules

config.js

Centralized game settings. Change values here to adjust:

  • Movement speed
  • Physics (gravity, jump)
  • Camera (distance, height, FOV)
  • World colors
  • Tree positions

utils.js

Shared utility functions:

  • addEdges() - Adds edges to meshes
  • clamp() - Clamps values
  • normalizeAngle() - Normalizes angles
  • distance2D() - Calculates 2D distance
  • lerp() - Linear interpolation

scene.js

Manages the Three.js scene:

  • Renderer creation
  • Camera setup
  • Lighting
  • Resizing

character.js

Player character:

  • 3D model (head, body, limbs)
  • Walking animation
  • Physics (gravity, jump)
  • Smooth rotation

world.js

Game environment:

  • Ground and grid
  • Trees made of blocks
  • Collision system
  • Collectible blocks

inventory.js

Inventory system:

  • Item counting
  • UI updates
  • Types: wood and leaves

camera.js

Camera control:

  • First-person mode
  • Third-person mode
  • Zoom and rotation

controls.js

Player input:

  • Keyboard (WASD, arrows, space)
  • Mouse (drag, click, scroll)
  • Raycasting for collection

game.js

Main loop:

  • Initialization
  • Game loop
  • Coordination between modules

🎮 Controls

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

🔧 How to Run

  1. Open index-modular.html in a local web server
  2. Or use the Live Server extension in VS Code

Note: Due to script loading, an HTTP server is required.

🤖 Modification Tips (Humans & AI)

To change settings:

Edit js/config.js - all constants are centralized there.

To add new block types:

  1. Add the color in config.js
  2. Modify world.js to create the new type
  3. Update inventory.js to track the new item

To add new mechanics:

  1. Create a new file in js/
  2. Add the script in index-modular.html (order matters!)
  3. Integrate in game.js

To modify the character:

Edit character.js - each body part is separated.

To modify controls:

Edit controls.js - input handlers are organized by type.

📝 Code Conventions

  • 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

📄 License

This project is licensed under the MIT License.

About

A simple 3D game made with Three.js where you control a blocky character in a world with trees.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published