1
0
Fork 0

Fixed bug when a round ends while falling, and reset gamepad state between rounds

This commit is contained in:
Julien Dessaux 2022-10-17 22:21:09 +02:00
parent e4b1d7f947
commit 873b384bc6
Signed by: adyxax
GPG key ID: F92E51B86E07177E
4 changed files with 8 additions and 0 deletions

0
.gitmodules vendored
View file

View file

@ -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)])

View file

@ -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.*);

View file

@ -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);