use sdl2::{event::Event, keyboard::Keycode}; // TODO: no boolean modification (no pub) pub struct InputStatus { pub key_left: bool, pub key_right: bool, pub key_thrust: bool, } impl InputStatus { pub fn new() -> Self { InputStatus { key_left: false, key_right: false, key_thrust: false, } } fn handle_keyup(&mut self, keycode: Keycode) { match keycode { Keycode::Left => self.key_left = false, Keycode::Right => self.key_right = false, Keycode::Up => self.key_thrust = false, _ => {} } } fn handle_keydown(&mut self, keycode: Keycode) { match keycode { Keycode::Left => self.key_left = true, Keycode::Right => self.key_right = true, Keycode::Up => self.key_thrust = true, _ => {} } } pub fn update(&mut self, event: Event) { match event { Event::KeyDown { keycode: Some(key), .. } => self.handle_keydown(key), Event::KeyUp { keycode: Some(key), .. } => self.handle_keyup(key), _ => {} } } }