diff options
Diffstat (limited to 'src/player_process.c')
| -rw-r--r-- | src/player_process.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/player_process.c b/src/player_process.c index 8cabe9a..5fcf994 100644 --- a/src/player_process.c +++ b/src/player_process.c @@ -6,26 +6,42 @@ /* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/14 12:40:05 by dkaiser #+# #+# */ -/* Updated: 2024/05/14 12:44:17 by dkaiser ### ########.fr */ +/* Updated: 2024/05/14 15:12:28 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; + t_player *player; + t_vector collision_pos; + int collision; - player = game->player; - player.direction = get_direction_from_input(game); - player.velocity.x = player.direction.x * PLAYER_MOVE_SPEED + 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 + 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; + + collision_pos.x = player->position.x + player->velocity.x; + collision_pos.y = player->position.y + player->velocity.y; + collision = check_wall_collision(collision_pos, game->map.tile_size, &game->map); + if (collision & LEFT && player->velocity.x < 0) + player->velocity.x = 0; + if (collision & RIGHT && player->velocity.x > 0) + player->velocity.x = 0; + if (collision & UP && player->velocity.y < 0) + player->velocity.y = 0; + if (collision & DOWN && player->velocity.y > 0) + player->velocity.y = 0; + + player->position.x += player->velocity.x; + player->position.y += player->velocity.y; } static t_vector get_direction_from_input(t_game *game) |
