aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--physics.c40
1 files changed, 26 insertions, 14 deletions
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;
+ }
}
}
});