aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/brothers.zig22
-rw-r--r--src/game.zig7
2 files changed, 19 insertions, 10 deletions
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 =
diff --git a/src/game.zig b/src/game.zig
index c8492df..40804b2 100644
--- a/src/game.zig
+++ b/src/game.zig
@@ -14,6 +14,13 @@ pub const Game = struct {
try self.brothers[0].draw(rc);
try self.brothers[1].draw(rc);
try self.ball.draw(rc);
+ var score: [1]u8 = undefined;
+ try rc.moveCursorTo(1, 3);
+ score[0] = '0' + self.brothers[0].score;
+ _ = try rc.buffer.writer().write(score[0..]);
+ try rc.moveCursorTo(1, 76);
+ score[0] = '0' + self.brothers[1].score;
+ _ = try rc.buffer.writer().write(score[0..]);
}
pub fn moveJump(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(side)].moveJump();