Advertisement
ZEdKasat

Follow the Circle

Aug 4th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4. WIDTH = 970
  5. HEIGHT = 600
  6. window = pygame.display.set_mode((WIDTH, HEIGHT))
  7. red = (255, 0, 0)
  8. green = (0, 255, 0)
  9. run = True
  10. speed = 2
  11. x, y = 100, 200
  12. dx, dy = speed, speed
  13. count = 0
  14. clock = pygame.time.Clock()
  15.  
  16. color = red
  17. while run:
  18.     clock.tick(60)
  19.     window.fill((0,0,0))
  20.     for event in pygame.event.get():
  21.         if event.type == pygame.QUIT:
  22.             run = False
  23.    
  24.     x += dx
  25.     y += dy
  26.     circle = pygame.draw.circle(window, color, (x, y), 40)
  27.     m = pygame.mouse.get_pos()
  28.     r = pygame.Rect(m[0], m[1], 10,10)
  29.     pygame.mouse.set_visible(False)
  30.     rec = pygame.draw.rect(window, (0, 255, 0), r)
  31.     if not circle.colliderect(rec):
  32.         # print(count)
  33.         count += 0.1
  34.         color = red
  35.     else:
  36.         color = green
  37.    
  38.     if circle.left <= 0:
  39.         speed += 0.5
  40.         dx = speed
  41.     elif circle.right >= WIDTH:
  42.         speed += 0.5
  43.         dx = -speed
  44.     elif circle.top <= 0:
  45.         speed += 0.5
  46.         dy = speed
  47.     elif circle.bottom >= HEIGHT:
  48.         speed += 0.5
  49.         dy = -speed
  50.        
  51.         print(speed)
  52.     pygame.display.update()
  53. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement