summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/so_long.h3
-rw-r--r--src/draw.c30
-rw-r--r--src/main.c3
-rw-r--r--textures/wall.pngbin0 -> 99 bytes
4 files changed, 33 insertions, 3 deletions
diff --git a/include/so_long.h b/include/so_long.h
index 47443aa..e9097d1 100644
--- a/include/so_long.h
+++ b/include/so_long.h
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/08 14:14:02 by dkaiser #+# #+# */
-/* Updated: 2024/05/10 17:28:23 by dkaiser ### ########.fr */
+/* Updated: 2024/05/11 16:10:26 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -81,6 +81,7 @@ int load_map_from_file(t_tilemap *tilemap, char *filename);
int init(t_game *game);
void loop(void *params);
int draw(t_game *game);
+int draw_map(t_game *game);
void on_key_input(mlx_key_data_t event, void *params);
#endif // SO_LONG_H
diff --git a/src/draw.c b/src/draw.c
index de4ba48..b5e5455 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -6,13 +6,41 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 17:58:23 by dkaiser #+# #+# */
-/* Updated: 2024/05/10 11:58:52 by dkaiser ### ########.fr */
+/* Updated: 2024/05/11 16:00:17 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
+#include "MLX42/MLX42.h"
#include "libft.h"
#include "so_long.h"
+int draw_map(t_game *game)
+{
+ int x;
+ int y;
+ mlx_texture_t *wall_texture;
+ mlx_image_t *wall_image;
+
+ wall_texture = mlx_load_png("textures/wall.png");
+ wall_image = mlx_texture_to_image(game->mlx, wall_texture);
+ mlx_resize_image(wall_image, 48, 48);
+ game->map.tile_size.x = 48;
+ game->map.tile_size.y = 48;
+ x = 0;
+ while (x < game->map.grid_size.x)
+ {
+ y = 0;
+ while (y < game->map.grid_size.y)
+ {
+ 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);
+ y++;
+ }
+ x++;
+ }
+ return (0);
+}
+
int draw(t_game *game)
{
game->player.img->instances[0].x = game->player.position.x;
diff --git a/src/main.c b/src/main.c
index 53fb23d..f7352f4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/08 14:14:13 by dkaiser #+# #+# */
-/* Updated: 2024/05/10 17:30:38 by dkaiser ### ########.fr */
+/* Updated: 2024/05/11 15:58:31 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,5 +21,6 @@ int main(int argc, char *argv[])
if (load_map_from_file(&game.map, argv[1]))
return (1);
init(&game);
+ draw_map(&game);
mlx_loop(game.mlx);
}
diff --git a/textures/wall.png b/textures/wall.png
new file mode 100644
index 0000000..358cdfb
--- /dev/null
+++ b/textures/wall.png
Binary files differ