
So Long
2D Game Development
A 2D game developed in C using the MiniLibX graphics library, featuring player movement, collectible items, enemy mechanics, and map-based gameplay.
Key Features
Player Movement
Smooth player character movement with keyboard input handling and collision detection system.
Collectible System
Implemented collectible items that players must gather before accessing the exit, with progress tracking.
Map Parsing
Dynamic map loading from text files with validation for proper game element placement and path checking.
Win Condition
Game completion logic requiring collection of all items before exit becomes accessible.
Development Journey
Graphics Setup
Set up MiniLibX graphics library and implemented basic window management with sprite loading and rendering system.
Game Mechanics
Implemented player movement, collision detection, and collectible system with proper game state management.
Map System
Developed map parsing and validation system with flood-fill algorithm for ensuring map completability.
Challenges & Solutions
Graphics Library Integration
Learning and integrating MiniLibX library for graphics rendering and event handling in a game environment.
Studied MiniLibX documentation and implemented wrapper functions for easier graphics management with proper error handling.
Map Validation
Ensuring maps are valid with proper walls, single exit, and collectibles placement while guaranteeing game completability.
Developed comprehensive map parsing with flood-fill algorithm to verify map accessibility and proper game element validation.
Game State Management
Managing complex game state including player position, collectibles, and win conditions efficiently.
Implemented structured game state management with proper data organization and efficient update mechanisms.
// Game structure definition
typedef struct s_game
{
void *mlx;
void *win;
void *img_player;
void *img_wall;
void *img_collect;
void *img_exit;
char **map;
int map_width;
int map_height;
int player_x;
int player_y;
int collectibles;
int moves;
} t_game;
// Main game loop
int game_loop(t_game *game)
{
render_map(game);
render_player(game);
render_ui(game);
return (0);
}
// Player movement function
int move_player(int keycode, t_game *game)
{
int new_x = game->player_x;
int new_y = game->player_y;
if (keycode == 13 || keycode == 126) // W or UP
new_y--;
else if (keycode == 1 || keycode == 125) // S or DOWN
new_y++;
else if (keycode == 0 || keycode == 123) // A or LEFT
new_x--;
else if (keycode == 2 || keycode == 124) // D or RIGHT
new_x++;
else if (keycode == 53) // ESC
exit_game(game);
if (is_valid_move(game, new_x, new_y))
{
if (game->map[new_y][new_x] == 'C')
{
game->collectibles--;
game->map[new_y][new_x] = '0';
}
else if (game->map[new_y][new_x] == 'E' && game->collectibles == 0)
{
ft_printf("Congratulations! You won in %d moves!\n", ++game->moves);
exit_game(game);
}
game->player_x = new_x;
game->player_y = new_y;
game->moves++;
ft_printf("Moves: %d\n", game->moves);
}
return (0);
}