Skip to content
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

Merged
merged 8 commits into from
Feb 25, 2024

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]>
@itzpr3d4t0r itzpr3d4t0r added New API This pull request may need extra debate as it adds a new class or function to pygame geometry pygame.geometry labels Jan 7, 2024
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner January 7, 2024 11:40
@itzpr3d4t0r itzpr3d4t0r mentioned this pull request Jan 7, 2024
89 tasks
buildconfig/stubs/pygame/geometry.pyi Outdated Show resolved Hide resolved
docs/reST/ref/geometry.rst Outdated Show resolved Hide resolved
@itzpr3d4t0r itzpr3d4t0r requested a review from Matiiss January 28, 2024 11:53
@itzpr3d4t0r itzpr3d4t0r reopened this Jan 29, 2024
Copy link
Member

@MyreMylar MyreMylar left a 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()

test/geometry_test.py Outdated Show resolved Hide resolved
src_c/circle.c Outdated
Comment on lines 422 to 423
"Invalid shape argument, must be a CircleType, RectType, "
"LineType, PolygonType or a sequence of 2 numbers");
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.

buildconfig/stubs/pygame/geometry.pyi Show resolved Hide resolved
@Matiiss Matiiss merged commit 7699c03 into pygame-community:main Feb 25, 2024
30 checks passed
@ankith26 ankith26 added this to the 2.5.0 milestone Feb 26, 2024
@itzpr3d4t0r itzpr3d4t0r deleted the circle-collideswith branch February 27, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geometry pygame.geometry New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants