#28 Added event repeater for joyhatmotion. /JL
This commit is contained in:
39
pman.py
39
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,7 +152,6 @@ 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]):
|
||||
@@ -184,6 +183,38 @@ class Game:
|
||||
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:
|
||||
# This event will be generated when the program starts for every
|
||||
|
Reference in New Issue
Block a user