summaryrefslogtreecommitdiff
path: root/src/draw.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-06-10 16:39:55 +0200
committerDominik Kaiser2024-06-10 16:39:55 +0200
commitff7d60ad044e98e1e2e14170b5804d141856a949 (patch)
treedd896d064a49bb399b7c942fde49ae0bf892263b /src/draw.c
parent81bfaf91dedc75b758a9057a2b7c23adc5a68e93 (diff)
downloadso_long-ff7d60ad044e98e1e2e14170b5804d141856a949.tar.gz
so_long-ff7d60ad044e98e1e2e14170b5804d141856a949.zip
Cleanup
Diffstat (limited to 'src/draw.c')
-rw-r--r--src/draw.c69
1 files changed, 41 insertions, 28 deletions
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 <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);
}