Advertisement
cookertron

Kostik Iln Crosshair Circular Boundary

Feb 21st, 2022
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import pygame
  2. from pygame import Vector2, Rect
  3. from pygame.locals import *
  4.  
  5. WHITE = 16777215
  6. BLACK = 0
  7.  
  8. pygame.init()
  9. PDR = Rect(0, 0, 1280, 720)
  10. PDS = pygame.display.set_mode(PDR.size)
  11.  
  12. boundry_pos = Vector2(PDR.center)
  13. boundry_radius = 200
  14. crosshair_pos = Vector2(PDR.center)
  15.  
  16. exit_demo = False
  17. while not exit_demo:
  18.     for e in pygame.event.get():
  19.         if e.type == KEYUP and e.key == K_ESCAPE:
  20.             exit_demo = False
  21.  
  22.     crosshair_pos = Vector2(pygame.mouse.get_pos())
  23.     distance = boundry_pos.distance_to(crosshair_pos)
  24.     if distance >= boundry_radius:
  25.         degrees = Vector2().angle_to(crosshair_pos - boundry_pos)
  26.         crosshair_pos = Vector2(PDR.center) + Vector2(1, 0).rotate(degrees) * boundry_radius
  27.  
  28.     PDS.fill(BLACK)
  29.     pygame.draw.circle(PDS, WHITE, PDR.center, boundry_radius, 2)
  30.     pygame.draw.line(PDS, WHITE, crosshair_pos - (0, 25), crosshair_pos + (0, 25))
  31.     pygame.draw.line(PDS, WHITE, crosshair_pos - (25, 0), crosshair_pos + (25, 0))
  32.     pygame.display.update()
  33.    
  34.     pygame.time.Clock().tick(120)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement