summaryrefslogtreecommitdiff
path: root/src/draw.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-29 13:11:19 +0200
committerGitHub2024-05-29 13:11:19 +0200
commit7b230503231e154c5400413b4f9b87dd6fcd8304 (patch)
treeaaa06976a569ad3f3452121800e6bf33fc8d14ac /src/draw.c
parentcb6f98a5fa7bb2ed361abe68b3000f2e3f578ea7 (diff)
parent3ad8aa9e66f7e159b175a9a52e5ad00bbfd90734 (diff)
downloadso_long-7b230503231e154c5400413b4f9b87dd6fcd8304.tar.gz
so_long-7b230503231e154c5400413b4f9b87dd6fcd8304.zip
Merge collectibles-and-exit into master
Collectibles and exit
Diffstat (limited to 'src/draw.c')
-rw-r--r--src/draw.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/draw.c b/src/draw.c
index e350ca1..5284d74 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/15 16:41:15 by dkaiser ### ########.fr */
+/* Updated: 2024/05/20 20:10:15 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,16 +14,40 @@
#include "libft.h"
#include "so_long.h"
+int 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)
+{
+ 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);
+}
+
int draw_walls(t_game *game)
{
int x;
int y;
mlx_texture_t *wall_texture;
mlx_image_t *wall_image;
+ 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);
game->map.tile_size.x = 48;
game->map.tile_size.y = 48;
x = 0;
@@ -35,16 +59,12 @@ int draw_walls(t_game *game)
if (game->map.tiles[y * game->map.grid_size.x + x] == WALL)
mlx_image_to_window(game->mlx, wall_image, x
* game->map.tile_size.x, y * game->map.tile_size.y);
+ if (game->map.tiles[y * game->map.grid_size.x + x] == COLLECTIBLE)
+ mlx_image_to_window(game->mlx, game->map.collectible_img, x
+ * game->map.tile_size.x, y * game->map.tile_size.y);
y++;
}
x++;
}
return (0);
}
-
-int 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);
-}