Вы должны добавить приложение l oop. Основное приложение l oop должно:
clock = pygame.time.Clock()
run = True
while run:
clock.tick(60)
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
# update position
# [...]
# clear the display
screen.fill(WHITE)
# draw the scene
pacman(px, py, dir_x)
# update the display
pygame.display.flip()
Более того, вы должны нарисовать pacman относительно позиции ( x
, y
) и направление (dir_x
). См. Пример:
![](https://i.stack.imgur.com/IMa98.gif)
import pygame
pygame.init()
BLACK = (0,0,0)
YELLOW = (255, 245, 59)
WHITE = (242, 242, 242)
SIZE = (500, 500)
screen = pygame.display.set_mode(SIZE)
def pacman(x, y, dir_x):
sign_x = -1 if dir_x < 0 else 1
pygame.draw.circle(screen, YELLOW, (x, y), 100,)
pygame.draw.circle(screen, BLACK, (x, y), 100, 3)
pygame.draw.circle(screen, BLACK, (x+10*sign_x, y-50), 10,)
pygame.draw.polygon(screen, WHITE, ((x, y),(x+250*sign_x, y+250),(x+250*sign_x, y-150)))
pygame.draw.line(screen, BLACK, (x, y), (x+84*sign_x, y-52), 3)
pygame.draw.line(screen, BLACK, (x, y), (x+65*sign_x, y+68), 3)
px, py, dir_x = 250, 250, 1
clock = pygame.time.Clock()
run = True
while run:
clock.tick(60)
# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
px += dir_x
if px > 300 or px < 200:
dir_x *= -1
# clear the display
screen.fill(WHITE)
# draw the scene
pacman(px, py, dir_x)
# update the display
pygame.display.flip()