aboutsummaryrefslogtreecommitdiff
path: root/src/game.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-08-22 20:18:30 +0200
committerJulien Dessaux2022-08-22 20:18:30 +0200
commita899bc060b6180635f3ff4ac73b7e6aee4fe9a7b (patch)
tree4ffe0a498eff6980e948c96c0e1cbbb69c37063a /src/game.zig
parentAllow to control both brothers from the same keyboard (diff)
downloadgrenade-brothers-a899bc060b6180635f3ff4ac73b7e6aee4fe9a7b.tar.gz
grenade-brothers-a899bc060b6180635f3ff4ac73b7e6aee4fe9a7b.tar.bz2
grenade-brothers-a899bc060b6180635f3ff4ac73b7e6aee4fe9a7b.zip
Implemented a ball with basic physics and collisions
Diffstat (limited to '')
-rw-r--r--src/game.zig9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/game.zig b/src/game.zig
index 8af1889..c8492df 100644
--- a/src/game.zig
+++ b/src/game.zig
@@ -1,16 +1,19 @@
const std = @import("std");
const spoon = @import("spoon");
+const ball = @import("ball.zig");
const brothers = @import("brothers.zig");
const playfield = @import("playfield.zig");
pub const Game = struct {
+ ball: ball.Ball = undefined,
brothers: [2]brothers.Brother = undefined,
side: brothers.Side = undefined,
pub fn draw(self: Game, rc: *spoon.Term.RenderContext) !void {
try playfield.draw(rc);
try self.brothers[0].draw(rc);
try self.brothers[1].draw(rc);
+ try self.ball.draw(rc);
}
pub fn moveJump(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(side)].moveJump();
@@ -26,11 +29,13 @@ pub const Game = struct {
self.resetRound();
}
pub fn resetRound(self: *Game) void {
+ self.ball.reset(.left);
self.brothers[0].reset(.left);
self.brothers[1].reset(.right);
}
pub fn step(self: *Game) void {
- self.brothers[0].step();
- self.brothers[1].step();
+ self.ball.step();
+ self.brothers[0].step(&self.ball);
+ self.brothers[1].step(&self.ball);
}
};