Added ghost image files. /JL

This commit is contained in:
2025-04-20 21:30:23 +02:00
parent 97c06fd3cf
commit c95c755e3f
9 changed files with 67 additions and 26 deletions

27
pman.py
View File

@@ -7,7 +7,7 @@ from actors.ghost_mode_controller import GhostModeController
from hud import HUD
from maze import Maze
__version__ = "0.4.1"
__version__ = "0.4.2"
# Constants
HAT_REPEAT_DELAY = 300 # milliseconds before first repeat
@@ -62,10 +62,10 @@ class Game:
"""
offset = 20 # spread out a little bit inside ghost home
self.blinky = Blinky((center_position[0] - offset, center_position[1] - offset))
self.pinky = Pinky((center_position[0] + offset, center_position[1] - offset))
self.inky = Inky((center_position[0] - offset, center_position[1] + offset))
self.clyde = Clyde((center_position[0] + offset, center_position[1] + offset))
self.blinky = Blinky((center_position[0] - 64, center_position[1] - 32), start_location=(13, 14))
self.pinky = Pinky((center_position[0] + 64, center_position[1] - 32), start_location=(17, 14))
self.inky = Inky((center_position[0] - 64, center_position[1] + 32), start_location=(13, 16))
self.clyde = Clyde((center_position[0] + 64, center_position[1] + 32), start_location=(17, 16))
return pygame.sprite.Group(self.blinky, self.pinky, self.inky, self.clyde)
@@ -120,21 +120,29 @@ class Game:
case pygame.K_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()
case pygame.K_LEFT:
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 pygame.K_UP:
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 pygame.K_DOWN:
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()
case pygame.JOYHATMOTION:
@@ -147,24 +155,32 @@ class Game:
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()
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]):
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()
elif self.hat_y == 1:
if event.type == pygame.USEREVENT and event.dict.get("type_name") == "JOYHATREPEAT":
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()
elif self.hat_y == -1:
if event.type == pygame.USEREVENT and event.dict.get("type_name") == "JOYHATREPEAT":
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()
@@ -184,6 +200,7 @@ class Game:
self.hud.add_points(10)
case "power":
self.hud.add_points(50)
self.ghost_mode_controller.trigger_frightened()
if __name__ == "__main__":
pman = Game()