So Long is the first graphical project of the 42 Cursus. The objective is to create a simple 2D game where the player navigates a map, collecting items scattered throughout the level to unlock the exit and complete the game.
This project serves as a practical introduction to using external libraries, particularly focusing on graphical rendering, window management, and event handling.
-
Parsing:
Verifies if the arguments are correct.
Checks the .ber file by checking forvalid characters
,correct character counts
,proper shape
,complete enclosure
, andvalid path
, while simultaneously storing information in the struct in the process. -
Initialization:
Uses
get_next_line
to convert the .ber file into an array of string.
Initializes the MLX library and creates thedisplay window
.
Loads and prepares theinit_sprites
for rendering. -
Execution:
Starts the rendering process to display the walls, floors, collectibles, exit, player tiles, and the in-game text.
Configures the main game loop to handle user input and game events.
- Run
make
to compile the program. - Run
make re
to recompile everything. - Run
./so_long <map_path>
to execute the program.
Maps can be found in the maps
folder, and has to be in the .ber
extension.
Char | Entity |
---|---|
1 |
Wall |
0 |
Floor |
P |
Player |
C |
Collectible |
E |
Exit |
H |
Horizontal Enemy |
V |
Vertical Enemy |
Only the specified characters (e.g., walls, floors, etc.).
Maps must be rectangular and enclosed (player cannot move outside the map area).
Maps must contain exactly one player, one exit, and at least one collectible.
It must be possible to reach all collectible(s) and the exit from the starting position.
- Run
make clean
to remove every object files. - Run
make fclean
to remove every object files, including the executable.
-
get_next_line
- Slightly modified version of get_next_line. -
init_map
- Initializes the struct, allocates, and assigns the map file as an array of strings. -
free_map
-
is_valid_char
- Checks if the map file contains only correct characters (1, 0, P, C, E). -
is_valid_count
- Checks and counts if there is one player, collectibles, and one exit. -
is_valid_shape
- Checks if the map is rectangular and counts its width and height. -
is_valid_close
- Checks if the map is enclosed with '1' characters on all sides. -
is_valid_path
- Checks if the map is possible (if the player can reach all collectibles and exit) using the Flood Fill algorithm.
-
init_display
- Acts as a main for the MLX's display part. -
init_sprites
- Calls every functions to initialize sprites.
-
display_walls
- Draws wall tiles according to their positions and neighboring tiles. -
init_wall_sprites
- Initializes wall sprites. -
which_inner_wall
- Finds the wall sprite by checking its adjacent walls. -
which_outer_wall
- Finds the wall sprite by checking its diagonal walls.
-
display_floors
- Draws floor tiles according to their positions with a pseudo-random pattern. -
init_floor_sprites
- Initializes floor sprites.
-
init_player_sprites
- Initializes player sprites.
-
handle_keypress
- Runs every time a key is pressed. -
player_move
- Manages player movements. -
enemy_move
- Manages enemy movements. -
handle_text
- Display text in the game window. -
close_window
- Frees everything and ends the program.
-
ft_printf
- Slightly modified version of ft_printf. -
ft_putchar
- Prints a character. -
ft_putstr
- Prints a string. -
ft_puterr
- Prints a string and exit the program. -
ft_putnbr
- Prints an integer. -
ft_putuni
- Prints an unsigned integer. -
ft_strchr
- Searches for a character in a string. -
ft_strcmp
- Checks for a difference between two strings. -
ft_strdup
- Duplicates and allocates a string. -
ft_strjoin
- Concatenates two strings. -
ft_strlen
- Returns the length of a string. -
ft_itoa
- Converts an integer into a string.