mirror of https://github.com/sotrh/learn-wgpu
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
Rust
52 lines
1.3 KiB
Rust
use winit::event::{ElementState, VirtualKeyCode};
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct Input {
|
|
pub p1_up_pressed: bool,
|
|
pub p1_down_pressed: bool,
|
|
pub p2_up_pressed: bool,
|
|
pub p2_down_pressed: bool,
|
|
pub enter_pressed: bool,
|
|
}
|
|
|
|
impl Input {
|
|
pub fn new() -> Self {
|
|
Default::default()
|
|
}
|
|
|
|
pub fn update(&mut self, key: VirtualKeyCode, state: ElementState) -> bool {
|
|
let pressed = state == ElementState::Pressed;
|
|
match key {
|
|
VirtualKeyCode::Up => {
|
|
self.p2_up_pressed = pressed;
|
|
true
|
|
}
|
|
VirtualKeyCode::Down => {
|
|
self.p2_down_pressed = pressed;
|
|
true
|
|
}
|
|
VirtualKeyCode::W => {
|
|
self.p1_up_pressed = pressed;
|
|
true
|
|
}
|
|
VirtualKeyCode::S => {
|
|
self.p1_down_pressed = pressed;
|
|
true
|
|
}
|
|
VirtualKeyCode::Return => {
|
|
self.enter_pressed = pressed;
|
|
true
|
|
}
|
|
_ => false,
|
|
}
|
|
}
|
|
|
|
pub fn ui_up_pressed(&self) -> bool {
|
|
self.p1_up_pressed || self.p2_up_pressed
|
|
}
|
|
|
|
pub fn ui_down_pressed(&self) -> bool {
|
|
self.p1_down_pressed || self.p2_down_pressed
|
|
}
|
|
}
|