aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2022-08-17 21:12:51 +0200
committerJulien Dessaux2022-08-17 21:12:51 +0200
commit94008bfbe33aae97c89eb0c32b6e69ec186decd4 (patch)
tree468a34a95d4a11c59fd8c47dcb68aaa1eada12fa
parentFixed playfield symetry (diff)
downloadgrenade-brothers-94008bfbe33aae97c89eb0c32b6e69ec186decd4.tar.gz
grenade-brothers-94008bfbe33aae97c89eb0c32b6e69ec186decd4.tar.bz2
grenade-brothers-94008bfbe33aae97c89eb0c32b6e69ec186decd4.zip
Allow to control both brothers from the same keyboard
-rw-r--r--src/game.zig16
-rw-r--r--src/main.zig18
2 files changed, 20 insertions, 14 deletions
diff --git a/src/game.zig b/src/game.zig
index ddd0b62..8af1889 100644
--- a/src/game.zig
+++ b/src/game.zig
@@ -12,22 +12,22 @@ pub const Game = struct {
try self.brothers[0].draw(rc);
try self.brothers[1].draw(rc);
}
- pub fn moveJump(self: *Game) void {
- self.brothers[@enumToInt(self.side)].moveJump();
+ pub fn moveJump(self: *Game, side: brothers.Side) void {
+ self.brothers[@enumToInt(side)].moveJump();
}
- pub fn moveLeft(self: *Game) void {
- self.brothers[@enumToInt(self.side)].moveLeft();
+ pub fn moveLeft(self: *Game, side: brothers.Side) void {
+ self.brothers[@enumToInt(side)].moveLeft();
}
- pub fn moveRight(self: *Game) void {
- self.brothers[@enumToInt(self.side)].moveRight();
+ pub fn moveRight(self: *Game, side: brothers.Side) void {
+ self.brothers[@enumToInt(side)].moveRight();
}
pub fn reset(self: *Game, side: brothers.Side) void {
self.side = side;
self.resetRound();
}
pub fn resetRound(self: *Game) void {
- self.brothers[0].reset(brothers.Side.left);
- self.brothers[1].reset(brothers.Side.right);
+ self.brothers[0].reset(.left);
+ self.brothers[1].reset(.right);
}
pub fn step(self: *Game) void {
self.brothers[0].step();
diff --git a/src/main.zig b/src/main.zig
index 3a534b9..875b02c 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -49,12 +49,18 @@ pub fn main() !void {
if (in.eqlDescription("escape") or in.eqlDescription("q")) {
done = true;
break;
- } else if (in.eqlDescription("arrow-left") or in.eqlDescription("a")) {
- gs.moveLeft();
- } else if (in.eqlDescription("arrow-right") or in.eqlDescription("d")) {
- gs.moveRight();
- } else if (in.eqlDescription("arrow-up") or in.eqlDescription("space")) {
- gs.moveJump();
+ } else if (in.eqlDescription("arrow-left")) {
+ gs.moveLeft(.right);
+ } else if (in.eqlDescription("arrow-right")) {
+ gs.moveRight(.right);
+ } else if (in.eqlDescription("arrow-up")) {
+ gs.moveJump(.right);
+ } else if (in.eqlDescription("a")) {
+ gs.moveLeft(.left);
+ } else if (in.eqlDescription("d")) {
+ gs.moveRight(.left);
+ } else if (in.eqlDescription("space")) {
+ gs.moveJump(.left);
}
}
} else {