mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-09 10:07:58 -06:00
38 lines
872 B
Rust
38 lines
872 B
Rust
use glam::IVec2;
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
|
pub enum Direction {
|
|
Up,
|
|
Down,
|
|
Left,
|
|
Right,
|
|
}
|
|
|
|
impl Direction {
|
|
pub fn opposite(&self) -> Direction {
|
|
match self {
|
|
Direction::Up => Direction::Down,
|
|
Direction::Down => Direction::Up,
|
|
Direction::Left => Direction::Right,
|
|
Direction::Right => Direction::Left,
|
|
}
|
|
}
|
|
|
|
pub fn as_ivec2(&self) -> IVec2 {
|
|
(*self).into()
|
|
}
|
|
}
|
|
|
|
impl From<Direction> for IVec2 {
|
|
fn from(dir: Direction) -> Self {
|
|
match dir {
|
|
Direction::Up => -IVec2::Y,
|
|
Direction::Down => IVec2::Y,
|
|
Direction::Left => -IVec2::X,
|
|
Direction::Right => IVec2::X,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub const DIRECTIONS: [Direction; 4] = [Direction::Up, Direction::Down, Direction::Left, Direction::Right];
|