Added pacman movement. /JL

This commit is contained in:
2025-04-19 13:05:20 +02:00
parent ffa7ba0db3
commit bd5d7da84e
4 changed files with 39 additions and 25 deletions

16
pman.py
View File

@@ -1,12 +1,12 @@
import pygame
from actors.enums import Colors, PlayerDirection, PillType
from actors.enums import Colors, PlayerDirection
from actors.pacman import ActorPacman
from actors.ghost import Blinky, Pinky, Inky, Clyde # adjust import path as needed
from actors.ghost_mode_controller import GhostModeController
from hud import HUD
from maze import Maze
__version__ = "0.2.4"
__version__ = "0.2.7"
def spawn_ghosts(center_position):
@@ -38,7 +38,7 @@ def main() -> None:
hud = HUD(screen_width, screen_height, cherry_image=cherry_img)
maze = Maze("maze/pacman_maze.txt")
player = ActorPacman(screen, center=maze.pacman_start)
player = ActorPacman(screen, center=maze.pacman_start, start_location=maze.pacman_location, maze=maze)
ghost_mode_controller = GhostModeController()
ghost_home_center = (screen_width // 2, (screen_height) // 2)
ghosts = spawn_ghosts(ghost_home_center)
@@ -56,28 +56,36 @@ def main() -> None:
match event.key:
case pygame.K_RIGHT:
player.direction = PlayerDirection.DirectionRight
player.move_right()
case pygame.K_LEFT:
player.direction = PlayerDirection.DirectionLeft
player.move_left()
case pygame.K_UP:
player.direction = PlayerDirection.DirectionUp
player.move_up()
case pygame.K_DOWN:
player.direction = PlayerDirection.DirectionDown
player.move_down()
case pygame.JOYHATMOTION:
print("Hat has been pressed.")
hat_x, hat_y = event.value
if hat_x == 1:
player.direction = PlayerDirection.DirectionRight
player.move_right()
elif hat_x == -1:
player.direction = PlayerDirection.DirectionLeft
player.move_left()
elif hat_y == 1:
player.direction = PlayerDirection.DirectionUp
player.move_up()
elif hat_y == -1:
player.direction = PlayerDirection.DirectionDown
player.move_down()
# In your main game loop:
hud.draw(screen)
maze.draw(screen)
player.animate()
player.update()
player.draw()
ghost_mode_controller.update()
current_mode = ghost_mode_controller.mode