1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| import pygame
from pygame.locals import *
def main():
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
size = [700, 500]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
done = False
clock = pygame.time.Clock()
font = pygame.font.Font(None, 25)
frame_count = 0
frame_rate = 60
start_time = 5
# -------- Main Program Loop -----------
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill(WHITE)
total_seconds = start_time - (frame_count // frame_rate)
if total_seconds < 0:
total_seconds = 0
minutes = total_seconds // 60
seconds = total_seconds % 60
output_string = "Time left: {0:02}:{1:02}".format(minutes, seconds)
text = font.render(output_string, True, BLACK)
screen.blit(text, [250, 280])
frame_count += 1
clock.tick(frame_rate)
if total_seconds == 0:
fond = pygame.image.load("timeout.png").convert()
screen.blit(fond, (0,0))
pygame.display.flip()
pygame.init()
main()
pygame.quit() |