From b37cbbbb8851207192b991d5ea91609c7dd5ad7d Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 18 Jun 2023 08:48:18 +0100 Subject: Fix horizontal collision detection Instead going down, what we want is not going up (so no gravity OR going down). --- src/player.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/player.c b/src/player.c index b0960bc..1528337 100644 --- a/src/player.c +++ b/src/player.c @@ -24,7 +24,7 @@ #define GRAVITY_SEQ_LEN 24 -#define IS_GOING_DOWN(x) ((x)>=GRAVITY_DOWN) +#define IS_NOT_GOING_UP(x) (gravity == GRAVITY_OFF || (x)>=GRAVITY_DOWN) static uint16_t x, y; static uint8_t dir, frame, delay, gravity, jump; @@ -110,8 +110,8 @@ void player_update() /* XXX: off limits */ if (x < MAP_W * MAP_TILE_W - 16) { - if ((IS_GOING_DOWN(gravity) && !map_is_blocked(x + 16, y + 15)) - || (!IS_GOING_DOWN(gravity) + if ((IS_NOT_GOING_UP(gravity) && !map_is_blocked(x + 16, y + 15)) + || (!IS_NOT_GOING_UP(gravity) && !(map_is_blocked(x + 16, y + 15) && map_is_blocked(x + 16, y + 7)))) x++; @@ -126,8 +126,8 @@ void player_update() /* XXX: off limits */ if (x) { - if ((IS_GOING_DOWN(gravity) && !map_is_blocked(x - 1, y + 15)) - || (!IS_GOING_DOWN(gravity) + if ((IS_NOT_GOING_UP(gravity) && !map_is_blocked(x - 1, y + 15)) + || (!IS_NOT_GOING_UP(gravity) && !(map_is_blocked(x - 1, y + 15) && map_is_blocked(x - 1, y + 7)))) x--; -- cgit v1.2.3