A 2D top-down game written in C using MiniLibX (42 School graphics library). Navigate a map, collect all items, and reach the exit to win.
- Tile-based rendering with custom sprites (32x32px)
- 6-frame player walk animation
- Collectible tracking with dynamic exit unlock
- Move counter displayed in terminal
- Robust map validation (rectangular, walled, valid path via flood fill)
- Clean memory management and error handling
| Key | Action |
|---|---|
W |
Move up |
A |
Move left |
S |
Move down |
D |
Move right |
ESC |
Quit game |
Before opening the window, the program:
- Validates the
.berfile extension - Reads the map line by line using
get_next_line - Checks that the map is rectangular and enclosed by walls (
1) - Validates characters:
0(floor),1(wall),P(player),C(collectible),E(exit) - Requires exactly 1 player, 1 exit, and at least 1 collectible
- Runs flood fill (DFS) from the player position to verify all collectibles and the exit are reachable
- Each keypress attempts to move the player
- Walls block movement
- Stepping on
Cincrements the collectible counter - When all collectibles are gathered, the exit opens (sprite changes)
- Reaching the exit after collecting everything ends the game
make # compiles so_long
make clean # removes object files
make fclean # removes objects and binary
make re # full recompileRequires MiniLibX and X11 dev libraries (
libXext,libX11) on Linux.
./so_long maps/map.ber1111111111111
10010000000C1
10000C00P0001
1000000000E01
1111111111111
1= wall0= empty spaceP= player startC= collectibleE= exit
so_long/
├── makefile
├── include/
│ ├── so_long.h
│ ├── map.h
│ ├── player.h
│ ├── game_init.h
│ ├── image_handler.h
│ ├── validate_map.h
│ ├── flood_fill.h
│ ├── exit_game.h
│ └── exit_with_error.h
├── src/
│ ├── main.c
│ ├── map.c
│ ├── player.c
│ ├── game_init.c
│ ├── image_handler.c
│ ├── validate_map.c
│ ├── flood_fill.c
│ ├── exit_game.c
│ └── exit_with_error.c
├── get_next_line/
├── libft/
├── printf/
├── maps/
│ └── map.ber
└── assets/
└── jzelada.png
- Language: C (C99)
- Graphics: MiniLibX (X11)
- Build: Make
- Standard: 42 Norm compliant
- Platform: Linux
Developed as part of the 42 Madrid curriculum. The project focuses on graphics programming, event handling, memory management, and algorithm application (DFS for path validation).
