2019-03-02 03:48:30 +00:00
|
|
|
use vek::Vec2;
|
|
|
|
|
|
|
|
pub struct KeyState {
|
|
|
|
pub right: bool,
|
|
|
|
pub left: bool,
|
|
|
|
pub up: bool,
|
|
|
|
pub down: bool,
|
2020-03-24 07:38:16 +00:00
|
|
|
pub climb_up: bool,
|
|
|
|
pub climb_down: bool,
|
|
|
|
pub toggle_wield: bool,
|
|
|
|
pub toggle_sit: bool,
|
|
|
|
pub swap_loadout: bool,
|
|
|
|
pub respawn: bool,
|
2020-03-10 21:00:13 +00:00
|
|
|
pub analog_matrix: Vec2<f32>,
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl KeyState {
|
|
|
|
pub fn new() -> KeyState {
|
|
|
|
KeyState {
|
|
|
|
right: false,
|
|
|
|
left: false,
|
|
|
|
up: false,
|
|
|
|
down: false,
|
2020-03-24 07:38:16 +00:00
|
|
|
climb_up: false,
|
|
|
|
climb_down: false,
|
|
|
|
toggle_wield: false,
|
|
|
|
toggle_sit: false,
|
|
|
|
swap_loadout: false,
|
|
|
|
respawn: false,
|
2020-03-10 21:00:13 +00:00
|
|
|
analog_matrix: Vec2::zero(),
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dir_vec(&self) -> Vec2<f32> {
|
2020-03-10 21:00:13 +00:00
|
|
|
let dir = if self.analog_matrix == Vec2::zero() {
|
|
|
|
Vec2::<f32>::new(
|
|
|
|
if self.right { 1.0 } else { 0.0 } + if self.left { -1.0 } else { 0.0 },
|
|
|
|
if self.up { 1.0 } else { 0.0 } + if self.down { -1.0 } else { 0.0 },
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
self.analog_matrix
|
|
|
|
};
|
2019-05-09 17:12:24 +00:00
|
|
|
|
2020-03-10 21:00:13 +00:00
|
|
|
if dir.magnitude_squared() <= 1.0 {
|
2019-05-09 17:12:24 +00:00
|
|
|
dir
|
|
|
|
} else {
|
|
|
|
dir.normalized()
|
|
|
|
}
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|
2020-03-24 07:38:16 +00:00
|
|
|
|
|
|
|
pub fn climb(&self) -> Option<common::comp::Climb> {
|
|
|
|
use common::comp::Climb;
|
|
|
|
match (self.climb_up, self.climb_down) {
|
|
|
|
(true, false) => Some(Climb::Up),
|
|
|
|
(false, true) => Some(Climb::Down),
|
|
|
|
(true, true) => Some(Climb::Hold),
|
|
|
|
(false, false) => None,
|
|
|
|
}
|
|
|
|
}
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|