]> git.dkaiser.de - 42/so_long.git/commitdiff
Add player image
authorDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Thu, 9 May 2024 17:25:14 +0000 (19:25 +0200)
committerDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Thu, 9 May 2024 17:25:14 +0000 (19:25 +0200)
include/so_long.h
src/draw.c
src/init.c
src/loop.c

index 1661dbece7acf54cc2df26c514ffd7d343749cac..bff31156ee08dc97a54d44eea35de75ff44a1efc 100644 (file)
@@ -6,13 +6,15 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/08 14:14:02 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/09 17:59:42 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 19:24:00 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #ifndef SO_LONG_H
 # define SO_LONG_H
 
+# define PLAYER_MOVE_SPEED 3
+
 # include "libft.h"
 # include "mlx.h"
 
@@ -36,6 +38,7 @@ typedef struct s_player
        t_vector        position;
        t_vector    direction;
        t_vector        velocity;
+       void *img;
 }                              t_player;
 
 typedef struct s_game
index 759f03fc7538ba212ebf5825b63991481adf1b6b..ce2384271334d43d9fc18f44e758fb1262c3065a 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/09 17:58:23 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/09 18:05:58 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 19:24:37 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -15,6 +15,7 @@
 
 int    draw(t_game *game)
 {
+       mlx_clear_window(game->mlx, game->window);
        if (game->input_direction & UP)
                mlx_string_put(game->mlx, game->window, 150, 100, 0x00FFFFFF, "^");
        if (game->input_direction & DOWN)
@@ -27,7 +28,7 @@ int   draw(t_game *game)
                ft_itoa(game->player.direction.x));
        mlx_string_put(game->mlx, game->window, 550, 500, 0x00FFFFFF,
                ft_itoa(game->player.direction.y));
-
-    mlx_pixel_put(game->mlx, game->window, game->player.position.x, game->player.position.y, 0x00FFFF00);
+       mlx_put_image_to_window(game->mlx, game->window, game->player.img,
+               game->player.position.x, game->player.position.y);
        return (0);
 }
index 7c9645b5e79804224b94134c621cf23870964c66..0aa6664978fbcca7d9372c94665a0a5ce4767525 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/09 14:50:09 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/09 17:48:10 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 18:37:18 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -25,6 +25,8 @@ int   init(t_game *game)
        init_hooks(game);
        init_player(&game->player, 960, 540);
        // TODO: make player spawn point dynamic
+       int w, h;
+    game->player.img = mlx_xpm_file_to_image(game->mlx, "textures/player.xpm", &w, &h);
        return (0);
 }
 
index 89eabba80e799604a337caeaf2d2086761dda422..d0d9fe59c948cda7462d23b5ece4e13cd70bc405 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/09 15:09:24 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/09 18:03:03 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/09 19:08:51 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 
 int    loop(t_game *game)
 {
-       mlx_clear_window(game->mlx, game->window);
 
        game->player.direction.x = ((game->input_direction & RIGHT) != 0)
                - ((game->input_direction & LEFT) != 0);
        game->player.direction.y = ((game->input_direction & DOWN) != 0)
                - ((game->input_direction & UP) != 0);
 
-    game->player.position.x += game->player.direction.x;
-    game->player.position.y += game->player.direction.y;
+    game->player.position.x += game->player.direction.x * PLAYER_MOVE_SPEED;
+    game->player.position.y += game->player.direction.y * PLAYER_MOVE_SPEED;
 
     draw(game);
        return (0);