diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-09-19 20:12:56 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-09-19 20:12:56 -0400 |
| commit | 626509b4a2f66be31d50f03019afcedf9509133e (patch) | |
| tree | 402f159b278d30bcdfa6258d5333fb27774d43b6 | |
| parent | d439ed77546a00929ddd55bf44d65b448d9d520c (diff) | |
| download | balls-626509b4a2f66be31d50f03019afcedf9509133e.zip | |
wall clipping
| -rw-r--r-- | balls.c | 23 |
1 files changed, 11 insertions, 12 deletions
@@ -305,17 +305,6 @@ ball(void *arg) { printf("(%d,%d) %f %f\n", p.x, p.y, v.x, v.y); - /* check for wall collision */ - if (p.x < bounds.min.x+RADIUS || p.x > bounds.max.x-RADIUS) { - p.x = clamp(p.x, bounds.min.x+RADIUS, bounds.max.x-RADIUS); - printf("clamped to %d\n", p.x); - v.x = -v.x; - } - if (p.y < bounds.min.y+RADIUS || p.y > bounds.max.y-RADIUS) { - p.y = clamp(p.y, bounds.min.y+RADIUS, bounds.max.y-RADIUS); - v.y = -v.y; - } - broadcast(p, barg->out, barg->nothers); /* check for ball collision */ @@ -340,7 +329,17 @@ ball(void *arg) { printf("newv: (%2.2f,%2.2f)\n", v.x, v.y); } } - + + /* check for wall collision */ + if (p.x < bounds.min.x+RADIUS || p.x > bounds.max.x-RADIUS) { + p.x = clamp(p.x, bounds.min.x+RADIUS, bounds.max.x-RADIUS); + printf("clamped to %d\n", p.x); + v.x = -v.x; + } + if (p.y < bounds.min.y+RADIUS || p.y > bounds.max.y-RADIUS) { + p.y = clamp(p.y, bounds.min.y+RADIUS, bounds.max.y-RADIUS); + v.y = -v.y; + } recv(barg->frametick, &t); drawcircle(erase, oldp); drawcircle(fill, p); |