A simple 2D game developed as part of the 42 School curriculum. The player must collect all collectibles on the map and reach the exit with the minimum number of moves possible.
So Long is a small 2D game where the player navigates through a map, collecting coins and finding the exit. The project focuses on working with textures, sprites, and basic game mechanics using the MiniLibX graphics library.
This project is part of the 42 School common core curriculum and helps students understand:
- Window management
- Event handling
- Texture rendering
- Basic game loop implementation
- Map validation and pathfinding
- Smooth movement - Move your character with arrow keys or WASD
- Collectibles - Gather all coins before the exit opens
- Animated sprites - Coin animations for visual appeal
- Move counter - Track your efficiency with a movement counter
- Map validation - Comprehensive map checking for valid paths
- Error handling - Clear error messages for invalid maps or inputs
- GCC or Clang compiler
- Make
- X11 development libraries (for MiniLibX)
- Linux/Unix operating system
sudo apt-get update
sudo apt-get install gcc make xorg libxext-dev libbsd-dev- Clone the repository:
git clone https://github.com/ccakirr/so_long.git
cd so_long- Compile the project:
makeThis will create the so_long executable.
Run the game with a map file:
./so_long maps/test_map.berThe project includes several test maps in the maps/ directory:
test_map.ber- Small test mapeasy_map_to_test.ber- Easy levelmap_42.ber- Medium difficultybig_map.ber- Larger challenging map
Maps must be rectangular and saved with a .ber extension. They consist of the following characters:
| Character | Meaning |
|---|---|
1 |
Wall |
0 |
Empty space |
C |
Collectible (coin) |
E |
Exit |
P |
Player starting position |
- The map must be rectangular
- The map must be surrounded by walls (1s)
- Must contain:
- Exactly one exit (E)
- Exactly one starting position (P)
- At least one collectible (C)
- Must have a valid path from the player to all collectibles and the exit
111111111
100000001
1C0E0P0C1
100000001
111111111
| Key | Action |
|---|---|
W / ↑ |
Move up |
A / ← |
Move left |
S / ↓ |
Move down |
D / → |
Move right |
ESC |
Exit game |
so_long/
├── src/ # Source files
│ ├── main.c
│ ├── game_init.c
│ ├── map_parse.c
│ ├── validate_map.c
│ ├── floodfill.c
│ ├── load_textures.c
│ ├── render.c
│ ├── handle_input.c
│ └── exit_game.c
├── inc/ # Header files
│ └── so_long.h
├── utils/ # Utility functions
├── maps/ # Map files (.ber)
├── assets/ # Game textures/sprites
├── my_libs/ # External libraries
│ ├── minilibx-linux/
│ ├── get_next_line/
│ └── ft_printf/
├── Makefile
└── README.md
make- Compile the projectmake clean- Remove object filesmake fclean- Remove object files and executablemake re- Recompile the project from scratchmake norm- Check code against 42 norminette standards
To test the game with different scenarios:
- Valid map:
./so_long maps/test_map.ber - Invalid map (no exit): The program will display an error
- Invalid map (not rectangular): The program will display an error
- No valid path: The program will check and reject maps where collectibles or exit are unreachable
Error: "Invalid map file!"
- Check that your map follows all the rules listed above
- Ensure the map is rectangular
- Verify all collectibles and the exit are reachable
Error: "Usage: ./so_long map_file.ber"
- You need to provide a map file as an argument
Compilation errors
- Make sure all dependencies are installed
- Check that you're using a compatible operating system (Linux/Unix)
This project is part of the 42 School curriculum and is meant for educational purposes.
Caner Çakır
- GitHub: @ccakirr
- 42 School for the project specifications
- MiniLibX team for the graphics library
- Fellow 42 students for testing and feedback
Made with ❤️ at 42 Istanbul