a small retro-style 3d engine that renders a maze using raycasting (similar to wolfenstein 3d).
you can move inside the maze using arrow keys.
download: https://www.msys2.org/
install using default settings.
after install: open msys2 ucrt64 terminal
run:
pacman -S mingw-w64-ucrt-x86_64-gcc
pacman -S mingw-w64-ucrt-x86_64-sdl
press y when asked.
this installs:
- g++ compiler
- sdl graphics library
create a folder anywhere, for example:
desktop/maze
place these files inside:
maze/
│
├── main.cpp
├── quickcg.cpp
├── quickcg.h
│
└── pics/
├── eagle.png
├── redbrick.png
├── purplestone.png
├── greystone.png
├── bluestone.png
├── mossy.png
├── wood.png
└── colorstone.png
quickcg files download:
https://lodev.org/cgtutor/files/quickcg.cpp https://lodev.org/cgtutor/files/quickcg.h
textures are required or the program will crash.
open msys2 ucrt64 terminal
navigate to project folder:
example:
cd /c/users/yourname/desktop/maze
run:
g++ *.cpp -lmingw32 -lsdlmain -lsdl -o3 -o raycaster
if compilation succeeds, a file appears:
raycaster.exe
ignore warning about missing return statement.
./raycaster.exe
a window opens showing a 3d maze.
| key | action |
|---|---|
| ↑ | move forward |
| ↓ | move backward |
| ← | turn left |
| → | turn right |
| esc | exit |
| file | purpose |
|---|---|
| main.cpp | raycasting engine |
| quickcg.cpp | graphics helper functions |
| quickcg.h | declarations for quickcg |
| pics/ | wall textures |
quickcg simplifies:
- window creation
- keyboard input
- image loading
- drawing pixels
run:
pacman -S mingw-w64-ucrt-x86_64-sdl
compile using:
g++ *.cpp -lmingw32 -lsdlmain -lsdl -o3 -o raycaster
check folder:
pics/
must be in same directory as exe.
concepts:
- raycasting
- dda algorithm
- texture mapping
- camera projection
- game loop
each vertical pixel column shoots a ray into a 2d grid map to simulate a 3d view.
this project stands on the shoulders of this beautifully explained guide by lode vandevenne.