Avatar ·

Питон код самодвижения

📁 python, вопрос, помощь, ошибка, новичок

Почему в этом коде фигура не идет влево? Как зациклить движение?

 

import pygame
pygame.init()
WIDTH = 500
HEIGHT = 500
FPS = 60
screen = pygame.display.set_mode((WIDTH, HEIGHT ))
clock = pygame.time.Clock()
BG = (72, 209, 204)
red = (255, 0, 0)
pl = pygame.Rect(0,0,50,50)
direct = True


while True:
    screen.fill(BG)
    pygame.draw.rect(screen,red,pl,8)
    if direct:
        if pl.y <= 450: # down
            pl.y += 3
        else:
            direct = False # stop

    else:
        if pl.x <= 450: # rigth
            pl.x += 3
        else:
            direct = False # stop


            if pl.y >= 0:
                pl.y -= 3
            else:
                direct = False


                if pl.x >= 0:
                    pl.x -= 3
                else:
                    direct = False
     

    pygame.display.update()
    clock.tick(FPS)