summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2024-09-19 20:12:56 -0400
committerSam Anthony <sam@samanthony.xyz>2024-09-19 20:12:56 -0400
commit626509b4a2f66be31d50f03019afcedf9509133e (patch)
tree402f159b278d30bcdfa6258d5333fb27774d43b6
parentd439ed77546a00929ddd55bf44d65b448d9d520c (diff)
downloadballs-626509b4a2f66be31d50f03019afcedf9509133e.zip
wall clipping
-rw-r--r--balls.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/balls.c b/balls.c
index b284492..b0afbd0 100644
--- a/balls.c
+++ b/balls.c
@@ -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);