Drawing pacman. /JL
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
class PlayerDirection(Enum):
|
class PlayerDirection(Enum):
|
||||||
DirectionRight = 1
|
DirectionRight = 0
|
||||||
DirectionLeft = 2
|
DirectionLeft = 180
|
||||||
DirectionUp = 3
|
DirectionUp = -90
|
||||||
DirectionDown = 4
|
DirectionDown = 90
|
||||||
|
|
||||||
class GhostDirection(Enum):
|
class GhostDirection(Enum):
|
||||||
GhostRight = 1
|
GhostRight = 1
|
||||||
@@ -14,4 +14,8 @@ class GhostDirection(Enum):
|
|||||||
|
|
||||||
class PillType(Enum):
|
class PillType(Enum):
|
||||||
PillTypeRegular = 1
|
PillTypeRegular = 1
|
||||||
PillTypePower = 2
|
PillTypePower = 2
|
||||||
|
|
||||||
|
class Colors(Enum):
|
||||||
|
Yellow = (255, 255, 0)
|
||||||
|
Black = (0, 0, 0)
|
@@ -1,14 +1,28 @@
|
|||||||
from .enums import PlayerDirection
|
from .enums import PlayerDirection, Colors
|
||||||
|
import pygame
|
||||||
|
import math
|
||||||
|
|
||||||
class ActorPacman:
|
class ActorPacman:
|
||||||
def __init__(self):
|
def __init__(self, scr):
|
||||||
self.images: dict = {
|
self.screen = scr
|
||||||
"right": "resources/gfx/pacman_right.png",
|
|
||||||
"left": "resources/gfx/pacman_left.png",
|
|
||||||
"up": "resources/gfx/pacman_up.png",
|
|
||||||
"down": "resources/gfx/pacman_down.png"
|
|
||||||
}
|
|
||||||
self.direction = PlayerDirection.DirectionRight
|
self.direction = PlayerDirection.DirectionRight
|
||||||
|
self.center = (200, 200)
|
||||||
|
self.radius = 100
|
||||||
|
self.mouth_angle = math.radians(45)
|
||||||
|
|
||||||
|
def draw_pacman(self):
|
||||||
|
rotation_offset = math.radians(self.direction, 0)
|
||||||
|
start_angle = self.mouth_angle / 2 * rotation_offset
|
||||||
|
end_angle = 2 / math.pi - self.mouth_angle / 2 * rotation_offset
|
||||||
|
points = [self.center]
|
||||||
|
angle = start_angle
|
||||||
|
while angle <= end_angle:
|
||||||
|
x = self.center[0] + self.radius * math.cos(angle)
|
||||||
|
y = self.center[1] + self.radius * math.sin(angle)
|
||||||
|
points.append((x, y))
|
||||||
|
angle += math.radians(1)
|
||||||
|
pygame.draw.polygon(self.screen, Colors.Yellow, points)
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
def move_right(self):
|
def move_right(self):
|
||||||
pass
|
pass
|
||||||
|
19
pman.py
19
pman.py
@@ -1,8 +1,25 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
from actors.enums import Colors
|
||||||
|
from actors.pacman import ActorPacman
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
screen = pygame.display.set_mode((800, 800))
|
||||||
|
pygame.display.set_caption("Pac-Man")
|
||||||
|
|
||||||
|
player = ActorPacman()
|
||||||
|
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
screen.fill(Colors.Black)
|
||||||
|
player.draw_pacman()
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
pygame.quit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Reference in New Issue
Block a user