sm64_binds/sm64/
game_pad.rs1#[derive(Clone, Debug)]
2pub struct GamePad {
3 pub(crate) button: u16,
4 pub(crate) stick_x: i8,
5 pub(crate) stick_y: i8,
6}
7
8impl GamePad {
9 pub fn new(button: u16, stick_x: i8, stick_y: i8) -> Self {
10 GamePad { button, stick_x, stick_y }
11 }
12
13 pub fn equals(&self, pad: &GamePad) -> bool {
14 self.button == pad.button && self.stick_x == pad.stick_x && self.stick_y == pad.stick_y
15 }
16
17 pub fn from_bytes(data: &[u8]) -> Self {
18 let button = u16::from_le_bytes(data[0..1].try_into().unwrap());
19 let stick_x = data[2] as i8;
20 let stick_y = data[3] as i8;
21 GamePad::new(button, stick_x, stick_y)
22 }
23
24 pub fn is_pressed(&self, button_mask: u16) -> bool {
25 (self.button & button_mask) != 0
26 }
27
28 pub fn enable_button(&mut self, button_mask: u16) {
29 self.button |= button_mask;
30 }
31
32 pub fn disable_button(&mut self, button_mask: u16) {
33 self.button &= !button_mask;
34 }
35}