1
0
Fork 0

Allow to control both brothers from the same keyboard

This commit is contained in:
Julien Dessaux 2022-08-17 21:12:51 +02:00
parent 8159efd437
commit 94008bfbe3
Signed by: adyxax
GPG key ID: F92E51B86E07177E
2 changed files with 20 additions and 14 deletions

View file

@ -12,22 +12,22 @@ pub const Game = struct {
try self.brothers[0].draw(rc); try self.brothers[0].draw(rc);
try self.brothers[1].draw(rc); try self.brothers[1].draw(rc);
} }
pub fn moveJump(self: *Game) void { pub fn moveJump(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(self.side)].moveJump(); self.brothers[@enumToInt(side)].moveJump();
} }
pub fn moveLeft(self: *Game) void { pub fn moveLeft(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(self.side)].moveLeft(); self.brothers[@enumToInt(side)].moveLeft();
} }
pub fn moveRight(self: *Game) void { pub fn moveRight(self: *Game, side: brothers.Side) void {
self.brothers[@enumToInt(self.side)].moveRight(); self.brothers[@enumToInt(side)].moveRight();
} }
pub fn reset(self: *Game, side: brothers.Side) void { pub fn reset(self: *Game, side: brothers.Side) void {
self.side = side; self.side = side;
self.resetRound(); self.resetRound();
} }
pub fn resetRound(self: *Game) void { pub fn resetRound(self: *Game) void {
self.brothers[0].reset(brothers.Side.left); self.brothers[0].reset(.left);
self.brothers[1].reset(brothers.Side.right); self.brothers[1].reset(.right);
} }
pub fn step(self: *Game) void { pub fn step(self: *Game) void {
self.brothers[0].step(); self.brothers[0].step();

View file

@ -49,12 +49,18 @@ pub fn main() !void {
if (in.eqlDescription("escape") or in.eqlDescription("q")) { if (in.eqlDescription("escape") or in.eqlDescription("q")) {
done = true; done = true;
break; break;
} else if (in.eqlDescription("arrow-left") or in.eqlDescription("a")) { } else if (in.eqlDescription("arrow-left")) {
gs.moveLeft(); gs.moveLeft(.right);
} else if (in.eqlDescription("arrow-right") or in.eqlDescription("d")) { } else if (in.eqlDescription("arrow-right")) {
gs.moveRight(); gs.moveRight(.right);
} else if (in.eqlDescription("arrow-up") or in.eqlDescription("space")) { } else if (in.eqlDescription("arrow-up")) {
gs.moveJump(); 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 { } else {