mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-14 10:12:26 -06:00
refactor: simplify keyboard event direction change logic in Game
This commit is contained in:
28
src/game.rs
28
src/game.rs
@@ -43,28 +43,14 @@ impl Game<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_to_pixel(cell: (u32, u32)) -> (i32, i32) {
|
|
||||||
((cell.0 as i32 * 24), ((cell.1) as i32 * 24))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn keyboard_event(&mut self, keycode: Keycode) {
|
pub fn keyboard_event(&mut self, keycode: Keycode) {
|
||||||
match keycode {
|
// Change direction
|
||||||
Keycode::D => {
|
let direction = Direction::from_keycode(keycode);
|
||||||
self.pacman.next_direction = Some(Direction::Right);
|
self.pacman.next_direction = direction;
|
||||||
}
|
|
||||||
Keycode::A => {
|
// Toggle debug mode
|
||||||
self.pacman.next_direction = Some(Direction::Left);
|
if keycode == Keycode::Space {
|
||||||
}
|
self.debug = !self.debug;
|
||||||
Keycode::W => {
|
|
||||||
self.pacman.next_direction = Some(Direction::Up);
|
|
||||||
}
|
|
||||||
Keycode::S => {
|
|
||||||
self.pacman.next_direction = Some(Direction::Down);
|
|
||||||
}
|
|
||||||
Keycode::Space => {
|
|
||||||
self.debug = !self.debug;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user