My first RayCaster with miniLibX 💡
The aim of the cub3d
proyect is to create a 3D game using the raycasting technique which is a rendering method implemented in the world-famous Wolfenstein 3D
game.
The cub3D
executable receives as a single argument the map file we read, which must be of .cub
filetype.
The file must follow these rules:
- There must be header lines before the actual map containing the following:
- At least a line containing
NO
,SO
,EA
andWE
followed by a valid path to an xpm image - A line starting with
F
(floor) orC
(ceiling) followed by a color in RGB separated by commas
- At least a line containing
- Only
1
(wall),0
(floor), and eitherN
,S
,E
orW
(Player starting position looking at North, South, East or West), will be accepted characters in our map (except if you add other characters as bonus) - The map may not be rectangular, but it must be surrounded by walls
- Spaces are allowed but the player cannot walk on them, thus every space must also be closed/surrounded by walls
- There must be a single player on the map
Here's an example of a valid map (not rectangular but still valid):
NO ./textures/WALL2.xpm
SO ./textures/WALL21.xpm
WE ./textures/WALL8.xpm
EA ./textures/WALL22.xpm
F 112,112,112
C 53,53,53
1111111111111111111111111
1000000000110000000000001
1011000001110000000000001
1001000000000000000000001
111111111011000001110000000000001
100000000011000001110111110111111
11110111111111011100000010001
11110111111111011101010010001
11000000110101011100000010001
10000000000000001100000000001
10000W00000000001101010010001
1100000111010101111101111000111
11110111 1110101 100000010001
11111111 1111111 111111111111
Raycasting is a rendering technique to create a 3D perspective in a 2D map. The logic behind RayCasting is to throw rays in the direction of the player view. Basically, we need to check the distance between the player and the nearest wall (i.e. the point where the ray hits a wall) to caculate the height of the vertical lines we draw. Here is a simple depiction of it:
Here is a summary of the various controls in the game:
- The
WASD
keys move the player up, down, left and right relative to the player's viewing angle - The
left
andright
arrow keys rotate the viewing angle of the player - Press the
ESC
key or theX
button on the window to exit the game