aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdvard Thörnros <edvard.thornros@gmail.com>2021-01-31 10:04:41 +0100
committerEdvard Thörnros <edvard.thornros@gmail.com>2021-01-31 10:04:41 +0100
commita23e8c074efdde39ba0e284cc27f1aa41b4efce7 (patch)
treea2eebd14a5190239bd1e0aff37bf417366e6f459
parent40b9ec3f0f1273440d4405b531cd3290dd259b78 (diff)
downloadsylt-a23e8c074efdde39ba0e284cc27f1aa41b4efce7.tar.gz
Add correct collisions
-rw-r--r--pong/pong.tdy11
1 files changed, 9 insertions, 2 deletions
diff --git a/pong/pong.tdy b/pong/pong.tdy
index e1eb210..9778dfc 100644
--- a/pong/pong.tdy
+++ b/pong/pong.tdy
@@ -46,8 +46,14 @@ or := fn a: bool, b: bool -> bool {
}
rect_overlap := fn ax: float, ay: float, aw: float, ah: float, bx: float, by: float, bw: float, bh: float -> bool {
- dx := abs(ax - bx) + (-aw - bw) / 2.
- dy := abs(ay - by) + (-ah - bh) / 2.
+ acx := ax + aw / 2.
+ acy := ay + ah / 2.
+
+ bcx := bx + bw / 2.
+ bcy := by + bh / 2.
+
+ dx := abs(acx - bcx) + (-aw - bw) / 2.
+ dy := abs(acy - bcy) + (-ah - bh) / 2.
ret and(dx < 0., dy < 0.)
}
@@ -85,6 +91,7 @@ update := fn state: State {
draw := fn state: State {
clear()
+
draw_rectangle(state.p1.paddle.x, state.p1.paddle.y, 0.2, 1.)
draw_rectangle(state.p2.paddle.x, state.p2.paddle.y, 0.2, 1.)