Guest User

Untitled

a guest
Apr 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import pygame
  2. import sys
  3.  
  4. SCREEN_SIZE = WIDTH, HEIGHT = (640, 480)
  5. BLACK = (0, 0, 0)
  6. WHITE = (255, 255, 255)
  7. RED = (255, 50, 50)
  8. GREEN = (50, 255, 50)
  9. CIRCLE_RADIUS = 20
  10.  
  11.  
  12. pygame.init()
  13. screen = pygame.display.set_mode(SCREEN_SIZE)
  14. pygame.display.set_caption('Circles')
  15. fps = pygame.time.Clock()
  16. paused = False
  17.  
  18. ball_pos1 = [290, 140]
  19. p=True
  20. r=0
  21. e=1
  22. def update():
  23. global e
  24. global r
  25. if(e==1):
  26. ball_pos1[0]-=1
  27. ball_pos1[1]+=1
  28. r+=1
  29.  
  30. if(e==2):
  31. ball_pos1[0]+=1
  32. ball_pos1[1]+=1
  33. r+=1
  34.  
  35. if(e==3):
  36. ball_pos1[0]+=1
  37. ball_pos1[1]-=1
  38. r+=1
  39. if(e==4):
  40. ball_pos1[0]-=1
  41. ball_pos1[1]-=1
  42. r+=1
  43. if(r>=45 and e<5):
  44. r=0
  45. e+=1
  46. if(e>=5):
  47. e=1
  48.  
  49.  
  50.  
  51. def render():
  52. screen.fill(BLACK)
  53. pygame.draw.circle(screen, RED, ball_pos1, CIRCLE_RADIUS, 0)
  54. pygame.display.update()
  55. fps.tick(60)
  56. c=0
  57. t=0
  58.  
  59. while True:
  60. for event in pygame.event.get():
  61. if event.type == pygame.QUIT:
  62. pygame.quit()
  63. sys.exit()
  64. if event.type == pygame.KEYUP:
  65. if event.key == pygame.K_SPACE:
  66. paused = not paused
  67. if not paused:
  68. update()
  69. render()
  70. if(CIRCLE_RADIUS<50 and p==True):
  71. CIRCLE_RADIUS+=1
  72. c+=1
  73. elif(CIRCLE_RADIUS>20 and p==False):
  74. CIRCLE_RADIUS-=1
  75. c-=1
  76. if(c>15):
  77. p=False
  78. t+=1
  79. if(t>30):
  80. t=0
  81. c=0
  82. p=True
Add Comment
Please, Sign In to add comment