From ff7d60ad044e98e1e2e14170b5804d141856a949 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 10 Jun 2024 16:39:55 +0200 Subject: Cleanup --- src/draw.c | 69 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 28 deletions(-) (limited to 'src/draw.c') diff --git a/src/draw.c b/src/draw.c index 5284d74..2c525dc 100644 --- a/src/draw.c +++ b/src/draw.c @@ -6,7 +6,7 @@ /* By: dkaiser 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); } -- cgit v1.2.3