diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-31 10:14:22 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-01-31 10:14:22 +0100 |
| commit | ef62c52f4ef990c5f51dd3a3d38c90757890b898 (patch) | |
| tree | 9b175d8765b3fd048e1b526d3629d4848854d5d7 | |
| parent | a23e8c074efdde39ba0e284cc27f1aa41b4efce7 (diff) | |
| download | sylt-ef62c52f4ef990c5f51dd3a3d38c90757890b898.tar.gz | |
Fix edge case
| -rw-r--r-- | pong/pong.tdy | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/pong/pong.tdy b/pong/pong.tdy index 9778dfc..cb861f9 100644 --- a/pong/pong.tdy +++ b/pong/pong.tdy @@ -45,6 +45,13 @@ or := fn a: bool, b: bool -> bool { ret b } +sign := fn a: float -> float { + if a < 0.0 { + ret -1.0 + } + ret 1.0 +} + rect_overlap := fn ax: float, ay: float, aw: float, ah: float, bx: float, by: float, bw: float, bh: float -> bool { acx := ax + aw / 2. acy := ay + ah / 2. @@ -59,7 +66,11 @@ rect_overlap := fn ax: float, ay: float, aw: float, ah: float, bx: float, by: fl ball_and_paddle_check := fn pad: Paddle, ball: Ball { if rect_overlap(ball.x, ball.y, 0.2, 0.2, pad.x, pad.y, 0.2, 1.) { - ball.vx = -ball.vx + if ball.x < pad.x { + ball.vx = -abs(ball.vx) + } else { + ball.vx = abs(ball.vx) + } } } |
