cub3d
Published @ 10-03-2024
— A wolfenstein clone written in C.
The project’s goal was to create wolfenstein’esque game, this was a group project so Yesim and I teamed up together for this one.
The repo is over here
Features
- Floor and ceiling textures.
- Recessed doors that can be opened with the
F
key. - Billboard style sprite rendering, which can be defined in the
.cub
file. - Mouse support.
- Minimap with zoom.
- Comic Sans font rendering 🤓.
Description
The program takes a .cub
file which contains some key value pairs, and the actual map layout.
NO | Path to north wall texture. |
SO | Path to south wall texture. |
EA | Path to east wall texture. |
WE | Path to west wall texture. |
F | Path to a floor texture or an RGB color value. |
C | Path to a ceiling texture or an RGB color value. |
D | Path to a door texture. |
SP | Path to a sprite texture, seperated by a space and follwed by the sprite’s coordinates in the map. |
The map layout has the following values
N/S/E/W | The player’s starting position with a certain orientation. |
0 | Empty tile or simply a floor tile. |
1 | Collidable wall. |
D | Openable door. |
What is a raycaster?
— Raycasting is a rendering technique to create a 3D perspective in a 2D map.
It works by drawing a lot of lines (with a varying angle) from the players position through the map up until it hits a non-collidable tile.
When it detects a hit we can get its tiletype
(e.g a wall, door or sprite) and can render it using the rays length, drawing the texture’s size proportional to the distance of the player.
For a more detailed explanation take a look over here.
Game loop
Because we wanted to game to run with a variable framerate, we had to do some research on gameloops and seperating the rendering part of the code from the game logic.
This is a great resource for just that.
Resources
https://www.middle-engine.com/blog/posts/2020/07/28/bresenhams-line-algorithm
https://gameprogrammingpatterns.com/game-loop.html
https://lodev.org/cgtutor/raycasting.html