mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 16:07:57 -06:00
feat: keycode to direction utility function
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use sdl2::keyboard::Keycode;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
pub enum Direction {
|
||||
Up,
|
||||
@@ -24,4 +26,18 @@ impl Direction {
|
||||
Direction::Up => (0, -1),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_keycode(keycode: Keycode) -> Option<Direction> {
|
||||
match keycode {
|
||||
Keycode::D => Some(Direction::Right),
|
||||
Keycode::Right => Some(Direction::Right),
|
||||
Keycode::A => Some(Direction::Left),
|
||||
Keycode::Left => Some(Direction::Left),
|
||||
Keycode::W => Some(Direction::Up),
|
||||
Keycode::Up => Some(Direction::Up),
|
||||
Keycode::S => Some(Direction::Down),
|
||||
Keycode::Down => Some(Direction::Down),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user