summaryrefslogtreecommitdiff
path: root/src/player_process.c
diff options
context:
space:
mode:
authorDominik Kaiser2024-05-15 12:16:05 +0200
committerDominik Kaiser2024-05-15 12:16:05 +0200
commited5342399d02ba5d1032a2ef99afdc1c875ed4d8 (patch)
treee76d37b1d416f0405a7267a38d184eca32ad1bd8 /src/player_process.c
parent5a7e68ce0331077594dc2d85c81fc087d80734c7 (diff)
downloadso_long-ed5342399d02ba5d1032a2ef99afdc1c875ed4d8.tar.gz
so_long-ed5342399d02ba5d1032a2ef99afdc1c875ed4d8.zip
Change collision checking and add player.size
Collision checking will now be done using the move_and_slide function. Instead of tile_size, now player.size will be used for checking collisions.
Diffstat (limited to 'src/player_process.c')
-rw-r--r--src/player_process.c19
1 files changed, 2 insertions, 17 deletions
diff --git a/src/player_process.c b/src/player_process.c
index 5fcf994..52277f8 100644
--- a/src/player_process.c
+++ b/src/player_process.c
@@ -6,7 +6,7 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/14 12:40:05 by dkaiser #+# #+# */
-/* Updated: 2024/05/14 15:12:28 by dkaiser ### ########.fr */
+/* Updated: 2024/05/15 12:03:52 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,8 +18,6 @@ static t_vector get_direction_from_input(t_game *game);
void player_process(t_game *game)
{
t_player *player;
- t_vector collision_pos;
- int collision;
player = &game->player;
player->direction = get_direction_from_input(game);
@@ -28,20 +26,7 @@ void player_process(t_game *game)
player->velocity.y = player->direction.y * PLAYER_MOVE_SPEED
* game->mlx->delta_time;
- 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;
+ move_and_slide(player, &game->map);
}
static t_vector get_direction_from_input(t_game *game)