Update pman.py
This commit is contained in:
31
pman.py
31
pman.py
@@ -2,9 +2,30 @@ import pygame
|
|||||||
from actors.enums import Colors, PlayerDirection
|
from actors.enums import Colors, PlayerDirection
|
||||||
from actors.pacman import ActorPacman
|
from actors.pacman import ActorPacman
|
||||||
from labyrinth import Labyrinth
|
from labyrinth import Labyrinth
|
||||||
|
from actors.ghosts import Blinky, Pinky, Inky, Clyde # adjust import path as needed
|
||||||
|
|
||||||
__version__ = "0.2.0"
|
__version__ = "0.2.0"
|
||||||
|
|
||||||
|
|
||||||
|
def spawn_ghosts(center_position):
|
||||||
|
"""
|
||||||
|
Spawns up to 4 ghosts at the center of the maze ("ghost house").
|
||||||
|
|
||||||
|
Args:
|
||||||
|
center_position (tuple): (x, y) coordinates for spawn point.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
pygame.sprite.Group: A group containing all ghost instances.
|
||||||
|
"""
|
||||||
|
offset = 20 # spread out a little bit inside ghost home
|
||||||
|
|
||||||
|
blinky = Blinky((center_position[0] - offset, center_position[1] - offset))
|
||||||
|
pinky = Pinky((center_position[0] + offset, center_position[1] - offset))
|
||||||
|
inky = Inky((center_position[0] - offset, center_position[1] + offset))
|
||||||
|
clyde = Clyde((center_position[0] + offset, center_position[1] + offset))
|
||||||
|
|
||||||
|
return pygame.sprite.Group(blinky, pinky, inky, clyde)
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen_width, screen_height = 800, 800
|
screen_width, screen_height = 800, 800
|
||||||
@@ -13,6 +34,8 @@ def main() -> None:
|
|||||||
|
|
||||||
labyrinth = Labyrinth(screen, width=screen_width, height=screen_height)
|
labyrinth = Labyrinth(screen, width=screen_width, height=screen_height)
|
||||||
player = ActorPacman(screen, center=(200, 200))
|
player = ActorPacman(screen, center=(200, 200))
|
||||||
|
ghost_home_center = (maze_width // 2, maze_height // 2)
|
||||||
|
ghosts = spawn_ghosts(ghost_home_center)
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
@@ -47,6 +70,14 @@ def main() -> None:
|
|||||||
labyrinth.draw()
|
labyrinth.draw()
|
||||||
player.animate()
|
player.animate()
|
||||||
player.draw()
|
player.draw()
|
||||||
|
ghost_mode_controller.update()
|
||||||
|
current_mode = ghost_mode_controller.mode
|
||||||
|
|
||||||
|
for ghost in ghosts:
|
||||||
|
ghost.set_mode(current_mode)
|
||||||
|
ghost.update(maze, pacman)
|
||||||
|
|
||||||
|
ghosts.draw(screen)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(60)
|
clock.tick(60)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user