A tiny 2D top‑down game for the 42 curriculum built with MiniLibX. Your goal is simple: collect all the items and reach the exit while navigating a valid, enclosed map.
This repository contains:
- mandatory/ — the required implementation
- bonus/ — optional enhancements (e.g., enemies, move counter on-screen, animations)
- Makefile — build targets for mandatory and bonus
- Renders a tile-based map with walls, player, collectibles, and exit
- Validates maps (rectangular, enclosed by walls, correct element counts, and solvable path)
- Player movement using keyboard with step counting printed to the terminal
- Window close button (red cross) properly exits and frees resources
- Bonus (if enabled in your Makefile):
- Enemies or hazards
- Animated sprites
- On-screen move counter
Your program must:
- Accept a single
.ber
map file as an argument - Use MiniLibX for rendering
- Ensure the map:
- Is rectangular
- Is surrounded by walls (
1
) - Contains exactly one player (
P
) and one exit (E
) - Contains at least one collectible (
C
) - Is solvable (player can collect all
C
and reachE
)
- Print the move count to the terminal after each valid move
- Handle errors gracefully, printing a clear error message and exiting
- Free all allocated resources and avoid memory leaks
- File extension:
.ber
- Allowed characters:
0
— empty space1
— wallP
— player (exactly one)C
— collectible (one or more)E
— exit (exactly one)M
— enemy (bonus only, optional)
Example:
111111
1P0C01
100001
1C0E11
111111
Constraints:
- The map must be fully enclosed by
1
- The map must be rectangular (all rows same length)
- There must be a valid path to collect all
C
and reachE
The Makefile provides standard targets.
Common targets:
make
ormake all
— build the mandatory program (usuallyso_long
)make bonus
— build the bonus program (usuallyso_long_bonus
)make clean
— remove object filesmake fclean
— remove objects and binariesmake re
— rebuild from scratch
Example:
# Mandatory build
make
# Bonus build (if implemented)
make bonus
Notes:
- The Makefile is typically configured for the 42 environment. If you build locally, ensure MiniLibX and required system libraries are available on your machine.
- On Linux you may need development packages for X11 and Xext (for example: libx11-dev, libxext-dev, zlib1g-dev, libbsd-dev, xorg). On macOS, Apple Clang and the 42-provided MiniLibX are usually sufficient.
Provide a .ber
file as the only argument:
./so_long path/to/map.ber
# or (bonus)
./so_long_bonus path/to/map.ber
If your repository includes sample maps (e.g., in a maps/
directory), you can run:
./so_long maps/simple.ber
W
,A
,S
,D
or arrow keys — moveESC
— quit- Window close button — quit
Each valid move increments and prints the move count to the terminal. In the bonus, a move counter may also be drawn on screen.
Typical error cases your program should handle:
- Wrong number of arguments
- File not found or unreadable
- Invalid file extension (must be
.ber
) - Invalid characters in the map
- Map not rectangular or not enclosed by walls
- Wrong element counts (
P
,E
,C
) - No valid path to collect all
C
and reachE
On error, print a clear message and exit. Ensure all allocations are freed.
.
├── Makefile
├── README.md
├── mandatory/
│ ├── ... source files for required part
│ └── ...
└── bonus/
├── ... source files for bonus part
└── ...
Exact source file names may vary by implementation.
- Follow 42’s Norminette for C code style
- Check for memory leaks (e.g., with valgrind on Linux)
- Handle all failure paths (file I/O, allocations, MLX calls) and free resources on exit
- Decouple parsing/validation, pathfinding, rendering, and input handling where possible
- “mlx” or X11 include/link errors:
- Verify MiniLibX paths in the Makefile
- Install X11 dev packages on Linux
- Ensure you’re using Apple Clang on macOS (the 42 default)
- Window doesn’t appear or closes immediately:
- Check return values of MLX initialization and window creation
- Confirm the event loop is running
- Sprites not displayed:
- Verify asset paths and image loading return values
This project is part of the 42 school curriculum. If you intend to reuse or distribute, check your school’s policies and add a license file as appropriate.
- GitHub: otmansabir