42 Project | Graphics Programming & Game Development
Objective: Create a 2D game using MiniLibX graphics library where a player collects items and reaches an exit.
So Long is a graphics programming project that introduces game development using MiniLibX (a simplified X11 interface). The game involves navigating a map, collecting collectibles, and reaching the exit while avoiding obstacles.
- Graphics Programming: MiniLibX window management and image rendering
- Game Loop: Event handling, frame rendering, game state management
- Map Parsing: Reading and validating
.bermap files - Pathfinding: Validating map connectivity and reachability
- Sprite Management: Loading and displaying XPM images
- Animation: Sprite animation and movement (bonus)
- Game Logic: Collision detection, collectible tracking, win conditions
so_long/
├── src/
│ ├── so_long.c # Main game loop and initialization
│ ├── load_map.c # Map file parsing and loading
│ ├── validate_map.c # Map validation (walls, collectibles, exit)
│ ├── hook.c # Keyboard input handling
│ ├── animate.c # Animation system
│ ├── exit_game.c # Cleanup and exit handling
│ └── ... # Additional source files
├── maps/ # Game map files (.ber format)
├── sprites/ # XPM image files
├── ft_printf/ # Printf library for output
├── mlx/ # MiniLibX library (macOS)
├── mlx_linux/ # MiniLibX library (Linux)
└── Makefile # Build configuration
Key Components:
- Map Parser: Reads
.berfiles and validates structure - Renderer: Displays game map and sprites using MiniLibX
- Game Logic: Handles player movement, collisions, and win conditions
- Bonus: Enemy patrol, sprite animation, movement counter
- Map parsing from
.berfiles - Player movement (WASD or arrow keys)
- Collectible items
- Exit door (accessible after collecting all items)
- Map validation (walls, valid path)
- Window management and rendering
- Enemy patrol system
- Sprite animation
- Movement counter display
- Multiple map support
Maps are text files with the following characters:
1- Wall0- Empty space (walkable)P- Player starting positionC- CollectibleE- Exit
Requirements:
- Surrounded by walls (
1) - Exactly one player (
P) - At least one collectible (
C) - Exactly one exit (
E) - Valid path from player to exit and all collectibles
# Build so_long
make
# Run with a map
./so_long maps/map1.ber
# Build bonus version
make bonusControls:
W/↑- Move upS/↓- Move downA/←- Move leftD/→- Move rightESC- Exit game
- MiniLibX Integration: Window creation, image loading, event handling
- Map Validation: Ensures playable maps with valid paths
- Memory Management: Proper cleanup of images and resources
- Cross-platform: Supports both macOS and Linux MiniLibX
The project has been tested with:
- Various map configurations and sizes
- Edge cases (single collectible, large maps)
- Memory leak detection (AddressSanitizer/ASan)
- Input validation and error handling
Completed - Mandatory and bonus features implemented
This project demonstrates graphics programming skills and game development fundamentals using low-level graphics libraries.