aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2022-10-17 22:21:09 +0200
committerJulien Dessaux2022-10-17 22:55:51 +0200
commit873b384bc6a1c6359b5f890e90e37ce3374ec90b (patch)
treee910f86a2774ac349e8a690288890395e7cb9652
parentAdd an alternative button for jumping (diff)
downloadgrenade-brothers-873b384bc6a1c6359b5f890e90e37ce3374ec90b.tar.gz
grenade-brothers-873b384bc6a1c6359b5f890e90e37ce3374ec90b.tar.bz2
grenade-brothers-873b384bc6a1c6359b5f890e90e37ce3374ec90b.zip
Fixed bug when a round ends while falling, and reset gamepad state between rounds
-rw-r--r--.gitmodules0
-rw-r--r--src/brothers.zig1
-rw-r--r--src/game.zig2
-rw-r--r--src/inputs.zig5
4 files changed, 8 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
deleted file mode 100644
index e69de29..0000000
--- a/.gitmodules
+++ /dev/null
diff --git a/src/brothers.zig b/src/brothers.zig
index f29895e..ddd0903 100644
--- a/src/brothers.zig
+++ b/src/brothers.zig
@@ -50,6 +50,7 @@ pub const Brother = struct {
pub fn resetRound(self: *Brother) void {
self.x = utils.startingX[@enumToInt(self.side)];
self.y = 160;
+ self.vy = 0;
}
pub fn update(self: *Brother, gamepad: inputs.Gamepad) void {
if (gamepad.held.left and self.x > utils.leftLimit[@enumToInt(self.side)])
diff --git a/src/game.zig b/src/game.zig
index ce98eef..a8be210 100644
--- a/src/game.zig
+++ b/src/game.zig
@@ -40,6 +40,8 @@ pub const Game = struct {
}
self.brothers[0].resetRound();
self.brothers[1].resetRound();
+ self.gamepads[0].reset();
+ self.gamepads[1].reset();
}
pub fn update(self: *Game) bool {
self.gamepads[0].update(w4.GAMEPAD1.*);
diff --git a/src/inputs.zig b/src/inputs.zig
index 4d2afa0..7a5e706 100644
--- a/src/inputs.zig
+++ b/src/inputs.zig
@@ -18,6 +18,11 @@ pub const Gamepad = struct {
pressed: Buttons = .{},
released: Buttons = .{},
+ pub fn reset(self: *Gamepad) void {
+ self.held = @bitCast(Buttons, @bitCast(u8, self.held) ^ @bitCast(u8, self.held));
+ self.pressed = @bitCast(Buttons, @bitCast(u8, self.pressed) ^ @bitCast(u8, self.pressed));
+ self.released = @bitCast(Buttons, @bitCast(u8, self.released) ^ @bitCast(u8, self.released));
+ }
pub fn update(self: *Gamepad, buttons: u8) void {
var previous = @bitCast(u8, self.held);
self.held = @bitCast(Buttons, buttons);