joypad clear buttons fn

This commit is contained in:
Alex Janka 2023-02-22 10:09:40 +11:00
parent 788afa49d4
commit a9886a773a

View file

@ -63,18 +63,7 @@ impl Joypad {
gamepads: ConnectedGamepadsIterator,
) -> bool {
let old = *self;
*self = Joypad {
sel_action: self.sel_action,
sel_direction: self.sel_direction,
down: false,
up: false,
left: false,
right: false,
start: false,
select: false,
b: false,
a: false,
};
self.clear_buttons();
for (_, pad) in gamepads {
self.down |= pad.is_pressed(Button::DPadDown);
self.up |= pad.is_pressed(Button::DPadUp);
@ -95,6 +84,17 @@ impl Joypad {
self.b |= keys.contains(&Key::Semicolon);
*self != old
}
fn clear_buttons(&mut self) {
self.down = false;
self.up = false;
self.left = false;
self.right = false;
self.start = false;
self.select = false;
self.a = false;
self.b = false;
}
}
impl Default for Joypad {