veloren/voxygen/src/key_state.rs
Joshua Barretto cf4e02252a Smartened up terrain generation
Former-commit-id: d85448e5171bd27b04530da8e1ca927554136ebf
2019-05-09 18:57:47 +01:00

35 lines
727 B
Rust

use vek::Vec2;
pub struct KeyState {
pub right: bool,
pub left: bool,
pub up: bool,
pub down: bool,
pub jump: bool,
}
impl KeyState {
pub fn new() -> KeyState {
KeyState {
right: false,
left: false,
up: false,
down: false,
jump: false,
}
}
pub fn dir_vec(&self) -> Vec2<f32> {
let dir = 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 },
);
if dir.magnitude_squared() == 0.0 {
dir
} else {
dir.normalized()
}
}
}