A 3D maze exploration game built with raycasting techniques, inspired by the legendary Wolfenstein 3D. This project creates a dynamic first-person perspective view inside a maze using the MinilibX graphics library.
- Real-time 3D rendering using raycasting algorithms
- Textured walls with different textures for each cardinal direction
- Smooth player movement with WASD controls
- Rotation controls using arrow keys
- Collision detection to prevent walking through walls
- Customizable maps with .cub file format
- Floor and ceiling colors configuration
- Cross-platform compatibility (Linux/macOS)
- GCC compiler
- Make
- X11 development libraries (Linux)
- MinilibX library (automatically downloaded)
-
Clone the repository git clone https://github.com/voloshynm/cub3d.git cd cub3d
-
Compile the project make
-
Run the game ./cub3D maps/test2.cub
| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
← |
Rotate left |
→ |
Rotate right |
ESC |
Exit game |
Maps are defined in .cub files with the following format:
NO ./textures/north_wall.xpm
SO ./textures/south_wall.xpm
WE ./textures/west_wall.xpm
EA ./textures/east_wall.xpm
F 127,125,119
C 174,234,255
11111111111111111111111111111
10000000001100000000011100001
10000000000000000000000000001
100000N0000000000000000000001
10000000000000000000000000001
10000000000000001100000010001
11111111111111111111111111111
- Textures:
NO,SO,WE,EA- Paths to XPM texture files - Colors:
F(floor),C(ceiling) - RGB values (0-255) - Map Characters:
1- Wall0- Empty spaceN/S/E/W- Player starting position and direction(space) - Void area
cub3d/
├── src/ # Source files
│ ├── main.c # Program entry point
│ ├── init_visuals.c # launch mlx loop, render frame and textures
│ ├── parser.c # Map file parsing
│ ├── parse_elements.c # Texture parsing
│ ├── parse_elements_helper.c # Texture parsing
│ ├── parse_elements_color.c # Color parsing
│ ├── parse_map.c # Map validation and processing
│ ├── parse_map_directions.c # Map processing
│ ├── validate_walls.c # Map validation
│ ├── raycasting.c # Core raycasting engine
│ ├── raycasting_helper.c # Core raycasting engine
│ ├── raycasting_rays_direction.c # Core raycasting engine
│ ├── controls.c # Input handling
│ ├── controls_helper.c # Input handling
│ ├── utils.c # Utility functions
│ └── utils_2.c # Utility functions
├── includes/
│ └── cub3d.h # Header file
├── textures/ # Texture files
├── maps/ # Example maps
├── libft/ # Custom C library
├── Makefile # Build configuration
└── README.md
The project implements a DDA (Digital Differential Analyzer) algorithm for raycasting:
- Ray initialization - Calculate ray direction for each screen column
- Grid traversal - Step through the map grid until hitting a wall
- Distance calculation - Compute perpendicular wall distance
- Wall rendering - Draw textured vertical lines based on distance
- Parser: Validates and loads map configuration
- Raycasting Engine: Renders 3D view from 2D map
- Texture Mapping: Applies appropriate textures to walls
- Input System: Handles player movement and rotation
- Memory Management: Proper allocation and cleanup
make # Compile the project make clean # Remove object files make fclean # Remove all generated files make re # Rebuild everything make help # Show available targets make status # Show project status
The project automatically handles dependencies:
- MinilibX: Downloaded and compiled automatically
- libft: Custom C library (cloned from repository)
Test your maps with the provided examples:
Valid map ./cub3D maps/test2.cub
Test error handling ./cub3D maps/invalid_map.cub ./cub3D nonexistent.cub
-
Segmentation fault
- Check map file format and validity
- Ensure texture files exist and are accessible
- Verify player position is valid
-
Compilation errors
- Install required development libraries
- Check GCC version compatibility
-
Texture loading fails
- Verify XPM file format
- Check file permissions
- Ensure paths are correct
Compile with debug symbols: make CFLAGS="-Wall -Wextra -Werror -g" gdb ./cub3D maps/test2.cub
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is part of the 42 School curriculum. Feel free to use it for educational purposes.
- Maksym Voloshyn - Hugo Huber
Thanks to mcombeau for sharing textures and maps for rigirous testing! https://github.com/mcombeau/cub3D
- 42 School for the project specification
- The creators of Wolfenstein 3D for inspiration
- MinilibX developers for the graphics library
- The raycasting community for tutorials and resources
Made with ❤️ at 42 School
