aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-18 08:48:18 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-18 08:48:18 +0100
commitb37cbbbb8851207192b991d5ea91609c7dd5ad7d (patch)
tree9f4f7a82f7214eaac09e3b4b524a7470c26bd200 /src
parentb50f8d403e36137d6f8dccd847efd4e220f2c505 (diff)
downloadgold-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')
-rw-r--r--src/player.c10
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--;