diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-18 08:48:18 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-18 08:48:18 +0100 |
commit | b37cbbbb8851207192b991d5ea91609c7dd5ad7d (patch) | |
tree | 9f4f7a82f7214eaac09e3b4b524a7470c26bd200 /src/player.c | |
parent | b50f8d403e36137d6f8dccd847efd4e220f2c505 (diff) | |
download | gold-mine-run-b37cbbbb8851207192b991d5ea91609c7dd5ad7d.tar.gz gold-mine-run-b37cbbbb8851207192b991d5ea91609c7dd5ad7d.zip |
Fix horizontal collision detection
Instead going down, what we want is not going up (so no gravity OR going
down).
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 10 |
1 files 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--; |