From 5395c87e5680012d64024115fb5a0f502463061b Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:06:15 +0200 Subject: [PATCH 1/9] Update actors/enums.py --- actors/enums.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/actors/enums.py b/actors/enums.py index 4b86c41..b04cf9d 100644 --- a/actors/enums.py +++ b/actors/enums.py @@ -1,5 +1,9 @@ from enum import Enum, auto +class PillType(Enum): + NORMAL = 1 + POWER = 2 + class PlayerDirection(Enum): DirectionRight = 0 DirectionLeft = 180 From 45b882110d854d9e6e8ff0d35bde313a0f454890 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:07:32 +0200 Subject: [PATCH 2/9] Update actors/pill.py --- actors/pill.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/actors/pill.py b/actors/pill.py index a26edcc..af3a597 100644 --- a/actors/pill.py +++ b/actors/pill.py @@ -1,5 +1,22 @@ +import pygame from .enums import PillType -class Pill: - def __init__(self, typ: PillType): - self.pilltype = typ \ No newline at end of file +class Pill(pygame.sprite.Sprite): + def __init__(self, x, y, pill_type: PillType): + super().__init__() + self.x = x + self.y = y + self.pill_type = pill_type + self.radius = 2 if pill_type == PillType.NORMAL else 6 + self.color = (255, 255, 255) + self.image = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA) + pygame.draw.circle(self.image, self.color, (self.radius, self.radius), self.radius) + self.rect = self.image.get_rect(center=(x, y)) + +class NormalPill(Pill): + def __init__(self, x, y): + super().__init__(x, y, PillType.NORMAL) + +class PowerPill(Pill): + def __init__(self, x, y): + super().__init__(x, y, PillType.POWER) \ No newline at end of file From 15f8e4bb2e35a392fb64c4811f48267a10096cf9 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:08:28 +0200 Subject: [PATCH 3/9] Update actors/ghost.py --- actors/ghost.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actors/ghost.py b/actors/ghost.py index 3c45261..6949464 100644 --- a/actors/ghost.py +++ b/actors/ghost.py @@ -1,5 +1,5 @@ -from enums import GhostColor, GhostMode, GhostBehavior -from behaviors import path_toward # required if you want a fallback +from .enums import GhostColor, GhostMode, GhostBehavior +from .behaviors import path_toward # required if you want a fallback class Ghost(pygame.sprite.Sprite): def __init__(self, name, color_enum, behavior_enum, position, speed): From b3e48c4039471c416c4c76c491842b9e8a6f51d6 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:08:48 +0200 Subject: [PATCH 4/9] Update actors/ghost_mode_controller.py --- actors/ghost_mode_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actors/ghost_mode_controller.py b/actors/ghost_mode_controller.py index 634d232..4732b7c 100644 --- a/actors/ghost_mode_controller.py +++ b/actors/ghost_mode_controller.py @@ -1,5 +1,5 @@ import time -from enums import GhostMode +from .enums import GhostMode class GhostModeController: def __init__(self): From 9e137a333caa24ecac00a1db6851ff2efde41815 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:17:24 +0200 Subject: [PATCH 5/9] Update pman.py --- pman.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pman.py b/pman.py index c8e2cfb..e39e877 100644 --- a/pman.py +++ b/pman.py @@ -4,7 +4,7 @@ from actors.pacman import ActorPacman from labyrinth import Labyrinth from actors.ghosts import Blinky, Pinky, Inky, Clyde # adjust import path as needed -__version__ = "0.2.0" +__version__ = "0.2.1" def spawn_ghosts(center_position): @@ -26,6 +26,30 @@ 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(NormalPill(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(PowerPill(cx * spacing + spacing // 2, cy * spacing + spacing // 2)) + + return pills + def main() -> None: pygame.init() screen_width, screen_height = 800, 800 From e53b52b1d7f4e5956e18f96d9ecf3a8729643d1c Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:18:22 +0200 Subject: [PATCH 6/9] Update actors/pill.py --- actors/pill.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/actors/pill.py b/actors/pill.py index af3a597..2329ba0 100644 --- a/actors/pill.py +++ b/actors/pill.py @@ -1,5 +1,5 @@ import pygame -from .enums import PillType +from enums import PillType class Pill(pygame.sprite.Sprite): def __init__(self, x, y, pill_type: PillType): @@ -7,16 +7,38 @@ class Pill(pygame.sprite.Sprite): self.x = x self.y = y self.pill_type = pill_type + self.eaten = False self.radius = 2 if pill_type == PillType.NORMAL else 6 self.color = (255, 255, 255) self.image = pygame.Surface((self.radius * 2, self.radius * 2), pygame.SRCALPHA) pygame.draw.circle(self.image, self.color, (self.radius, self.radius), self.radius) self.rect = self.image.get_rect(center=(x, y)) + def check_eaten(self, pacman_rect, game_state): + if not self.eaten and self.rect.colliderect(pacman_rect): + self.eaten = True + self.kill() + return self.on_eaten(game_state) + return 0 + + def on_eaten(self, game_state): + """Override this in subclasses to apply effects when eaten""" + return 0 + class NormalPill(Pill): def __init__(self, x, y): super().__init__(x, y, PillType.NORMAL) + def on_eaten(self, game_state): + game_state["score"] += 100 + return 100 + class PowerPill(Pill): def __init__(self, x, y): - super().__init__(x, y, PillType.POWER) \ No newline at end of file + super().__init__(x, y, PillType.POWER) + + def on_eaten(self, game_state): + game_state["score"] += 500 + game_state["ghost_mode"] = "frightened" + game_state["frightened_timer"] = pygame.time.get_ticks() # Optional + return 500 \ No newline at end of file From ddfe6f706d6f293b65aa3a0dc091fa35782651e4 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:22:18 +0200 Subject: [PATCH 7/9] Add scoreboard.py --- scoreboard.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 scoreboard.py diff --git a/scoreboard.py b/scoreboard.py new file mode 100644 index 0000000..560ed6a --- /dev/null +++ b/scoreboard.py @@ -0,0 +1,18 @@ +import pygame + +class Scoreboard: + def __init__(self, font_size=24): + self.score = 0 + self.font = pygame.font.Font(None, font_size) + self.color = (255, 255, 255) + self.position = (10, 10) + + def add_points(self, points): + self.score += points + + def reset(self): + self.score = 0 + + def draw(self, screen): + score_text = self.font.render(f"Score: {self.score}", True, self.color) + screen.blit(score_text, self.position) \ No newline at end of file From 0776a21bffd05de6c124c9bbe09ff7642abaa53d Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:24:53 +0200 Subject: [PATCH 8/9] Update pman.py --- pman.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pman.py b/pman.py index e39e877..a0eb9ac 100644 --- a/pman.py +++ b/pman.py @@ -3,6 +3,7 @@ from actors.enums import Colors, PlayerDirection from actors.pacman import ActorPacman from labyrinth import Labyrinth from actors.ghosts import Blinky, Pinky, Inky, Clyde # adjust import path as needed +from scoreboard import Scoreboard __version__ = "0.2.1" @@ -56,6 +57,7 @@ def main() -> None: 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) From c4c7c7caaecfe8450807a2c3da278f0db61a6bb6 Mon Sep 17 00:00:00 2001 From: Lerking Date: Tue, 15 Apr 2025 22:27:28 +0200 Subject: [PATCH 9/9] Update pman.py --- pman.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pman.py b/pman.py index a0eb9ac..72c90fc 100644 --- a/pman.py +++ b/pman.py @@ -104,6 +104,7 @@ def main() -> None: ghost.update(maze, pacman) ghosts.draw(screen) + scoreboard.draw(screen) pygame.display.flip() clock.tick(60)