This project has been created as part of the 42 curriculum by mobouifr.
A tiny 2D tile game built in C with MiniLibX.
Collect everything. Find the exit. Count your steps.
so_long is one of the first graphical projects in the 42 core curriculum. The concept is minimal on purpose — read a map from a .ber file, validate every rule, render it tile by tile, and let the player navigate to victory.
What's actually interesting is what's hiding under that simplicity. You parse a custom file format, validate its structure and playability, manage dynamic memory for the map grid, wire up keyboard hooks, run a render loop, and enforce game logic — all in C, all from scratch.
No game framework. No physics engine. Just C, file descriptors, and MLX pixels.
| Symbol | Meaning |
|---|---|
1 |
Wall — impassable |
0 |
Floor — walkable |
P |
Player spawn — exactly one |
C |
Collectible — at least one |
E |
Exit — exactly one |
Collect every C, then step onto E. The player cannot walk through walls. Every valid move prints the current step count to the terminal.
| Feature | Notes | |
|---|---|---|
.ber map loading |
✓ | Line-by-line via get_next_line |
| Rectangular map check | ✓ | Every row must have equal width |
| Character validation | ✓ | Only 1 0 P C E accepted |
| Required entity counts | ✓ | Exactly 1 P, exactly 1 E, at least 1 C |
| Border wall validation | ✓ | Outer frame must be walls |
| Playability check | ✓ | Flood fill verifies full reachability |
| Tile rendering with XPM | ✓ | Wall, floor, player, collectible, exit |
| Floor-first compositing | ✓ | Ensures consistent overlay on macOS and Linux |
| Movement + collision | ✓ | Arrow keys — target tile must be valid |
| Win condition | ✓ | Exit only triggers after all collectibles |
| ESC / window-close | ✓ | Both paths call clean shutdown |
| Key | Action |
|---|---|
↑ |
Move up |
↓ |
Move down |
← |
Move left |
→ |
Move right |
ESC |
Quit |
Raw keycodes (Linux MiniLibX)
Up: 65362 · Down: 65364 · Left: 65361 · Right: 65363 · ESC: 65307
A valid .ber map:
11111111111
10P00CC00E1
11111111111
Rules at a glance:
✓ Extension must be .ber
✓ Every row same width (rectangular)
✓ Fully enclosed by walls
✓ Exactly one P · exactly one E · at least one C
✗ Any other character → Error
so_long/
│
├── Makefile
├── so_long.h ← structs, prototypes, includes
├── so_long.c ← entry point and game loop
│
├── so_long_utils_00.c ← map loading and memory
├── so_long_utils_01.c ← validation helpers
├── so_long_utils_02.c ← rendering and tile drawing
├── so_long_utils_03.c ← movement and collision
├── so_long_mvp_utils.c ← flood fill / playability
├── ft_putnbr_nl.c ← move counter output
│
├── get_next_line/ ← line reader for the parser
├── maps/ ← .ber level files
├── textures/ ← XPM sprite assets
│
├── minilibx-linux/ ← MiniLibX Linux (X11)
├── minilibx_macos_opengl/ ← MiniLibX macOS OpenGL
└── minilibx_macos_metal/ ← MiniLibX macOS Metal (Apple Silicon)
git clone https://github.com/mobouifr/so_long.git
cd so_long
make
./so_long maps/map.berAlways launch from the project root — texture paths are relative (
textures/*.xpm).
| Rule | Effect |
|---|---|
make |
Compile so_long |
make clean |
Remove object files |
make fclean |
Remove objects and binary |
make re |
Full rebuild |
- MiniLibX documentation
man 2 open·man 2 read·man 2 close·man 3 malloc·man 3 free- 42 so_long subject guidelines
