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.
This commit is contained in:
Camden Dixie O'Brien 2025-01-04 02:12:55 +00:00
parent 6d01f8cc3f
commit 77725a5ce4

View File

@ -409,11 +409,14 @@ static void entityupdate(gamestate_t *state, entity_t *e, double dt)
const dvec_t pfb const dvec_t pfb
= { .x = nextx + e->fbox.off.x, .y = nexty + e->fbox.off.y }; = { .x = nextx + e->fbox.off.x, .y = nexty + e->fbox.off.y };
bool valid = true; bool valid = true;
valid &= tilepassable(state->map, pfb.x, pfb.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);
valid &= tilepassable(state->map, pfb.x, pfb.y + e->fbox.ext.y);
valid &= tilepassable( 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) { if (valid) {
e->pos.x = nextx; e->pos.x = nextx;
e->pos.y = nexty; e->pos.y = nexty;