diff options
| author | Dominik Kaiser | 2024-06-10 16:40:28 +0200 |
|---|---|---|
| committer | GitHub | 2024-06-10 16:40:28 +0200 |
| commit | 568827dc74eb4e2a7719d7cfbd48083facf85cc3 (patch) | |
| tree | dd896d064a49bb399b7c942fde49ae0bf892263b /src/draw.c | |
| parent | 7b230503231e154c5400413b4f9b87dd6fcd8304 (diff) | |
| parent | ff7d60ad044e98e1e2e14170b5804d141856a949 (diff) | |
| download | so_long-master.tar.gz so_long-master.zip | |
Map checker
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 69 |
1 files changed, 41 insertions, 28 deletions
@@ -6,7 +6,7 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/09 17:58:23 by dkaiser #+# #+# */ -/* Updated: 2024/05/20 20:10:15 by dkaiser ### ########.fr */ +/* Updated: 2024/06/10 16:37:51 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,42 +14,29 @@ #include "libft.h" #include "so_long.h" -int draw(t_game *game) +static void draw_walls_and_collectibles(t_game *game); +static void setup_images(t_game *game, mlx_image_t **wall_image); +static void draw_exit(t_game *game); + +void draw(t_game *game) { game->player.img->instances[0].x = game->player.position.x; game->player.img->instances[0].y = game->player.position.y; - return (0); } -void draw_exit(t_game *game) +void draw_map(t_game *game) { - mlx_texture_t *exit_texture; - mlx_image_t *exit_image; - t_vector pos; - - exit_texture = mlx_load_png("textures/exit.png"); - exit_image = mlx_texture_to_image(game->mlx, exit_texture); - mlx_resize_image(exit_image, game->map.tile_size.x, game->map.tile_size.y); - pos = grid_to_screen_pos(game->map.exit_tile, game->map.tile_size); - mlx_image_to_window(game->mlx, exit_image, pos.x, pos.y); + draw_walls_and_collectibles(game); + draw_exit(game); } -int draw_walls(t_game *game) +static void draw_walls_and_collectibles(t_game *game) { - int x; - int y; - mlx_texture_t *wall_texture; - mlx_image_t *wall_image; - mlx_texture_t *collectible_texture; + int x; + int y; + mlx_image_t *wall_image; - wall_texture = mlx_load_png("textures/wall.png"); - wall_image = mlx_texture_to_image(game->mlx, wall_texture); - collectible_texture = mlx_load_png("textures/collectible.png"); - game->map.collectible_img = mlx_texture_to_image(game->mlx, collectible_texture); - mlx_resize_image(wall_image, 48, 48); - mlx_resize_image(game->map.collectible_img, 48, 48); - game->map.tile_size.x = 48; - game->map.tile_size.y = 48; + setup_images(game, &wall_image); x = 0; while (x < game->map.grid_size.x) { @@ -66,5 +53,31 @@ int draw_walls(t_game *game) } x++; } - return (0); +} + +static void setup_images(t_game *game, mlx_image_t **wall_image) +{ + mlx_texture_t *wall_texture; + mlx_texture_t *collectible_texture; + + wall_texture = mlx_load_png("textures/wall.png"); + *wall_image = mlx_texture_to_image(game->mlx, wall_texture); + collectible_texture = mlx_load_png("textures/collectible.png"); + game->map.collectible_img = mlx_texture_to_image(game->mlx, + collectible_texture); + mlx_resize_image(*wall_image, 48, 48); + mlx_resize_image(game->map.collectible_img, 48, 48); +} + +static void draw_exit(t_game *game) +{ + mlx_texture_t *exit_texture; + mlx_image_t *exit_image; + t_vector pos; + + exit_texture = mlx_load_png("textures/exit.png"); + exit_image = mlx_texture_to_image(game->mlx, exit_texture); + mlx_resize_image(exit_image, game->map.tile_size.x, game->map.tile_size.y); + pos = grid_to_screen_pos(game->map.exit_tile, game->map.tile_size); + mlx_image_to_window(game->mlx, exit_image, pos.x, pos.y); } |
