jlebre/42Cub3d

Basic Raycaster in C

โ˜… 2Forks 0CGitHub โ†—Compare
cgamegame-developmentgamedevprojectraycasterraycaster-enginewolfensteinwolfenstein-3dwolfenstein-3d-engine

README

42Cub3D

42 School Logo

๐Ÿ•น๏ธ 42 Cursus - Cub3D

Cub3D is the final C project in the 42 curriculum, where we implemented a basic raycasting engine inspired by Wolfenstein 3D.

This was a group project:

The project took around 2 months to complete, using the original textures from Wolfenstein 3D.

One of the biggest challenges was correctly mapping the X-coordinate of a texture onto a wall.

๐Ÿ“œ To see the project subject, click here!


๐Ÿ“ธ Gallery

Screenshot

Screenshot

Recording.2023-05-10.020203.mp4
Recording.2023-05-10.020825.mp4

โš™๏ธ Installation

Install MLX:

sudo apt-get install gcc make xorg libxext-dev libbsd-dev
git clone https://github.com/42Paris/minilibx-linux.git && cd minilibx-linux && ( [ -f ./configure ] && ./configure || true ) && make && sudo cp libmlx.a /usr/local/lib/ && [ -f libmlx_$(uname -m).a ] && sudo cp libmlx_$(uname -m).a /usr/local/lib/ || true && sudo cp mlx.h /usr/local/include/ && sudo mkdir -p /usr/local/man/man3 && sudo cp man/man3/mlx*.1 /usr/local/man/man3

Download the rep:

git clone https://github.com/jlebre/42Cub3d.git
cd 42Cub3d/
make

To run the game:

./cub3d "map"

Available maps:

./cub3d basic.cub
./cub3d info.cub

You can create custom maps as long as they follow the constraints in The Assignment section.

To compile and run basic.cub in one command:

make a

๐Ÿ“œ The Assignment

The goal was to build a 3D labyrinth game with first-person view, inspired by Wolfenstein 3D.

Key Requirements

  • Use MiniLibX for rendering.
  • Smooth window management (switching, minimizing, etc.).
  • Textured walls that vary based on orientation (N, S, E, W).
  • Custom floor & ceiling colors.
  • Keyboard controls:
    • W, A, S, D โ†’ Move player
    • โ†, โ†’ โ†’ Rotate view
    • ESC โ†’ Exit game
  • Clicking the windowโ€™s close button should properly exit.
  • Parse .cub files for game settings & map layout.
  • The map must be enclosed by walls (1 for walls, 0 for empty space, N/S/E/W for player spawn position).

Example of a valid .cub map:

111111
100101
101001
1100N1
111111

Texture & Color Configuration

NO ./path_to_north_texture
SO ./path_to_south_texture
WE ./path_to_west_texture
EA ./path_to_east_texture

F 220,100,0
C 225,30,0

If any error is found in the configuration file, the program must exit with:

Error
[Description of the issue]

๐ŸŽฎ Features

โœ”๏ธ Working compass

โœ”๏ธ Minimap FOV matches actual player vision

โœ”๏ธ Pause menu (P key)

โœ”๏ธ Toggle minimap (M key)

โœ”๏ธ Lives system (press - to lose a life, game stops at 0)

โš ๏ธ The settings icon is not functional.


๐Ÿ† Final Grade: 115/100

We completed 3 out of 5 possible bonus features:

โœ”๏ธ Wall collisions

โœ”๏ธ Mini-map system

โœ”๏ธ Move FOV with mouse

Screenshot


๐ŸŽค Conclusion

This was one of the most enjoyable projects Iโ€™ve worked on! Seeing visual progress made it extra rewarding.

This might be my favorite project so far, and Iโ€™d love to add more features in the future. ๐Ÿš€

Contributors

jlebremtavares98

Issues