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,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl KeyState {
|
|
|
|
pub fn new() -> KeyState {
|
|
|
|
KeyState {
|
|
|
|
right: false,
|
|
|
|
left: false,
|
|
|
|
up: false,
|
|
|
|
down: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn dir_vec(&self) -> Vec2<f32> {
|
2019-05-09 17:12:24 +00:00
|
|
|
let dir = Vec2::<f32>::new(
|
2019-03-02 03:48:30 +00:00
|
|
|
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 },
|
2019-05-09 17:12:24 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if dir.magnitude_squared() == 0.0 {
|
|
|
|
dir
|
|
|
|
} else {
|
|
|
|
dir.normalized()
|
|
|
|
}
|
2019-03-02 03:48:30 +00:00
|
|
|
}
|
|
|
|
}
|