diff options
| author | Dominik Kaiser | 2024-05-15 12:36:00 +0200 |
|---|---|---|
| committer | GitHub | 2024-05-15 12:36:00 +0200 |
| commit | 012afb95fd1cb5c7e625b4b023c98573c0e0499f (patch) | |
| tree | e76d37b1d416f0405a7267a38d184eca32ad1bd8 /src/player_process.c | |
| parent | 7b021c4426f21bf20fed61459ddedb5224e25bc4 (diff) | |
| parent | ed5342399d02ba5d1032a2ef99afdc1c875ed4d8 (diff) | |
| download | so_long-012afb95fd1cb5c7e625b4b023c98573c0e0499f.tar.gz so_long-012afb95fd1cb5c7e625b4b023c98573c0e0499f.zip | |
Merge collision into master
Collision
Diffstat (limited to 'src/player_process.c')
| -rw-r--r-- | src/player_process.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/player_process.c b/src/player_process.c new file mode 100644 index 0000000..52277f8 --- /dev/null +++ b/src/player_process.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* player_process.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/14 12:40:05 by dkaiser #+# #+# */ +/* Updated: 2024/05/15 12:03:52 by dkaiser ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" +#include "so_long.h" + +static t_vector get_direction_from_input(t_game *game); + +void player_process(t_game *game) +{ + t_player *player; + + player = &game->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; + + move_and_slide(player, &game->map); +} + +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); +} |
