This project has been created as part of the 42 curriculum by hbani-at.
So Long is a 2D game project developed as part of the 42 curriculum. The objective is to create a simple yet engaging game where the player must navigate a map, collect all items, and reach an exit to complete each level.
- Build a functional 2D game using the MLX (Mini LibX) graphics library
- Implement proper map parsing and validation with error handling
- Develop game mechanics including player movement and collision detection
- Practice structured C programming with modular design
- Create an interactive graphical user interface using MLX
- Map-based Navigation: Load and render custom maps from
.berfiles - Player Movement: Control the player character using WASD
- Collectibles: Gather all items scattered across the map
- Exit: Reach the exit after collecting all items
- Map Validation: Comprehensive validation to ensure maps are correctly formatted and solvable
- Flood Fill Algorithm: Verify that all collectibles and the exit are reachable
- Error Handling: Clear error messages for various failure scenarios
- Graphical Rendering: XPM-based sprite rendering for player, collectibles, walls, ground, and exit
What it is: The GNU C Compiler, used to compile C source code into executable programs.
Installation:
-
Debian/Ubuntu:
sudo apt-get update sudo apt-get install gcc
-
Fedora/RHEL/CentOS:
sudo dnf install gcc
-
macOS (if needed):
xcode-select --install
Verify installation:
gcc --versionWhat it is: X11 (X Window System) libraries are required for graphical display on Linux systems. MLX depends on these libraries to create windows and handle graphics.
Installation:
-
Debian/Ubuntu:
sudo apt-get update sudo apt-get install libxext-dev libx11-dev libximg-dev
-
Fedora/RHEL/CentOS:
sudo dnf install libXext-devel libX11-devel libXrender-devel
-
Arch Linux:
sudo pacman -S libx11 libxext
Verify installation:
pkg-config --cflags --libs x11 xextWhat it is: A tool for automating the compilation process using Makefiles.
Installation:
-
Debian/Ubuntu:
sudo apt-get install make
-
Fedora/RHEL/CentOS:
sudo dnf install make
-
macOS:
xcode-select --install
Verify installation:
make --versionWhat it is: A lightweight graphics library created by 42 school for educational purposes.
Status: ✅ Included in the project - The MLX library is already present in the mlx/ directory and will be compiled as part of the build process.
Installation (if you need to clone it separately):
If the mlx/ directory is missing or you want to install MLX separately, clone it from the official repository:
git clone https://github.com/42paris/minilibx-linux.git mlxThis will clone the MLX repository into a directory named mlx. The Makefile in this project is configured to look for MLX in this location.
Verify installation:
ls -la mlx/You should see the MLX source files and configuration scripts in the directory.
Navigate to the project directory and compile the project:
makeThis will:
- Compile the libft library (custom C library)
- Compile the get_next_line module
- Link all components together to create the
so_longexecutable
To clean up object files:
make cleanTo remove all compiled files and executables:
make fcleanTo rebuild from scratch:
make reRun the game with a valid map file:
./so_long maps/easy.berThe executable requires exactly one argument: the path to a .ber map file.
Maps must be in .ber format with the following requirements:
- Rectangular: All rows must have the same length
- Surrounded by Walls: The entire perimeter must be walls (
1) - Required Elements:
- Exactly one player (
P) - At least one collectible (
C) - Exactly one exit (
E) - Ground tiles (
0) - Wall tiles (
1)
- Exactly one player (
- Valid Characters: Only the above characters are allowed
- Solvability: All collectibles and the exit must be reachable from the player's starting position
111111111111
100P00000001
10000C00C001
1000000000E1
111111111111
- WASD: Move the player
- ESC or Close Button: Exit the game
- Move counter displayed in terminal showing number of moves taken
- MLX Man Pages
- MLX Documentation: Mini LibX Manual
- 42 School Subject: Official 42 project subject
- Flood Fill Algorithm: Classic pathfinding technique for connectivity verification
- Enums in C: Enums in C
so_long/
├── main.c # Entry point and main game loop initialization
├── game.c # Game initialization and cleanup
├── map_loader.c # Map file reading and parsing
├── map_validation.c # Map format and structure validation
├── map_path_validation.c # Flood fill algorithm for path validation
├── images.c # XPM image loading and initialization
├── rendering.c # Game rendering loop
├── movement.c # Player movement and input handling
├── error.c # Error handling and messaging
├── utils.c # Utility functions
├── so_long.h # Main header with structures and function declarations
├── libft/ # Custom C library (includes list operations, string manipulation)
├── get_next_line/ # Buffer-based line reading utility
├── mlx/ # Mini LibX graphics library
├── textures/ # XPM sprite files
├── maps/ # Sample and test map files
└── Makefile # Build configuration
game_init(): Initializes game state and loads resourcesmap_load(): Reads and parses the map filemap_validate(): Validates map structure and formatmap_validate_path(): Uses flood fill to verify all elements are reachablerender_map(): Main rendering function called in the game loopplayer_move(): Handles keyboard input and player movementinit_images(): Loads XPM sprites for all game elements
Author: hbani-at
Project Type: 42 Curriculum - Graphics/Game Development
Language: C
Graphics Library: MLX (Mini LibX)