mirror of
https://github.com/Noratrieb/game-wip-dontplay.git
synced 2026-01-16 04:25:00 +01:00
Add keyboard input for camera movement
This commit is contained in:
parent
0aa2781c25
commit
91cd644b8c
3 changed files with 59 additions and 1 deletions
33
src/input.rs
Normal file
33
src/input.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
use fnv::FnvHashSet;
|
||||
use sfml::window::{Event, Key};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct KbInput {
|
||||
down: FnvHashSet<Key>,
|
||||
pressed: FnvHashSet<Key>,
|
||||
}
|
||||
|
||||
impl KbInput {
|
||||
pub fn update_from_event(&mut self, ev: &Event) {
|
||||
match ev {
|
||||
Event::KeyPressed { code, .. } => {
|
||||
self.pressed.insert(*code);
|
||||
self.down.insert(*code);
|
||||
}
|
||||
Event::KeyReleased { code, .. } => {
|
||||
self.down.remove(code);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
/// Pressed event should be cleared every frame
|
||||
pub fn clear_pressed(&mut self) {
|
||||
self.pressed.clear();
|
||||
}
|
||||
pub fn down(&self, key: Key) -> bool {
|
||||
self.down.contains(&key)
|
||||
}
|
||||
pub fn pressed(&self, key: Key) -> bool {
|
||||
self.pressed.contains(&key)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue