]> git.dkaiser.de - 42/so_long.git/commitdiff
Draw exit
authorDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Wed, 15 May 2024 15:35:56 +0000 (17:35 +0200)
committerDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Wed, 15 May 2024 15:35:56 +0000 (17:35 +0200)
include/so_long.h
src/draw.c
src/init.c
src/main.c

index 5d0d3942b6671337b8f87a09c73a9b4129283f8f..b0332d01bab654d473def98af1c6ed4ec4f8f587 100644 (file)
@@ -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);
index e350ca101af62be5b91dc33c8ad0361d51bb2800..4e7e4e8a80cba824353b0ef678452167d3e7230a 100644 (file)
@@ -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       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #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);
-}
index e7fedf209d4990f5fd256885d0c65fb378e53d30..7431c26d3b5ed5b492811fa240c7a325e47034f8 100644 (file)
@@ -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;
index 048fa21cbd256b67a4948781d60b36c4b4075db3..fca5cf00cf95ffd20b39bd754455d8ce0ad28984 100644 (file)
@@ -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);
 }