summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-15 17:35:56 +0200
committerDominik Kaiser2024-05-15 17:35:56 +0200
commit71e3dec2a0d675a1d911c529d228814742c49fcf (patch)
tree6e53fe40cc25b04aefe9792c261276cea2cbd093
parentcb6f98a5fa7bb2ed361abe68b3000f2e3f578ea7 (diff)
downloadso_long-71e3dec2a0d675a1d911c529d228814742c49fcf.tar.gz
so_long-71e3dec2a0d675a1d911c529d228814742c49fcf.zip
Draw exit
-rw-r--r--include/so_long.h3
-rw-r--r--src/draw.c29
-rw-r--r--src/init.c8
-rw-r--r--src/main.c3
4 files changed, 29 insertions, 14 deletions
diff --git a/include/so_long.h b/include/so_long.h
index 5d0d394..b0332d0 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/15 16:41:49 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 17:31:34 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -90,6 +90,7 @@ void loop(void *params);
void player_process(t_game *game);
int draw(t_game *game);
int draw_walls(t_game *game);
+void draw_exit(t_game *game);
void on_key_input(mlx_key_data_t event, void *params);
t_vector grid_to_screen_pos(t_ivector grid_pos, t_ivector tile_size);
t_ivector screen_to_grid_pos(t_vector screen_pos, t_ivector tile_size);
diff --git a/src/draw.c b/src/draw.c
index e350ca1..4e7e4e8 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/15 17:31:11 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,6 +14,26 @@
#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;
@@ -41,10 +61,3 @@ int draw_walls(t_game *game)
}
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);
-}
diff --git a/src/init.c b/src/init.c
index e7fedf2..7431c26 100644
--- a/src/init.c
+++ b/src/init.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/09 14:50:09 by dkaiser #+# #+# */
-/* Updated: 2024/05/15 15:09:44 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 17:19:06 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,7 +14,7 @@
#include "so_long.h"
static void init_hooks(t_game *game);
-static void init_actor(t_game *game);
+static void init_player(t_game *game);
int init(t_game *game)
{
@@ -22,7 +22,7 @@ int init(t_game *game)
// TODO: make size and title dynamic
game->input_direction = ZERO;
init_hooks(game);
- init_actor(game);
+ init_player(game);
return (0);
}
@@ -32,7 +32,7 @@ static void init_hooks(t_game *game)
mlx_key_hook(game->mlx, on_key_input, game);
}
-static void init_actor(t_game *game)
+static void init_player(t_game *game)
{
mlx_texture_t *texture;
t_actor *player;
diff --git a/src/main.c b/src/main.c
index 048fa21..fca5cf0 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/15 16:41:35 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 17:31:46 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,5 +22,6 @@ int main(int argc, char *argv[])
return (1);
init(&game);
draw_walls(&game);
+ draw_exit(&game);
mlx_loop(game.mlx);
}