Added Labyrinth. /JL
This commit is contained in:
@@ -18,4 +18,5 @@ class PillType(Enum):
|
|||||||
|
|
||||||
class Colors(Enum):
|
class Colors(Enum):
|
||||||
Yellow = (255, 255, 0)
|
Yellow = (255, 255, 0)
|
||||||
Black = (0, 0, 0)
|
Black = (0, 0, 0)
|
||||||
|
Blue = (0, 0, 255)
|
24
labyrinth.py
Normal file
24
labyrinth.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
from actors.enums import Colors
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
class Labyrinth:
|
||||||
|
def __init__(self, screen, width, height, wall_thickness=20):
|
||||||
|
self.screen = screen
|
||||||
|
self.width = width
|
||||||
|
self.height = height
|
||||||
|
self.wall_thickness = wall_thickness
|
||||||
|
|
||||||
|
def draw(self):
|
||||||
|
w = self.wall_thickness
|
||||||
|
mid_x = self.width // 2
|
||||||
|
mid_y = self.height // 2
|
||||||
|
|
||||||
|
pygame.draw.rect(self.screen, Colors.Blue, (0, 0, mid_x - 50, w))
|
||||||
|
pygame.draw.rect(self.screen, Colors.Blue, (mid_x + 50, self.width - (mid_x + 50), w))
|
||||||
|
pygame.draw.rect(self.screen, Colors.Blue, (0, self.height - w, mid_x - 50, w))
|
||||||
|
pygame.draw.rect(self.screen, Colors.Blue, (mid_x + 50, self.height - w, self.width - (mid_x + 50), w))
|
||||||
|
|
||||||
|
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)))
|
19
pman.py
19
pman.py
@@ -1,15 +1,18 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from actors.enums import Colors, PlayerDirection
|
from actors.enums import Colors, PlayerDirection
|
||||||
from actors.pacman import ActorPacman
|
from actors.pacman import ActorPacman
|
||||||
|
from labyrinth import Labyrinth
|
||||||
|
|
||||||
__version__ = "0.1.0"
|
__version__ = "0.1.1"
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
pygame.init()
|
pygame.init()
|
||||||
screen = pygame.display.set_mode((800, 800))
|
screen_width, screen_height = 800, 800
|
||||||
|
screen = pygame.display.set_mode((screen_width, screen_height))
|
||||||
pygame.display.set_caption("Pac-Man " + __version__)
|
pygame.display.set_caption("Pac-Man " + __version__)
|
||||||
|
|
||||||
player = ActorPacman()
|
labyrinth = Labyrinth(screen, width=screen_width, height=screen_height)
|
||||||
|
player = ActorPacman(screen, center=(200, 200))
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
@@ -30,6 +33,16 @@ def main() -> None:
|
|||||||
player.direction = PlayerDirection.DirectionUp
|
player.direction = PlayerDirection.DirectionUp
|
||||||
case pygame.K_DOWN:
|
case pygame.K_DOWN:
|
||||||
player.direction = PlayerDirection.DirectionDown
|
player.direction = PlayerDirection.DirectionDown
|
||||||
|
case pygame.JOYHATMOTION:
|
||||||
|
hat_x, hat_y =event.value
|
||||||
|
if hat_x == 1:
|
||||||
|
player.direction = PlayerDirection.DirectionRight
|
||||||
|
elif hat_x == -1:
|
||||||
|
player.direction = PlayerDirection.DirectionLeft
|
||||||
|
elif hat_y == 1:
|
||||||
|
player.direction = PlayerDirection.DirectionUp
|
||||||
|
elif hat_y == -1:
|
||||||
|
player.direction = PlayerDirection.DirectionDown
|
||||||
|
|
||||||
player.animate()
|
player.animate()
|
||||||
player.draw()
|
player.draw()
|
||||||
|
Reference in New Issue
Block a user