{"id":28042325,"url":"https://github.com/nabilac27/42-so_long","last_synced_at":"2025-05-11T14:26:08.986Z","repository":{"id":285542909,"uuid":"928975359","full_name":"nabilac27/42-so_long","owner":"nabilac27","description":"This project is a small 2D game with MLX Library. I learned about window management, event handling, textures, sprites, tiles, etc.","archived":false,"fork":false,"pushed_at":"2025-04-10T02:13:18.000Z","size":3706,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T03:23:13.528Z","etag":null,"topics":["2d-game","game-loop","graphics","linked-list","rendering","sprites","textures","tiles"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nabilac27.png","metadata":{"files":{"readme":"docs/README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-07T15:26:31.000Z","updated_at":"2025-04-10T02:13:22.000Z","dependencies_parsed_at":"2025-04-10T03:33:23.232Z","dependency_job_id":null,"html_url":"https://github.com/nabilac27/42-so_long","commit_stats":null,"previous_names":["nabilac27/so_long","nabilac27/42-so_long"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabilac27%2F42-so_long","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabilac27%2F42-so_long/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabilac27%2F42-so_long/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nabilac27%2F42-so_long/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nabilac27","download_url":"https://codeload.github.com/nabilac27/42-so_long/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253578779,"owners_count":21930599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d-game","game-loop","graphics","linked-list","rendering","sprites","textures","tiles"],"created_at":"2025-05-11T14:26:08.484Z","updated_at":"2025-05-11T14:26:08.970Z","avatar_url":"https://github.com/nabilac27.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **so_long**\nThe **so_long** project is a 2D game created using the **[MLX42 Library](https://github.com/codam-coding-college/MLX42)** library,\n\nwhere the player navigates through a map collecting items and reaching an exit. \n\nThe game involves rendering, movement, and collision detection.\n\n## **Key Concepts**\n\n- **[MLX42 Library](https://github.com/codam-coding-college/MLX42)**: Used for rendering graphics, handling user input, and managing the game window.\n\n- **Game Loop**: The loop updates the game state, renders graphics, and checks player input.\n\n- **Map Parsing**: The map is read from a file and checked for walls, the player, the exit, and collectibles.\n\n- **Player Movement**: The player moves using keyboard inputs, and the screen is updated accordingly.\n\n- **Collectibles \u0026 Exit**: The player collects items, which unlock the exit when all items are gathered.\n\n\n## How to Run\n\nTo run the project, follow these steps:\n\n1. Compile the program: `make`.\n   ```bash\n    $ make\n    ```\n2.  run the game, use the following format: `./so_long map.ber`.\n    ```bash\n    $ ./so_long map.ber\n    ```\n3. Rebuild the Project: `make re`.\n    ```bash\n    $ make re\n    ```\n\n---\n   \n\n## **Functions Overview**\n\n| **Function**                            | **Description** |\n|-----------------------------------------|-----------------|\n| `check_args_map(int argc, char **argv, t_game *game)` | Validates the arguments passed to the program and prepares the game. |\n| `game_render(t_game *game)`             | Renders the game elements to the screen. |\n| `check_collect_exit(t_game *game)`      | Checks if all collectibles are collected and the exit can be accessed. |\n| `game_loop(t_game *game)`               | Main loop of the game that handles game events and updates. |\n| `free_2d(char **array)`                 | Frees a 2D array used for map storage. |\n| `parse_map(t_game *game, char *map_name)` | Parses the map file to extract the layout. |\n| `read_map(t_game *game, char *map_name)` | Reads the map file into the game structure. |\n| `read_line(t_game *game, char *line, int i)` | Reads a single line from the map file. |\n| `check_map(t_game *game)`               | Validates the parsed map to ensure it's correct. |\n| `check_valid_map(t_game *game, char c, int y, int x)` | Checks if the map contains valid characters. |\n| `start_render(t_game *game)`            | Starts the rendering process for the game window. |\n| `read_textures(t_game *game)`           | Loads textures needed for the game environment. |\n| `read_mlx_to_image(t_game *game)`      | Converts loaded textures into images that can be displayed. |\n| `dup_map(t_game *game)`                 | Duplicates the map for internal processing. |\n| `flood_fill(t_game *game, int x, int y, char c)` | Ensures there are no unreachable areas in the map. |\n| `render_tile_img(void *param)`          | Renders a tile's image to the screen. |\n| `render_map(t_game *game)`              | Renders the entire map to the screen. |\n| `render_tile(t_game *game, int x, int y)` | Renders a specific tile at coordinates (x, y). |\n| `tile_img_to_img(mlx_image_t *img, mlx_image_t *tile_img, int x, int y)` | Converts tile images into a format for the game window. |\n| `pixel(mlx_image_t *img, uint32_t x, uint32_t y)` | Retrieves the pixel at coordinates (x, y) in the image. |\n| `handle_key(mlx_key_data_t keydata, void *param)` | Handles key press events for player movement. |\n| `move_key(t_game *game, int x, int y)`  | Moves the player to a new position based on key input. |\n\n\n\n\n## **MLX42 Functions Overview**\n\n| **Step**                   | **Function**                | **Description**                                                                 |\n|----------------------------|-----------------------------|---------------------------------------------------------------------------------|\n| **Initialization**       | `mlx_init`                  | Initializes the MLX window with the specified size and window name.             |\n| **Image Creation**       | `mlx_new_image`             | Creates a new image with the specified width and height.                        |\n| **Game Loop \u0026 Input**    | `mlx_loop_hook`             | Registers a function to be called every time the game loop runs.                |\n|                            | `mlx_key_hook`              | Registers a function to handle keyboard input during the game loop.             |\n| **Settings**             | `mlx_set_setting`           | Enables or disables image stretching for window rendering.                      |\n| **Event Loop**           | `mlx_loop`                  | Starts the MLX event loop, rendering the window and handling events.            |\n| **Termination \u0026 Cleanup**| `mlx_terminate`             | Terminates the MLX library and frees associated resources.                      |\n|                            | `mlx_close_window`          | Closes the MLX window.                                                         |\n| **Image and Pixel Handling** | `mlx_put_pixel`          | Places a pixel with the specified color at coordinates in the image.            |\n|                            | `mlx_image_to_window`       | Renders the image to the game window at position (0, 0).                        |\n|                            | `mlx_load_png`              | Loads a PNG texture from the specified path.                                    |\n|                            | `mlx_texture_to_image`      | Converts the texture into an image that can be rendered by MLX.                 |\n| **Key Data Structure**      | `mlx_key_data_t`            | Data structure used for key event handling, containing key code and state.     |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabilac27%2F42-so_long","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnabilac27%2F42-so_long","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnabilac27%2F42-so_long/lists"}