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

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


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

go = True
while go:

    plaer = pygame.Rect(x, y, 50, 50)
    vrag = pygame.Rect(x1, y1, 100, 100)

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

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



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



    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






