-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Circle collideswith()
#2661
Add Circle collideswith()
#2661
Conversation
Co-authored-by: Emc2356 <[email protected]> Co-authored-by: NovialRiptide <[email protected]> Co-authored-by: ScriptLineStudios <[email protected]> Co-authored-by: Avaxar <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
All works locally. Tested with:
import pygame
from pygame import Color, Rect, Vector2
from pygame.geometry import Circle
pygame.init()
screen = pygame.display.set_mode((640, 480), 0)
white_background = pygame.Surface(screen.get_rect().size)
white_background.fill((255, 255, 255))
circle_1 = Circle((50, 50), 30)
circle_col = Color("red")
circle_2 = Circle((250, 250), 30)
circle_2_col = Color("blue")
rect_3 = Rect(40, 40, 30, 30)
rect_3_col = Color("blue")
point_4_col = Color("blue")
point_4 = Vector2(100, 150)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
circle_1.center = pygame.mouse.get_pos()
if circle_1.collideswith(circle_2):
circle_col = Color("blue")
circle_2_col = Color("green")
elif circle_1.collideswith(point_4):
circle_col = Color("blue")
point_4_col = Color("green")
elif circle_1.collideswith(rect_3):
circle_col = Color("blue")
rect_3_col = Color("green")
else:
circle_col = Color("red")
circle_2_col = Color("blue")
rect_3_col = Color("blue")
screen.blit(white_background, (0, 0))
pygame.draw.circle(screen, circle_col, (circle_1.x, circle_1.y), circle_1.r)
pygame.draw.circle(screen, circle_2_col, (circle_2.x, circle_2.y), circle_2.r)
pygame.draw.rect(screen, rect_3_col, rect_3)
pygame.draw.line(screen, point_4_col, point_4, point_4)
pygame.display.flip()
pygame.quit()
src_c/circle.c
Outdated
"Invalid shape argument, must be a CircleType, RectType, " | ||
"LineType, PolygonType or a sequence of 2 numbers"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about this one, because the argument is an instance of those types not a type itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I changed it a bit. I've removed mentions of Line and Poly as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure Coordinate should've been used instead of a sequence of two points since we don't really have a Coordinate object, it only appears in type stubs, maybe you can change that back, as for the other shapes, maybe those could stay in the message since otherwise they'd have to be added later and that could be forgotten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright.
This PR adds the much awaited Circle.collideswith function.
Credits
Geometry Project:
For code, docs and tests:
@novialriptide @Emc2356 @itzpr3d4t0r @ScriptLineStudios @avaxar @Matiiss @newpaxonian @maqa41 @blankRiot96
Also thanks to @Starbuck5 for kickstarting the idea and the occasional help!
Functionality added in this PR
circle.c
https://github.com/pygame-community/pygame-geometry/blame/main/src_c/circle.c
Credits to @Emc2356 @itzpr3d4t0r @novialriptide
geometry.pyi
https://github.com/pygame-community/pygame-geometry/blame/main/geometry.pyi
Credits to @Emc2356 @itzpr3d4t0r @novialriptide @ScriptLineStudios @avaxar
geometry_test.py
https://github.com/pygame-community/pygame-geometry/blame/main/test/test_circle.py
Credits to @itzpr3d4t0r @novialriptide
geometry.rst
https://github.com/pygame-community/pygame-geometry/blame/main/docs/circle.rst
Credits to @itzpr3d4t0r