Skip to content

anarita99/so_long

Repository files navigation

This project has been created as part of the 42 curriculum by adores.

🐱🐟 so_long

Description

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.

Instructions

Compilation

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 mlx

Build the game:

make

Note: If you run make without building the mlx library first, the linker will fail.

Running the Game

Run the game by providing a valid .ber map file:

./so_long maps/map.ber

Example:

./so_long maps/valid_map.ber

Gameplay & Controls

Objective: 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.

Controls

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.

Features

  • 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

Map Format

Maps use the .ber extension and must follow specific rules:

Valid Characters

Symbol Meaning
1 Wall
0 Empty floor
P Player start position (Cat) 🐱
C Collectible (Fish) 🐟
E Exit

Map Requirements

  • 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

Example Map

111111111111
100000000001
10P000C00001
1000111110C1
1C0000000001
100000000E01
111111111111

Error Handling

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

Project Structure

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

Resources

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:

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! 🐱🐟

About

A 2D game built with MiniLibX where a cat collects fish to unlock the exit, featuring sprite animation and map validation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors