Skip to content

Latest commit

 

History

35 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

So Long - 2D Game with MiniLibX

42 Project | Graphics Programming & Game Development
Objective: Create a 2D game using MiniLibX graphics library where a player collects items and reaches an exit.


Overview

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.


Skills Demonstrated

  • Graphics Programming: MiniLibX window management and image rendering
  • Game Loop: Event handling, frame rendering, game state management
  • Map Parsing: Reading and validating .ber map 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

Project Structure

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 .ber files 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

Game Features

Mandatory

  • Map parsing from .ber files
  • Player movement (WASD or arrow keys)
  • Collectible items
  • Exit door (accessible after collecting all items)
  • Map validation (walls, valid path)
  • Window management and rendering

Bonus

  • Enemy patrol system
  • Sprite animation
  • Movement counter display
  • Multiple map support

Map Format (.ber)

Maps are text files with the following characters:

  • 1 - Wall
  • 0 - Empty space (walkable)
  • P - Player starting position
  • C - Collectible
  • E - 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

Compilation & Usage

# Build so_long
make

# Run with a map
./so_long maps/map1.ber

# Build bonus version
make bonus

Controls:

  • W / - Move up
  • S / - Move down
  • A / - Move left
  • D / - Move right
  • ESC - Exit game

Technical Highlights

  • 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

Testing

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

Project Status

Completed - Mandatory and bonus features implemented


This project demonstrates graphics programming skills and game development fundamentals using low-level graphics libraries.

About

2D game built with MiniLibX | Map parsing, player movement, collectibles, and sprite animation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages