From 77725a5ce475577bcd9fe79a81b6915cf7f96662 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 4 Jan 2025 02:12:55 +0000 Subject: [PATCH] Round coordinates in collision detection This fixes an issue where the player could get stuck to an edge when being aligned to the pixel grid due to the rounded coordinate being outside an invalid tile but the truncated position being inside. Also we should be doing it anyway. --- game/main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/game/main.c b/game/main.c index 2138c50..2370fc1 100644 --- a/game/main.c +++ b/game/main.c @@ -409,11 +409,14 @@ static void entityupdate(gamestate_t *state, entity_t *e, double dt) const dvec_t pfb = { .x = nextx + e->fbox.off.x, .y = nexty + e->fbox.off.y }; bool valid = true; - valid &= tilepassable(state->map, pfb.x, pfb.y); - valid &= tilepassable(state->map, pfb.x + e->fbox.ext.x, pfb.y); - valid &= tilepassable(state->map, pfb.x, pfb.y + e->fbox.ext.y); + valid &= tilepassable(state->map, (int)rint(pfb.x), (int)rint(pfb.y)); valid &= tilepassable( - state->map, pfb.x + e->fbox.ext.x, pfb.y + e->fbox.ext.y); + state->map, (int)rint(pfb.x + e->fbox.ext.x), (int)rint(pfb.y)); + valid &= tilepassable( + state->map, (int)rint(pfb.x), (int)rint(pfb.y + e->fbox.ext.y)); + valid &= tilepassable( + state->map, (int)rint(pfb.x + e->fbox.ext.x), + (int)rint(pfb.y + e->fbox.ext.y)); if (valid) { e->pos.x = nextx; e->pos.y = nexty;