mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-14 14:12:26 -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)]
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Up,
|
Up,
|
||||||
@@ -24,4 +26,18 @@ impl Direction {
|
|||||||
Direction::Up => (0, -1),
|
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