mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-10 06:07:55 -06:00
refactor: build decoupled input processing & add event queue system
This commit is contained in:
@@ -14,7 +14,6 @@ use crate::entity::{
|
||||
use crate::texture::animated::AnimatedTexture;
|
||||
use crate::texture::directional::DirectionalAnimatedTexture;
|
||||
use crate::texture::sprite::SpriteAtlas;
|
||||
use sdl2::keyboard::Keycode;
|
||||
use tracing::error;
|
||||
|
||||
use crate::error::{GameError, GameResult, TextureError};
|
||||
@@ -107,24 +106,6 @@ impl Pacman {
|
||||
texture: DirectionalAnimatedTexture::new(textures, stopped_textures),
|
||||
})
|
||||
}
|
||||
|
||||
/// Handles keyboard input to change Pac-Man's direction.
|
||||
///
|
||||
/// Maps arrow keys to directions and queues the direction change
|
||||
/// for the next valid intersection.
|
||||
pub fn handle_key(&mut self, keycode: Keycode) {
|
||||
let direction = match keycode {
|
||||
Keycode::Up => Some(Direction::Up),
|
||||
Keycode::Down => Some(Direction::Down),
|
||||
Keycode::Left => Some(Direction::Left),
|
||||
Keycode::Right => Some(Direction::Right),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(direction) = direction {
|
||||
self.traverser.set_next_direction(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Collidable for Pacman {
|
||||
|
||||
Reference in New Issue
Block a user