import pygame

pygame.init()
clock=pygame.time.Clock()
import random

x = 50
y = 50
x1, y1=800,0


def vrag(name ,x,y):
    global go

    name= pygame.draw.rect(screen, (210, 210, 210), [x, y, 100, 100])
    a = random.randint(0,4)
    if a == 1:
        y=-5
    elif a == 2:
        x=+5
    elif a == 3:
        y=+5
    else:
        x=-5

    if plaer.colliderect(name):
        print("Вы проиграли")
        go = Fals



sc = pygame.display.set_mode((800,600))
pygame.display.set_caption("MyGame")

go = True
while go:

    plaer = pygame.Rect(x, y, 50, 50)
    vrag("",500, 300)

    sc.fill((255,150,0))

    pygame.draw.rect(sc, (0, 150, 255), plaer)  # Игрок
    #pygame.draw.rect(sc,(0,0,255),vrag)      #Враг







    if x1<=-100:
        x1= 800
        y1= random.randint(0,500)
    x1-=20







    Keys = pygame.key.get_pressed()
    if Keys[pygame.K_LEFT] and x>=0:
        x-=10
    Keys = pygame.key.get_pressed()
    if Keys[pygame.K_RIGHT]and x<=750:
        x += 10

    Keys = pygame.key.get_pressed()
    if Keys[pygame.K_UP] and y>=0:
        y -= 10
    Keys = pygame.key.get_pressed()
    if Keys[pygame.K_DOWN] and y<=550:
        y += 10


    pygame.display.update()
    clock.tick(30)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            go = False