Skip to content

A simple 2D game built with MiniLibX, focusing on low-level graphics programming. Part of the 42 Common Core curriculum.

License

Notifications You must be signed in to change notification settings

Vpekdas/so_long

Repository files navigation

so_long

Screenshots

Screenshot Screenshot2 Screenshot3 Screenshot4 Screenshot5

Gameplay.mp4

Table of Contents

  1. Description
  2. Installation
  3. Run
  4. Credits
  5. Contributing
  6. License

Description

so_long is a project from the 42 Common Core curriculum designed to introduce students to low-level graphics programming using the MiniLibX graphics API. The objective is to build a simple 2D game where the player must collect items and reach the exit while avoiding enemies.

As part of the 42 curriculum, this project comes with strict coding guidelines:

  • The standard C library is forbidden, requiring the use of custom code for all tasks.
  • A strict rule of 5 functions per file and 25 lines per function is enforced.
  • There are restrictions such as no assignments on the same line and a focus on clean, maintainable code.

This project provides hands-on experience with low-level graphical programming and reinforces good coding practices under challenging constraints.

Purpose

The goal of this game is to collect all the collectibles and defeat or avoid enemies to reach the exit safely. Key features include:

  • Gravity-based movement
  • Collision solver for map and object interactions
  • Smart enemies that:
    • Dodge projectiles
    • Track the player's position
    • Launch attacks
  • Animated sprites for:
    • Player
    • Enemies
    • Collectibles
    • Projectiles and particles
  • Parallax background for visual depth
  • Interactive doors that open when all collectibles are gathered

Controls

Controls Actions
W or Jump
A or Move Left
S or Dash Down
D or Move Right
Space Throw projectiles
ESC or click the X in the top-right corner Exit the game

Technologies used

  • C language.
  • Make.

Challenges and Future Features

The main challenges were learning how MiniLibX works, creating a window, drawing pixels and sprites, implementing a game loop and keyboard input, handling game physics like gravity and collisions, experimenting with visual effects such as parallax scrolling and cave darkening, and developing an algorithm to ensure that the map is completable.

I'm not planning to add new features.

Installation

  • Ensure you have a C compiler installed, such as Clang or GCC
clang --version
gcc --version
  • Ensure you have installed Make to build the project
make --version
  • Install Necessary Packages: Certain packages are required to run the game. You can install them using your distribution's package manager. For example, on Ubuntu, you can use the following command:

  • X11 include files (package xorg)

  • XShm extension must be present (package libxext-dev)

  • Utility functions from BSD systems - development files (package libbsd-dev)

sudo apt install xorg libxext-dev libbsd-dev

Warning: This game can only work in Unix systems since the functions used and the minilib functions called needs X11, in windows you can install WSL and install packages. In Macos, it wont works.

  • Windows: You can install WSL (Windows Subsystem for Linux) and set up the necessary packages to run the game.
  • MacOS: Unfortunately, the game won't work on macOS as it doesn't support the necessary X11 functions natively.

Run

  1. Build the project:
make
  1. This will create a ./so_long binary.

  2. Run the program with the following arguments:

./so_long [maps]

Map Customization

The maps for the game are stored in files with the .ber extension. These are essentially text files where the game’s layout and elements are defined. You can find our pre-configured maps in the assets/maps directory.

When creating a custom map, be sure to follow these rules to ensure proper functionality:

1. Player Boundaries

Ensure that the player cannot go outside the map's boundaries. If the player can escape the map, the algorithm will refuse the map and display an error.

Map Layout:
  • 1 Refers to walls in the map, which the player cannot pass through.
  • 0 Refers to empty spaces where the player can walk.
  • D: Refers to a door in the map. There must be only one in the map.
  • C: Refers to collectibles. There must be at least one in the map.
  • P: Refers to player. There must be only one in the map.

Credits

Special thanks to the following individuals and assets for their contributions to this project:

  • FirePh0enix: Thank you for explaining the basics of sprite drawing, key detection, collision calculation, gravity management, parallax effects, and player camera coding.
  • Fidwig: Special thanks for coding the vignette, optimizing falling collision, and initiating pathfinding with the max jump factor.
  • ForAbby-X: Gratitude for providing references in 2D game development and sharing ideas to enhance the game's immersion.
  • Ludenc: Providing the Cave background and tileset.
  • Pixel Frog: Supplying player, enemy, and bomb animated textures.
  • Totuslotus: Contributing animated coin textures.

Contributing

To report issues, please create an issue here: issue tracker.

If you'd like to contribute, please follow the steps outlined in CONTRIBUTING.md.

License

This project is licensed under the MIT License.

Third-Party Licenses

  • MiniLibX, provided by École 42, is included in this project and is licensed under the BSD 2-Clause License.
    Please refer to the linked file for full license terms.

About

A simple 2D game built with MiniLibX, focusing on low-level graphics programming. Part of the 42 Common Core curriculum.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Languages