🧱 My 7th project in the 42 Common Core
(≖_≖ ) good GOD …the horrors I witnessed.
- 💡 MiniLibX: Basic graphics in C (rendering, input, events)
- 🗺️ Map parsing: Read & validate
.ber
maps - 🧍 Game logic: Move the player, collect items, reach the exit
- 🧭 Pathfinding: Use DFS/BFS to validate solvability
- 🧼 Memory management: Avoiding leaks like your life depends on it
- 💀 Bonus: Enemies, animations, on-screen counters (for the brave)
Create a 2D tile-based game where a player:
- Navigates a map using WASD
- Collects all C (collectibles)
- Reaches the E (exit) only when all C are collected
- Avoids walking into 1 (walls)
so\_long/
├── src/
├── include/
│ ├── so\_long.h
│ ├── libft.h
│ └── ft\_printf.h
├── lib/
│ ├── minilibx-linux/
│ ├── libft/
│ └── ft\_printf/
├── assets/
├── maps/
├── main.c
└── Makefile
Maps are built from characters:
Char | Meaning |
---|---|
1 |
Wall |
0 |
Empty/floor |
C |
Collectible |
E |
Exit |
P |
Player start |
✅ Must be rectangular
✅ Enclosed by walls
✅ 1 player P
, 1 exit E
, at least 1 C
✅ All collectibles and exit must be reachable
W
→ Move upA
→ Move leftS
→ Move downD
→ Move rightESC
→ Quit game
- Render map to window
- Capture keypress events
- Move player (check walls)
- Pick up collectibles
- Only allow exit when all
C
are collected - Track and display move count
Check that all collectibles and the exit can be reached from the player’s position.
Common approach:
- Duplicate the map
- Use DFS/BFS to traverse from
P
- Check if you reached all
C
andE
You can use your own sprite art if you're a digital illustrator like yours truly (chef’s kiss), or get free assets here I guess 🙄 :
Make sure images are .xpm
(MiniLibX requirement).
- Linux or WSL
- MiniLibX (included in repo)
make
./so_long maps/map1.ber
Feature | Status |
---|---|
🧟 Enemy patrols | ❓ |
🎞️ Animations | ❓ |
🎯 In-window counter | ❓ |
-
.ber
map parsing is airtight - DFS/BFS path validation is solid
- MiniLibX window displays correctly
- Player movement works with WASD
- Exit opens only after collecting all
C
- Terminal move counter prints correctly
- No memory leaks (test with
valgrind
) - Clean
Makefile
with all rules - ESC and X button exit cleanly
- Bonus features (if implemented) work bug-free
- Git repo is clean, commented, and pushed
11111
1P0C1
10001
1C0E1
11111
valgrind ./so_long maps/test.ber
Don’t forget:
- Free the map array
- Free textures and MLX pointers
- Close window and destroy display
“If you stare into the abyss of MiniLibX long enough, the abyss starts leaking memory.”
Stay hydrated. Comment your code.
And may your .ber
files never segfault again.
Made with 💀, 🎮 and maybe some tears by your local wizard