]> git.dkaiser.de - 42/so_long.git/commitdiff
Add delta_time to player movement
authorDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Fri, 10 May 2024 11:07:27 +0000 (13:07 +0200)
committerDominik Kaiser <dkaiser@1-C-7.42heilbronn.de>
Fri, 10 May 2024 11:07:27 +0000 (13:07 +0200)
include/so_long.h
src/loop.c

index 7365a30fc7df7e0cf73f01d4ac9c4d33704f797b..d66e3552c3b43d7c8ca0d0ba3bc232f9e957d326 100644 (file)
@@ -13,7 +13,7 @@
 #ifndef SO_LONG_H
 # define SO_LONG_H
 
-# define PLAYER_MOVE_SPEED 3
+# define PLAYER_MOVE_SPEED 250
 # include "MLX42/MLX42.h"
 # include "libft.h"
 
@@ -28,8 +28,8 @@ enum                  e_direction
 
 typedef struct s_vector
 {
-       int                     x;
-       int                     y;
+       double          x;
+       double          y;
 }                              t_vector;
 
 typedef struct s_player
index 6162935b6af58c002647c87896e7efe625bb2444..18590a536741d993229e207f0cb3d9693db3e1a5 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: dkaiser <dkaiser@student.42heilbronn.de    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/05/09 15:09:24 by dkaiser           #+#    #+#             */
-/*   Updated: 2024/05/10 12:17:03 by dkaiser          ###   ########.fr       */
+/*   Updated: 2024/05/10 12:31:15 by dkaiser          ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -22,7 +22,7 @@ void  loop(void *params)
                - ((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 * PLAYER_MOVE_SPEED;
-       game->player.position.y += game->player.direction.y * PLAYER_MOVE_SPEED;
+       game->player.position.x += game->player.direction.x * PLAYER_MOVE_SPEED * game->mlx->delta_time;
+       game->player.position.y += game->player.direction.y * PLAYER_MOVE_SPEED * game->mlx->delta_time;
        draw(game);
 }