Не используйте pygame.time.delay()
в игре l oop. Добавить состояние game_over
. Установите состояние по окончании игры:
game_over = x >= 1000 or y >= 1000 or x <= 0 or y <= 0
И делайте разные вещи в основном приложении l oop в зависимости от состояния:
if not game_over:
# draw game scene
else:
# draw game over screen
См. Пример:
game_over = False
while run:
pygame.time.delay(100)
seconds=(pygame.time.get_ticks()-start_ticks)/1000
# handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if not game_over:
if event.key == pygame.K_LEFT:
x -= vol; width += 25
left, right, up, down = True, False, False, False
elif event.key == pygame.K_RIGHT:
x += vol; width += 25
left, right, up, down = False, True, False, False
elif event.key == pygame.K_UP:
y -= vol; height += 25
left, right, up, down = False, False, True, False
elif event.key == pygame.K_DOWN:
y += vol; height += 25
left, right, up, down = False, False, False, True
if not game_over:
game_over = x >= 1000 or y >= 1000 or x <= 0 or y <= 0
if game_over:
game_over_time = pygame.time.get_ticks()
redraw()
vol, width, height = 25, 25, 25
else:
if pygame.time.get_ticks() > game_over_time + 5000:
run = False
screen.fill((0, 0, 0))
loss("GAME OVER", (250, 0, 0))
pygame.display.flip()