This project has been created as part of the 42 curriculum by adores.
so_long is a small 2D game project that introduces fundamental concepts of graphic design using the MiniLibX library. The objective is to create a playable game where the player controls a cat collecting fish to unlock the exit. This project covers topics such as window management, event handling, texture rendering, sprite animation, map validation, and basic game logic.
Prerequisites: Before running the game, ensure you have the necessary dependencies for MiniLibX (on Linux, this usually includes libxext-dev and libbsd-dev).
Build the graphics library:
make mlxBuild the game:
makeNote: If you run make without building the mlx library first, the linker will fail.
Run the game by providing a valid .ber map file:
./so_long maps/map.berExample:
./so_long maps/valid_map.berObjective: Help the cat collect all the fish (C) on the map. Once all fish are collected, the exit (E) opens. Reaching the exit wins the game.
| Key | Action |
|---|---|
W |
Move Up |
A |
Move Left |
S |
Move Down |
D |
Move Right |
ESC |
Close Game |
Move Counter: The current number of moves is printed to the shell as you play.
- Animated Sprites: The player (cat) has idle animations and directional walking animations (up, down, left, right)
- Map Validation: Comprehensive checks for map format, walls, collectibles, and path validity
- Flood Fill Algorithm: Ensures all collectibles and the exit are reachable
- Memory Management: All images, windows, and map memory are cleanly freed upon exit (no leaks)
- Error Handling: Clear error messages for invalid maps or game states
Maps use the .ber extension and must follow specific rules:
| Symbol | Meaning |
|---|---|
1 |
Wall |
0 |
Empty floor |
P |
Player start position (Cat) 🐱 |
C |
Collectible (Fish) 🐟 |
E |
Exit |
- Must be rectangular
- Surrounded by walls (
1) - Contains exactly one player (
P) - Contains exactly one exit (
E) - Contains at least one collectible (
C) - Valid path must exist from the player to all collectibles and the exit
111111111111
100000000001
10P000C00001
1000111110C1
1C0000000001
100000000E01
111111111111
The program validates maps and provides clear error messages for:
- Invalid map format (not rectangular)
- Missing or duplicate player/exit
- No collectibles present
- Map not surrounded by walls
- Unreachable collectibles or exit
- Invalid characters in the map
so_long/
├── ft_printf/ # Custom printf implementation
├── get_next_line/ # GNL implementation for reading maps
├── libft/ # Standard helper library
├── maps/ # .ber map files
├── textures/ # .xpm sprite files (cat, fish, walls)
├── cat.c # Sprite animation logic
├── check_map.c # Wall and element validation
├── check_map2.c # Flood fill & pathfinding checks
├── copy_map.c # Map duplication utility
├── for_main.c # Image loading & main loop hooks
├── free_things.c # Clean exit & memory management
├── initiate.c # Structure initialization
├── keys.c # Movement & gameplay logic
├── map.c # Map reading & rendering
├── so_long.c # Main entry point
├── so_long.h # Header file with prototypes
└── Makefile # Build automation
The main resource that contributed to my understanding of this project was discussing its requirements and challenges with my colleagues.
Additional references that were helpful include:
- so_long Map Maker - benbohle
- MiniLibX Documentation - 42docs
- Building Your First 2D Game in C - Medium
AI tools were used to assist with the writing and structuring of this README file.
Made with ❤️ and ☕ at 42
Go help that cat get some fish! 🐱🐟