This project demonstrates the core rendering technique used in early pseudo-3D games like Doom and Wolfenstein 3D.
- Basic raycasting engine
- Colored walls
- Simple map
- Player movement and rotation
- Collision detection
- Floor and ceiling rendering
minifbcrate for window management and graphics
-
Make sure you have Rust installed. If not, download it from https://www.rust-lang.org/
-
Clone the repository
git clone https://github.com/WillKirkmanM/doom- Run DOOM
cargo run --release-
Build and run the project:
cargo run --release
-
Use the following keys to control the player:
W: Move forwardS: Move backwardA: Turn leftD: Turn rightESC: Exit the game
-
src/main.rs: Contains the main game loop and rendering logic.-
WIDTH: Width of the window. -
HEIGHT: Height of the window. -
MAP_SIZE: Size of the map (number of cells in each dimension). -
get_map(): Function that defines the game map. Walls are represented by1, and empty spaces by0. Different numbers represent different wall colors. -
main():- Initializes the window using
minifb. - Sets up player position, direction, and camera plane.
- Enters the main loop, handling player input and rendering.
- Renders the floor and ceiling.
- Implements the raycasting algorithm to draw the walls.
- Initializes the window using
-
The raycasting algorithm works as follows:
-
For each vertical column of pixels on the screen:
- Calculate the ray direction based on the player's direction and camera plane.
- Determine which map cell the ray starts in.
- Calculate the distances to the nearest grid lines in the x and y directions (
side_dist_xandside_dist_y). - Use Digital Differential Analysis (DDA) to step through the map until a wall is hit.
- Calculate the distance from the player to the hit wall.
- Determine the height of the wall on the screen based on the distance.
- Draw a vertical line representing the wall, with the color determined by the wall type in the map.
The get_map() function defines the game map as a 2D array of u8 values. Each value represents a different type of block:
0: Empty space1: Red wall2: Green wall3: Blue wall4: Yellow wall
- The player's position is represented by
player_xandplayer_y. - The player's direction is represented by a direction vector (
dir_x,dir_y) and a camera plane vector (plane_x,plane_y). - The
WandSkeys move the player forward and backward, respectively. - The
AandDkeys rotate the player left and right, respectively. - Collision detection prevents the player from walking through walls.
