import pygame
import random
import time
def distance(x1, y1, x2, y2):
____dist = pow((pow(x2-x1,2)+pow(y2-y1,2)),0.5)
____return dist
pygame.init()
screen = pygame.display.set_mode((600, 600))
pygame.display.set_caption("Быстро!")
screen.fill((255,255,255))
pygame.display.flip()
FPS = 30
game_run = True
X, Y, R = 50, 120, 30
speed = 3
width = 580
clock = pygame.time.Clock()
catch = False
no_catch = False
timer_crasch = 0
point = 0
font_losing = pygame.font.SysFont('Arial', 50)
font_point = pygame.font.SysFont('Arial', 40)
text_losing = font_losing.render('Время вышло!', True, (255,255,255))
crasch = font_point.render('Штраф!', True, (255,0, 0))
text_point = font_point.render(str(point),True, (0,0,0))
while game_run:
____clock.tick(FPS)
____for event in pygame.event.get():
________if event.type == pygame.QUIT:
____________game_run = False
________if event.type == pygame.MOUSEBUTTONDOWN:
____________if event.button == 1:
________________if distance(X,Y, event.pos[0], event.pos[1]) <= R:
___________________catch = True
___________________point += 1
___________________text_point = font_point.render(str(point),True, (0,0,0))
________________else:
no_catch = True
____width -= speed
____if width < 10:
________screen.fill((255, 0, 0))
________screen.blit(text_losing,(170, 200))
________point_end = font_losing.render(str(point),True,(255,255,255))
________screen.blit(point_end, (270,300))
________pygame.display.flip()
________time.sleep(3)
________game_run = False
____if catch:
________width += 50
________X = random.randint(30, 570)
________Y = random.randint(120, 570)
________catch = False
____if no_catch:
________point -= 1
________width -= 50
________no_catch = False
________timer_crasch = 30
____screen.fill((255, 255, 255))
____pygame.draw.rect(screen, (255, 0, 0), (10, 10, width, 25))
____screen.blit(text_point,(20,40))
____if timer_crasch > 0:
________text_point = font_point.render(str(point), True, (0, 0, 0))
________screen.blit(crasch, (180, 40))
________timer_crasch -= 1
____pygame.draw.circle(screen, (0,255,0), (X, Y), R)
____pygame.display.flip()
pygame.quit()