Galactica/src/inputstatus.rs
2023-12-22 17:24:53 -08:00

28 lines
577 B
Rust

use winit::event::{ElementState, VirtualKeyCode};
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,
}
}
pub fn process(&mut self, state: &ElementState, key: &VirtualKeyCode) {
let down = state == &ElementState::Pressed;
match key {
VirtualKeyCode::Left => self.key_left = down,
VirtualKeyCode::Right => self.key_right = down,
VirtualKeyCode::Up => self.key_thrust = down,
_ => {}
}
}
}