A 3D maze exploration game built using raycasting techniques in C++ with SDL2. This project demonstrates the classic raycasting algorithm similar to early first-person games like Wolfenstein 3D.
- Procedurally Generated Mazes: Each maze is randomly generated for a unique experience
- 3D Raycasting Rendering: Converts 2D maze data into a 3D first-person perspective
- Smooth Movement: Fluid player movement and rotation controls
- Real-time Rendering: Efficient SDL2-based graphics rendering
- Configurable Settings: Easy-to-modify game parameters (FOV, speed, screen resolution)
The project automatically installs dependencies, but you'll need:
- Operating System: Linux (tested on Debian/Ubuntu-based distributions)
- Git: For project management
- Sudo privileges: For installing packages
build-essential: C++ compiler and build toolslibsdl2-dev: SDL2 development librariescmake: Build system generator
The project includes automated build scripts for easy setup.
./build.shThis script will:
- Check for required packages
- Install any missing dependencies
- Create a build directory
- Compile the project using CMake and Make
- Generate the executable in
build/Raycasting-in-Maze
After building, run the game with:
./run.shThe run.sh script will:
- Check if the executable exists
- Build the project if needed
- Launch the game
To force a rebuild before running, edit run.sh and set:
DEV_MODE=1| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
← |
Rotate camera left |
→ |
Rotate camera right |
ESC |
Exit game |
Raycasting-in-Maze/
├── include/
│ ├── Config.hpp # Game configuration constants
│ ├── Game.hpp # Main game loop and logic
│ ├── Maze.hpp # Maze generation and management
│ ├── Player.hpp # Player movement and state
│ └── Renderer.hpp # Raycasting rendering engine
├── src/
│ ├── main.cpp # Entry point
│ ├── Game.cpp # Game implementation
│ ├── Maze.cpp # Maze generation algorithm
│ ├── Player.cpp # Player controller
│ └── Renderer.cpp # Rendering implementation
├── build.sh # Automated build script
├── run.sh # Automated run script
├── clean.sh # Cleanup script
├── packages.txt # Required system packages
└── CMakeLists.txt # CMake configuration
The project implements a raycasting engine that:
- Casts rays from the player's position through each screen column
- Calculates ray-wall intersections using DDA (Digital Differential Analysis)
- Computes wall distances to determine wall heights
- Renders vertical lines with appropriate heights to create 3D perspective
Uses a randomized algorithm to generate perfect mazes (mazes with exactly one path between any two points).
To remove build artifacts and uninstall dependencies:
./clean.shThis will:
- Remove the
build/directory - Uninstall packages listed in
packages.txt
Note: Use with caution if you have other projects using the same dependencies.
Edit include/Config.hpp to customize:
- Maze Size:
MAZE_WIDTHandMAZE_HEIGHT(default: 20x20) - Movement Speed:
MOVE_SPEED(default: 0.05) - Rotation Speed:
ROTATE_SPEED(default: 0.05) - Field of View:
FOV(default: 0.66) - Screen Resolution:
SCREEN_WIDTHandSCREEN_HEIGHT(default: 1920x1080) - Key Bindings: Customize control keys
After modifying configuration, rebuild the project:
./build.shIf you prefer manual building:
# Install dependencies
sudo apt update
sudo apt install build-essential libsdl2-dev cmake
# Create build directory
mkdir -p build && cd build
# Configure with CMake
cmake -DCMAKE_BUILD_TYPE=Release ..
# Compile
make -j$(nproc)
# Run
./Raycasting-in-Maze- Ensure all dependencies are installed:
sudo apt install build-essential libsdl2-dev cmake - Check that you're in the project root directory
- Try cleaning and rebuilding:
./clean.sh && ./build.sh
- Check that SDL2 is properly initialized
- Verify screen resolution settings in
Config.hppmatch your display
- Reduce
SCREEN_WIDTHandSCREEN_HEIGHTinConfig.hpp - Ensure you're building in Release mode (default in
build.sh)