summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <me@armaanb.net>2021-05-15 22:21:41 -0400
committerArmaan Bhojwani <me@armaanb.net>2021-05-15 22:21:41 -0400
commit9f327207ca5e7c074ceb42efbeb1e62651a66336 (patch)
tree90dd6a4dd5d5da86459b0e0bd7d16318ecc34f21
parent1cfbdcdeeb9260b901cb8e78ed656354d7415550 (diff)
downloadpong-9f327207ca5e7c074ceb42efbeb1e62651a66336.tar.gz
Improve paddle bounce logic
-rw-r--r--pong.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/pong.c b/pong.c
index a61bc0d..0a75050 100644
--- a/pong.c
+++ b/pong.c
@@ -142,9 +142,9 @@ main(void) {
/* Find the distance that the ball hits from the center of the padel and
accordingly adjust ball path */
int poff = (x <= 1) ? aoff : boff;
- double fromc = fabs(0.5 * (poff + 0.5 * pad_h - y));
- slope_x *= (slope_x < 20) ? 1 : (int) ((double) slope_x / fromc);
- slope_x += 1;
+ double fromc = (fabs(poff + 0.5 * pad_h - y) / 2);
+ slope_x /= (abs(slope_x) > 25) ? 2 : fromc;
+ slope_x = (slope_x < 2) ? 2 : slope_x;
direction *= -1;
x += direction;