From 6cab1d56ad2b29a2556090f1f0ce7e2b72d5460a Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 4 Oct 2024 19:56:50 +1000 Subject: Improve physics stability --- physics.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'physics.c') diff --git a/physics.c b/physics.c index 332d292..a9bcc59 100644 --- a/physics.c +++ b/physics.c @@ -148,14 +148,20 @@ void update_body( if (ramp) goto do_x; ittiles({ if (tc == 1) { - if (*vy > 0) { - *y = tr.y - (r->y + r->h); - *vy = 0; - *grounded = 0; - } else if (*vy < 0) { - *y = (tr.y + tr.h) - r->y; - *vy = 0; - *headbutted = 1; + int to = *y + r->y + r->h - tr.y; + int bo = tr.y + tr.h - (r->y + *y); + if (to < bo) { + if (*vy > 0) { + *y = tr.y - (r->y + r->h); + *vy = 0; + *grounded = 0; + } + } else { + if (*vy < 0) { + *y = (tr.y + tr.h) - r->y; + *vy = 0; + *headbutted = 1; + } } } }); @@ -188,12 +194,18 @@ do_x: } ittiles({ if (tc == 1) { - if (*vx > 0) { - *x = tr.x - (r->x + r->w); - *vx = 0; - } else if (*vx < 0) { - *x = (tr.x + tr.w) - r->x; - *vx = 0; + int le = *x + r->x + r->w - tr.x; + int ri = tr.x + tr.w - (r->x + *x); + if (le < ri) { + if (*vx > 0) { + *x = tr.x - (r->x + r->w); + *vx = 0; + } + } else { + if (*vx < 0) { + *x = (tr.x + tr.w) - r->x; + *vx = 0; + } } } }); -- cgit v1.2.3-54-g00ecf