From 300128b8b0eaf4e6dd04c076887721dc645c939e Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Tue, 14 May 2024 12:45:49 +0200 Subject: Outsource player processing and add collision func --- src/player_process.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/player_process.c (limited to 'src/player_process.c') diff --git a/src/player_process.c b/src/player_process.c new file mode 100644 index 0000000..8cabe9a --- /dev/null +++ b/src/player_process.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* player_process.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser player; + player.direction = get_direction_from_input(game); + player.velocity.x = player.direction.x * PLAYER_MOVE_SPEED + * game->mlx->delta_time; + player.velocity.y = player.direction.y * PLAYER_MOVE_SPEED + * game->mlx->delta_time; + player.position.x += player.velocity.x; + player.position.y += player.velocity.y; +} + +static t_vector get_direction_from_input(t_game *game) +{ + t_vector result; + + result.x = ((game->input_direction & RIGHT) != 0) + - ((game->input_direction & LEFT) != 0); + result.y = ((game->input_direction & DOWN) != 0) + - ((game->input_direction & UP) != 0); + return (result); +} -- cgit v1.2.3