Allow to control both brothers from the same keyboard
This commit is contained in:
parent
8159efd437
commit
94008bfbe3
2 changed files with 20 additions and 14 deletions
16
src/game.zig
16
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();
|
||||
|
|
18
src/main.zig
18
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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue