diff --git a/pman.py b/pman.py index a641839..45029bd 100644 --- a/pman.py +++ b/pman.py @@ -7,11 +7,11 @@ from actors.ghost_mode_controller import GhostModeController from hud import HUD from maze import Maze -__version__ = "0.4.2" +__version__ = "0.5.0" # Constants -HAT_REPEAT_DELAY = 300 # milliseconds before first repeat -HAT_REPEAT_INTERVAL = 100 # milliseconds between repeats +HAT_REPEAT_DELAY = 0 # milliseconds before first repeat +HAT_REPEAT_INTERVAL = 200 # milliseconds between repeats class Game: def __init__(self): @@ -152,13 +152,12 @@ class Game: self.hat_first_press = True if self.hat_x == 1: - if event.type == pygame.USEREVENT and event.dict.get("type_name") == "JOYHATREPEAT": - if self.maze.is_wall(self.player.location[0] + 1, self.player.location[1]): - break - elif self.maze.is_ghost_home(self.player.location[0] + 1, self.player.location[1]): - break - self.player.direction = PlayerDirection.DirectionRight - self.player.move_right() + if self.maze.is_wall(self.player.location[0] + 1, self.player.location[1]): + break + elif self.maze.is_ghost_home(self.player.location[0] + 1, self.player.location[1]): + break + self.player.direction = PlayerDirection.DirectionRight + self.player.move_right() elif self.hat_x == -1: if event.type == pygame.USEREVENT and event.dict.get("type_name") == "JOYHATREPEAT": if self.maze.is_wall(self.player.location[0] - 1, self.player.location[1]): @@ -183,6 +182,38 @@ class Game: break self.player.direction = PlayerDirection.DirectionDown self.player.move_down() + + case pygame.USEREVENT: + if event.dict.get("type_name") == "JOYHATREPEAT": + match event.dict['value']: + case (1, 0): + if self.maze.is_wall(self.player.location[0] + 1, self.player.location[1]): + break + elif self.maze.is_ghost_home(self.player.location[0] + 1, self.player.location[1]): + break + self.player.direction = PlayerDirection.DirectionRight + self.player.move_right() + case (-1, 0): + if self.maze.is_wall(self.player.location[0] - 1, self.player.location[1]): + break + elif self.maze.is_ghost_home(self.player.location[0] - 1, self.player.location[1]): + break + self.player.direction = PlayerDirection.DirectionLeft + self.player.move_left() + case (0, 1): + if self.maze.is_wall(self.player.location[0], self.player.location[1] - 1): + break + elif self.maze.is_ghost_home(self.player.location[0], self.player.location[1] - 1): + break + self.player.direction = PlayerDirection.DirectionUp + self.player.move_up() + case (0, -1): + if self.maze.is_wall(self.player.location[0], self.player.location[1] + 1): + break + elif self.maze.is_ghost_home(self.player.location[0], self.player.location[1] + 1): + break + self.player.direction = PlayerDirection.DirectionDown + self.player.move_down() # Handle hotplugging case pygame.JOYDEVICEADDED: