From d265eb691eb9f273d62b9f5ffb573edd12da0ce3 Mon Sep 17 00:00:00 2001
From: Julien Dessaux <julien.dessaux@adyxax.org>
Date: Sat, 24 Sep 2022 22:33:08 +0200
Subject: [PATCH] Added ball and net collisions

---
 src/ball.zig | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/ball.zig b/src/ball.zig
index f2458d4..8c446b0 100644
--- a/src/ball.zig
+++ b/src/ball.zig
@@ -41,6 +41,20 @@ pub const Ball = struct {
             self.vy = 0;
             self.y = 160 - ball_height;
         }
+        // Net collision
+        var x1: f64 = 78 - ball_width;
+        var x2: f64 = 82;
+        var y1: f64 = 100 - ball_height;
+        var y2: f64 = 160;
+        if (self.x >= x1 and self.x < x2 and self.y >= y1 and self.y < y2) {
+            if (self.vx > 0) {
+                self.x = x1;
+            } else {
+                self.x = x2;
+            }
+            self.vx = -self.vx;
+        }
+        // TODO collision with top of the net?
     }
 };