From 2c027e787a7de91dc6c1e2bdfbc6bdc7ca91b75b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Fri, 26 Aug 2022 21:53:36 +0200 Subject: Began adding scoring --- src/brothers.zig | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/brothers.zig') diff --git a/src/brothers.zig b/src/brothers.zig index 448aaec..6f5fdce 100644 --- a/src/brothers.zig +++ b/src/brothers.zig @@ -15,6 +15,7 @@ const rightLimit = [2]f64{ 34, 74 }; // (38, 79) minus a brother's width pub const Brother = struct { side: Side, + score: u8, x: f64, y: f64, dx: f64, @@ -43,6 +44,17 @@ pub const Brother = struct { self.dx += 5 / (1000 / 60.0); self.moveDuration = 24; } + pub fn reset(self: *Brother, side: Side) void { + self.side = side; + self.score = 0; + } + pub fn resetRound(self: *Brother) void { + self.x = startingX[@enumToInt(self.side)]; + self.y = 17; + self.dx = 0; + self.dy = 0; + self.moveDuration = 0; + } pub fn step(self: *Brother, b: *ball.Ball) void { // Horizontal movement const x = self.x + self.dx; @@ -104,16 +116,6 @@ pub const Brother = struct { b.dy = b.dy * strength - 0.04; } } - pub fn reset(self: *Brother, side: ?Side) void { - if (side) |s| { - self.side = s; - } - self.x = startingX[@enumToInt(self.side)]; - self.y = 17; - self.dx = 0; - self.dy = 0; - self.moveDuration = 0; - } }; const brother = -- cgit v1.2.3