Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. # Impordime vajaminevad moodulid
  2. import pygame
  3. import random
  4. import time
  5.  
  6. # defineerime värvid
  7. valge = [255, 255, 255]
  8. punane = [255, 0, 0]
  9. roheline = [0, 255, 0]
  10. sinine = [0, 0, 255]
  11. must = [0, 0, 0]
  12. laius = 800
  13. korgus= 600
  14.  
  15. ringX = 100
  16. ringY = 100
  17. suundX = 0
  18. suundY = 1
  19. count = 0
  20.  
  21. raadius = 20
  22.  
  23. pygame.init()
  24.  
  25. ekraan = pygame.display.set_mode([laius, korgus])
  26.  
  27.  
  28. def colour(): # Funktsioon, mis tagastab suvalise värvi
  29. varv = [random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)]
  30. return varv
  31.  
  32. varv = colour()
  33.  
  34. running = True
  35. while running:
  36. for i in pygame.event.get():
  37. if i.type == pygame.QUIT:
  38. running = False
  39. elif i.type == pygame.MOUSEBUTTONDOWN:
  40. mouseX = i.pos[0]
  41. mouseY = i.pos[1]
  42. #if mouseX > ringX - raadius and mouseX < ringX + raadius and mouseY > ringY -raadius and ringY < mouseY + raadius:
  43. if abs(mouseX - ringX) < raadius and abs(mouseY - ringY) < raadius:
  44. varv = colour ()
  45. count = count + 1
  46. raadius = random.randint(5, 20)
  47. ringX = random.randint(raadius, laius - raadius)
  48. ringY = 0
  49. # random.choice([-1, 1])
  50. print("Pihtas! Punkte:", count)
  51.  
  52.  
  53. ekraan.fill(valge)
  54.  
  55. pygame.draw.circle(ekraan, varv, [ringX, ringY], raadius, 0)
  56.  
  57. ringX = ringX + suundX
  58. ringY = ringY + suundY
  59.  
  60.  
  61.  
  62. if ringY == korgus - raadius:
  63. ringY = 0
  64. ringX = random.randint(raadius, laius - raadius)
  65. print ("Punktid nullis :( ")
  66. count = 0
  67. varv = colour()
  68.  
  69. pygame.display.flip()
  70.  
  71. time.sleep(0.01)
  72.  
  73. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement