clicktimer.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pygame
  2. pygame.init()
  3. screen = pygame.display.set_mode((450, 600))
  4. timer_font = pygame.font.Font("04B_19__.ttf", 38)
  5. timer_sec = 0
  6. timer_min = 0
  7. timer_text = timer_font.render("00:00", True, (255, 255, 255))
  8. # USEREVENTS are just integers
  9. # you can only have like 31 of them or something arbitrarily low
  10. timer = pygame.USEREVENT + 1
  11. pygame.time.set_timer(timer, 50) # sets timer with USEREVENT and delay in milliseconds
  12. running = True
  13. texter = "Click at 10:00"
  14. while running:
  15. screen.fill((0, 0, 0))
  16. for event in pygame.event.get():
  17. if event.type == pygame.QUIT:
  18. running = False
  19. if event.type == pygame.MOUSEBUTTONDOWN:
  20. mouse_x, mouse_y = pygame.mouse.get_pos()
  21. if (mouse_x < 175 + 110) and (mouse_x > 175) and (mouse_y > 160) and (mouse_y < 160+100):
  22. print("HELLO")
  23. pygame.time.set_timer(timer, 0)
  24. if (timer_min == 10) and (timer_sec == 1):
  25. texter = "HOORAY"
  26. if event.button == 1:
  27. print("Left click at:", mouse_x, mouse_y)
  28. if event.type == timer:
  29. if timer_sec < 60:
  30. timer_text = timer_font.render("%02d:%02d" % (timer_min, timer_sec), True, (212, 55, 55))
  31. timer_sec += 1
  32. else:
  33. timer_min += 1
  34. timer_sec = 0
  35. screen.blit(timer_text, (175, 20))
  36. startX = 140
  37. pygame.draw.rect(screen, (181, 119, 33), (startX, 125, 160, 20))
  38. pygame.draw.rect(screen, (240, 162, 55), (startX, 145, 160, 140))
  39. pygame.draw.circle(screen, (153, 37, 37), (startX+80,140+70),50)
  40. pygame.draw.circle(screen, (212, 55, 55), (startX+80,140+80),50)
  41. print(timer_min)
  42. print(timer_sec)
  43. instructionsText = timer_font.render(texter, True, (255, 255, 255))
  44. screen.blit(instructionsText, (40, 375))
  45. pygame.display.update()