diff --git a/actors/enums.py b/actors/enums.py index 1a38528..45f4e39 100644 --- a/actors/enums.py +++ b/actors/enums.py @@ -19,4 +19,6 @@ class PillType(Enum): class Colors(Enum): Yellow = (255, 255, 0) Black = (0, 0, 0) - Blue = (0, 0, 255) \ No newline at end of file + Blue = (0, 0, 255) + Cyan = (0, 255, 255) + Magenta = (255, 0, 255) \ No newline at end of file diff --git a/labyrinth.py b/labyrinth.py index a9868bf..64dbbd8 100644 --- a/labyrinth.py +++ b/labyrinth.py @@ -1,5 +1,56 @@ from actors.enums import Colors import pygame +import math + +class PivotWall: + def __init__(self, screen, center, length=40, thickness=8, angle=0): + self.screen = screen + self.center = center + self.length = length + self.thickness = thickness + self.angle = angle + + def draw(self): + x, y = self.center + angle_rad = math.radians(self.angle) + dx = math.cos(angle_rad) * self.length / 2 + dy = math.sin(angle_rad) * self.length / 2 + + points = [ + (x - dx - dy * self.thickness / self.length, y - dy + dx * self.thickness / self.length), + (x - dx + dy * self.thickness / self.length, y - dy - dx * self.thickness / self.length), + (x + dx + dy * self.thickness / self.length, y + dy - dx * self.thickness / self.length), + (x + dx - dy * self.thickness / self.length, y + dy + dx * self.thickness / self.length), + ] + + pygame.draw.polygon(self.screen, Colors.Cyan, points) + + def rotate(self, delta_angle): + self.angle = (self.angle + delta_angle) % 360 + +class GhostHome: + def __init__(self, screen, center, width=100, height=60, wall_thickness=8): + self.screen = screen + self.center = center + self.width = width + self.height = height + self.wall_thickness = wall_thickness + cx, cy = self.center + self.rect = pygame.Rect(cx - width // 2, cy - height // 2, width, height) + + def draw(self): + r = self.rect + t = self.wall_thickness + + pygame.draw.rect(self.screen, Colors.Magenta, (r.left, r.top + t, t, r.height -t)) + pygame.draw.rect(self.screen, Colors.Magenta, (r.right - t, r.top + t, t, r.height -t)) + pygame.draw.rect(self.screen, Colors.Magenta, (r.left, r.bottom - t, r.width, t)) + + gap = 40 + gap_x1 = r.centerx - gap // 2 + gap_x2 = r.centerx + gap // 2 + pygame.draw.rect(self.screen, Colors.Magenta, (r.left, r.top, gap_x1 - r.left, t)) + pygame.draw.rect(self.screen, Colors.Magenta, (gap_x2, r.top, r.right - gap_x2, t)) class Labyrinth: def __init__(self, screen, width, height, wall_thickness=20): @@ -7,6 +58,14 @@ class Labyrinth: self.width = width self.height = height self.wall_thickness = wall_thickness + offset = 50 + self.pivot_walls = [ + PivotWall(self.screen, (offset, offset)), + PivotWall(self.screen, (width - offset, offset)), + PivotWall(self.screen, (offset - height, offset)), + PivotWall(self.screen, (width - offset, height - offset)) + ] + self.ghost_home = GhostHome(self.screen, center=(width // 2, height // 2)) def draw(self): w = self.wall_thickness @@ -21,4 +80,13 @@ class Labyrinth: pygame.draw.rect(self.screen, Colors.Blue, (0, 0, w, mid_y -50)) pygame.draw.rect(self.screen, Colors.Blue, (0, mid_y + 50, w, self.height - (mid_y + 50))) pygame.draw.rect(self.screen, Colors.Blue, (self.width - w, 0, w, mid_y - 50)) - pygame.draw.rect(self.screen, Colors.Blue, (self.width - w, mid_y + 50, w, self.height - (mid_y + 50))) \ No newline at end of file + pygame.draw.rect(self.screen, Colors.Blue, (self.width - w, mid_y + 50, w, self.height - (mid_y + 50))) + + for pivot in self.pivot_walls: + pivot.draw() + + self.ghost_home.draw() + + def rotate_all_pivots(self, angle): + for pivot in self.pivot_walls: + pivot.rotate(angle) \ No newline at end of file diff --git a/pman.py b/pman.py index e2c7c02..210573b 100644 --- a/pman.py +++ b/pman.py @@ -3,7 +3,7 @@ from actors.enums import Colors, PlayerDirection from actors.pacman import ActorPacman from labyrinth import Labyrinth -__version__ = "0.1.1" +__version__ = "0.1.2" def main() -> None: pygame.init() @@ -43,7 +43,8 @@ def main() -> None: player.direction = PlayerDirection.DirectionUp elif hat_y == -1: player.direction = PlayerDirection.DirectionDown - + + labyrinth.draw() player.animate() player.draw() pygame.display.flip()