diff options
-rw-r--r-- | physics.c | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -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; + } } } }); |