Skip to content
jzelada97Public

About

2D top-down game in C using MiniLibX. Map parsing, flood fill validation, sprite animations and keyboard controls (42 School).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

so_long

A 2D top-down game written in C using MiniLibX (42 School graphics library). Navigate a map, collect all items, and reach the exit to win.

Gameplay


Features

  • Tile-based rendering with custom sprites (32x32px)
  • 6-frame player walk animation
  • Collectible tracking with dynamic exit unlock
  • Move counter displayed in terminal
  • Robust map validation (rectangular, walled, valid path via flood fill)
  • Clean memory management and error handling

Controls

Key Action
W Move up
A Move left
S Move down
D Move right
ESC Quit game

How It Works

Map Parsing & Validation

Before opening the window, the program:

  1. Validates the .ber file extension
  2. Reads the map line by line using get_next_line
  3. Checks that the map is rectangular and enclosed by walls (1)
  4. Validates characters: 0 (floor), 1 (wall), P (player), C (collectible), E (exit)
  5. Requires exactly 1 player, 1 exit, and at least 1 collectible
  6. Runs flood fill (DFS) from the player position to verify all collectibles and the exit are reachable

Game Loop

  • Each keypress attempts to move the player
  • Walls block movement
  • Stepping on C increments the collectible counter
  • When all collectibles are gathered, the exit opens (sprite changes)
  • Reaching the exit after collecting everything ends the game

Compilation

make          # compiles so_long
make clean    # removes object files
make fclean   # removes objects and binary
make re       # full recompile

Requires MiniLibX and X11 dev libraries (libXext, libX11) on Linux.


Usage

./so_long maps/map.ber

Map Format (.ber)

1111111111111
10010000000C1
10000C00P0001
1000000000E01
1111111111111
  • 1 = wall
  • 0 = empty space
  • P = player start
  • C = collectible
  • E = exit

Project Structure

so_long/
├── makefile
├── include/
│   ├── so_long.h
│   ├── map.h
│   ├── player.h
│   ├── game_init.h
│   ├── image_handler.h
│   ├── validate_map.h
│   ├── flood_fill.h
│   ├── exit_game.h
│   └── exit_with_error.h
├── src/
│   ├── main.c
│   ├── map.c
│   ├── player.c
│   ├── game_init.c
│   ├── image_handler.c
│   ├── validate_map.c
│   ├── flood_fill.c
│   ├── exit_game.c
│   └── exit_with_error.c
├── get_next_line/
├── libft/
├── printf/
├── maps/
│   └── map.ber
└── assets/
    └── jzelada.png

Built With

  • Language: C (C99)
  • Graphics: MiniLibX (X11)
  • Build: Make
  • Standard: 42 Norm compliant
  • Platform: Linux

Context

Developed as part of the 42 Madrid curriculum. The project focuses on graphics programming, event handling, memory management, and algorithm application (DFS for path validation).

About

2D top-down game in C using MiniLibX. Map parsing, flood fill validation, sprite animations and keyboard controls (42 School).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages