Added HUD with lives and level indicators. /JL
This commit is contained in:
40
pman.py
40
pman.py
@@ -1,13 +1,12 @@
|
||||
import pygame
|
||||
from actors.enums import Colors, PlayerDirection, PillType
|
||||
from actors.pacman import ActorPacman
|
||||
from labyrinth import Labyrinth
|
||||
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 hud import HUD
|
||||
from maze import Maze
|
||||
|
||||
__version__ = "0.2.3"
|
||||
__version__ = "0.2.4"
|
||||
|
||||
|
||||
def spawn_ghosts(center_position):
|
||||
@@ -29,43 +28,19 @@ def spawn_ghosts(center_position):
|
||||
|
||||
return pygame.sprite.Group(blinky, pinky, inky, clyde)
|
||||
|
||||
def place_pills(maze, spacing=16):
|
||||
pills = pygame.sprite.Group()
|
||||
height = len(maze)
|
||||
width = len(maze[0])
|
||||
|
||||
# Normal pills
|
||||
for y in range(height):
|
||||
for x in range(width):
|
||||
if maze[y][x] == 0: # assuming 0 is path
|
||||
if x % spacing == 0 and y % spacing == 0:
|
||||
pills.add(PillType.PillTypeRegular(x * spacing + spacing // 2, y * spacing + spacing // 2))
|
||||
|
||||
# Power pills in 4 corners
|
||||
corners = [
|
||||
(1, 1),
|
||||
(1, width - 2),
|
||||
(height - 2, 1),
|
||||
(height - 2, width - 2)
|
||||
]
|
||||
for cy, cx in corners:
|
||||
pills.add(PillType.PillTypePower(cx * spacing + spacing // 2, cy * spacing + spacing // 2))
|
||||
|
||||
return pills
|
||||
|
||||
def main() -> None:
|
||||
pygame.init()
|
||||
screen_width, screen_height = (32*29), (32*30)
|
||||
screen_width, screen_height = (32*29), (32*30)+32
|
||||
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)
|
||||
cherry_img = pygame.image.load("assets/cherry.png").convert_alpha()
|
||||
hud = HUD(screen_width, screen_height, cherry_image=cherry_img)
|
||||
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)
|
||||
ghost_home_center = (screen_width // 2, (screen_height) // 2)
|
||||
ghosts = spawn_ghosts(ghost_home_center)
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
@@ -99,8 +74,8 @@ def main() -> None:
|
||||
elif hat_y == -1:
|
||||
player.direction = PlayerDirection.DirectionDown
|
||||
|
||||
#labyrinth.draw()
|
||||
# In your main game loop:
|
||||
hud.draw(screen)
|
||||
maze.draw(screen)
|
||||
player.animate()
|
||||
player.draw()
|
||||
@@ -112,7 +87,6 @@ def main() -> None:
|
||||
#ghost.update(maze, pacman)
|
||||
|
||||
ghosts.draw(screen)
|
||||
scoreboard.draw(screen)
|
||||
pygame.display.flip()
|
||||
clock.tick(60)
|
||||
|
||||
|
Reference in New Issue
Block a user