47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
from .enums import PlayerDirection, Colors
|
|
import pygame
|
|
import math
|
|
|
|
class ActorPacman:
|
|
def __init__(self, scr):
|
|
self.screen = scr
|
|
self.direction = PlayerDirection.DirectionRight
|
|
self.center = (200, 200)
|
|
self.radius = 100
|
|
self.mouth_angle_deg = 45
|
|
self.min_mouth_deg = 5
|
|
self.max_mouth_deg = 45
|
|
self.animate_speed = 2
|
|
self.mouth_closing = False
|
|
|
|
def animate(self):
|
|
if self.mouth_closing:
|
|
self.mouth_angle_deg -= self.animate_speed
|
|
if self.mouth_angle_deg <= self.min_mouth_deg:
|
|
self.mouth_angle_deg = self.min_mouth_deg
|
|
self.mouth_closing = False
|
|
else:
|
|
self.mouth_angle_deg += self.animate_speed
|
|
if self.mouth_angle_deg >= self.max_mouth_deg:
|
|
self.mouth_angle_deg = self.max_mouth_deg
|
|
self.mouth_closing = True
|
|
|
|
def draw(self):
|
|
mouth_angle = math.radians(self.mouth_angle_deg)
|
|
rotation_offset = math.radians(self.direction, 0)
|
|
start_angle = mouth_angle / 2 + rotation_offset
|
|
end_angle = 2 * math.pi - 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)
|
|
|
|
def move_right(self):
|
|
pass
|
|
|
|
def set_direction(self, dir: PlayerDirection):
|
|
self.direction = dir |