Added maze loading. /JL
This commit is contained in:
34
pman.py
34
pman.py
@@ -1,11 +1,13 @@
|
||||
import pygame
|
||||
from actors.enums import Colors, PlayerDirection
|
||||
from actors.enums import Colors, PlayerDirection, PillType
|
||||
from actors.pacman import ActorPacman
|
||||
from labyrinth import Labyrinth
|
||||
from actors.ghosts import Blinky, Pinky, Inky, Clyde # adjust import path as needed
|
||||
from actors.ghost import Blinky, Pinky, Inky, Clyde # adjust import path as needed
|
||||
from actors.ghost_mode_controller import GhostModeController
|
||||
from scoreboard import Scoreboard
|
||||
from maze import Maze
|
||||
|
||||
__version__ = "0.2.1"
|
||||
__version__ = "0.2.3"
|
||||
|
||||
|
||||
def spawn_ghosts(center_position):
|
||||
@@ -37,7 +39,7 @@ def place_pills(maze, spacing=16):
|
||||
for x in range(width):
|
||||
if maze[y][x] == 0: # assuming 0 is path
|
||||
if x % spacing == 0 and y % spacing == 0:
|
||||
pills.add(NormalPill(x * spacing + spacing // 2, y * spacing + spacing // 2))
|
||||
pills.add(PillType.PillTypeRegular(x * spacing + spacing // 2, y * spacing + spacing // 2))
|
||||
|
||||
# Power pills in 4 corners
|
||||
corners = [
|
||||
@@ -47,26 +49,29 @@ def place_pills(maze, spacing=16):
|
||||
(height - 2, width - 2)
|
||||
]
|
||||
for cy, cx in corners:
|
||||
pills.add(PowerPill(cx * spacing + spacing // 2, cy * spacing + spacing // 2))
|
||||
pills.add(PillType.PillTypePower(cx * spacing + spacing // 2, cy * spacing + spacing // 2))
|
||||
|
||||
return pills
|
||||
|
||||
def main() -> None:
|
||||
pygame.init()
|
||||
screen_width, screen_height = 800, 800
|
||||
screen_width, screen_height = (32*29), (32*30)
|
||||
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||
pygame.display.set_caption("Pac-Man " + __version__)
|
||||
|
||||
scoreboard = Scoreboard()
|
||||
labyrinth = Labyrinth(screen, width=screen_width, height=screen_height)
|
||||
player = ActorPacman(screen, center=(200, 200))
|
||||
ghost_home_center = (maze_width // 2, maze_height // 2)
|
||||
#labyrinth = Labyrinth(screen, width=screen_width, height=screen_height)
|
||||
maze = Maze("maze/pacman_maze.txt")
|
||||
|
||||
player = ActorPacman(screen, center=maze.pacman_start)
|
||||
ghost_mode_controller = GhostModeController()
|
||||
ghost_home_center = (screen_width // 2, screen_height // 2)
|
||||
ghosts = spawn_ghosts(ghost_home_center)
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
running = True
|
||||
while running:
|
||||
screen.fill(Colors.Black)
|
||||
screen.fill(Colors.Black.value)
|
||||
|
||||
for event in pygame.event.get():
|
||||
match event.type:
|
||||
@@ -83,7 +88,8 @@ def main() -> None:
|
||||
case pygame.K_DOWN:
|
||||
player.direction = PlayerDirection.DirectionDown
|
||||
case pygame.JOYHATMOTION:
|
||||
hat_x, hat_y =event.value
|
||||
print("Hat has been pressed.")
|
||||
hat_x, hat_y = event.value
|
||||
if hat_x == 1:
|
||||
player.direction = PlayerDirection.DirectionRight
|
||||
elif hat_x == -1:
|
||||
@@ -93,7 +99,9 @@ def main() -> None:
|
||||
elif hat_y == -1:
|
||||
player.direction = PlayerDirection.DirectionDown
|
||||
|
||||
labyrinth.draw()
|
||||
#labyrinth.draw()
|
||||
# In your main game loop:
|
||||
maze.draw(screen)
|
||||
player.animate()
|
||||
player.draw()
|
||||
ghost_mode_controller.update()
|
||||
@@ -101,7 +109,7 @@ def main() -> None:
|
||||
|
||||
for ghost in ghosts:
|
||||
ghost.set_mode(current_mode)
|
||||
ghost.update(maze, pacman)
|
||||
#ghost.update(maze, pacman)
|
||||
|
||||
ghosts.draw(screen)
|
||||
scoreboard.draw(screen)
|
||||
|
Reference in New Issue
Block a user