diff options
author | Julien Dessaux | 2022-09-29 22:03:25 +0200 |
---|---|---|
committer | Julien Dessaux | 2022-09-29 22:03:25 +0200 |
commit | 2f76bca8dc84525f18df8b0658176cf806815b15 (patch) | |
tree | 342c49f27bf662381a81d352ddffd7b5b83c0d1f /src/ball.zig | |
parent | Improved net collisions (diff) | |
download | grenade-brothers-2f76bca8dc84525f18df8b0658176cf806815b15.tar.gz grenade-brothers-2f76bca8dc84525f18df8b0658176cf806815b15.tar.bz2 grenade-brothers-2f76bca8dc84525f18df8b0658176cf806815b15.zip |
Added end of round detection and scoring
Diffstat (limited to '')
-rw-r--r-- | src/ball.zig | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/ball.zig b/src/ball.zig index 9603d9a..a48fe9f 100644 --- a/src/ball.zig +++ b/src/ball.zig @@ -20,7 +20,7 @@ pub const Ball = struct { self.vx = 0; self.vy = -250; } - pub fn update(self: *Ball) void { + pub fn update(self: *Ball) ?utils.side { self.vy += utils.gravity; self.x += self.vx * utils.frequency; self.y += self.vy * utils.frequency; @@ -40,6 +40,11 @@ pub const Ball = struct { if (self.y >= 160 - ball_height) { // floor self.vy = 0; self.y = 160 - ball_height; + if (self.x <= 80) { + return .left; + } else { + return .right; + } } // Net collision left var x1: f64 = 78 - ball_width; @@ -85,6 +90,7 @@ pub const Ball = struct { self.x = x2; } } + return null; } }; |