diff options
author | Julien Dessaux | 2022-09-24 22:33:08 +0200 |
---|---|---|
committer | Julien Dessaux | 2022-09-24 22:33:08 +0200 |
commit | d265eb691eb9f273d62b9f5ffb573edd12da0ce3 (patch) | |
tree | 6fba786ebc2c2d82437414deb231ee65553efff0 | |
parent | Added ball physics (diff) | |
download | grenade-brothers-d265eb691eb9f273d62b9f5ffb573edd12da0ce3.tar.gz grenade-brothers-d265eb691eb9f273d62b9f5ffb573edd12da0ce3.tar.bz2 grenade-brothers-d265eb691eb9f273d62b9f5ffb573edd12da0ce3.zip |
Added ball and net collisions
-rw-r--r-- | src/ball.zig | 14 |
1 files changed, 14 insertions, 0 deletions
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? } }; |