#28 Added event repeater for joyhatmotion. /JL
This commit is contained in:
51
pman.py
51
pman.py
@@ -7,11 +7,11 @@ from actors.ghost_mode_controller import GhostModeController
|
|||||||
from hud import HUD
|
from hud import HUD
|
||||||
from maze import Maze
|
from maze import Maze
|
||||||
|
|
||||||
__version__ = "0.4.2"
|
__version__ = "0.5.0"
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
HAT_REPEAT_DELAY = 300 # milliseconds before first repeat
|
HAT_REPEAT_DELAY = 0 # milliseconds before first repeat
|
||||||
HAT_REPEAT_INTERVAL = 100 # milliseconds between repeats
|
HAT_REPEAT_INTERVAL = 200 # milliseconds between repeats
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -152,13 +152,12 @@ class Game:
|
|||||||
self.hat_first_press = True
|
self.hat_first_press = True
|
||||||
|
|
||||||
if self.hat_x == 1:
|
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]):
|
||||||
if self.maze.is_wall(self.player.location[0] + 1, self.player.location[1]):
|
break
|
||||||
break
|
elif self.maze.is_ghost_home(self.player.location[0] + 1, self.player.location[1]):
|
||||||
elif self.maze.is_ghost_home(self.player.location[0] + 1, self.player.location[1]):
|
break
|
||||||
break
|
self.player.direction = PlayerDirection.DirectionRight
|
||||||
self.player.direction = PlayerDirection.DirectionRight
|
self.player.move_right()
|
||||||
self.player.move_right()
|
|
||||||
elif self.hat_x == -1:
|
elif self.hat_x == -1:
|
||||||
if event.type == pygame.USEREVENT and event.dict.get("type_name") == "JOYHATREPEAT":
|
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]):
|
if self.maze.is_wall(self.player.location[0] - 1, self.player.location[1]):
|
||||||
@@ -183,6 +182,38 @@ class Game:
|
|||||||
break
|
break
|
||||||
self.player.direction = PlayerDirection.DirectionDown
|
self.player.direction = PlayerDirection.DirectionDown
|
||||||
self.player.move_down()
|
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
|
# Handle hotplugging
|
||||||
case pygame.JOYDEVICEADDED:
|
case pygame.JOYDEVICEADDED:
|
||||||
|
Reference in New Issue
Block a user