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 collidepoint() #2536

Merged

Conversation

itzpr3d4t0r
Copy link
Member

@itzpr3d4t0r itzpr3d4t0r commented Oct 27, 2023

This one adds the base for adding more collision algorithms in the future for all shapes and the Circle.collidepoint function.
Also adds tests, docs and stubs.

Also adds an internal C api function for getting two doubles out of a fastcall array of PyObjects. This is used extensively across the geometry module and saves a lot of lines of code.

Can't thank @Emc2356 enough for making this possible, great job on the include stuff!

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

Co-authored-by: Emc2356 <63981925+emc2356@users.noreply.github.com>
Co-authored-by: NovialRiptide <35881688+novialriptide@users.noreply.github.com>
@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 Oct 27, 2023
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner October 27, 2023 18:53
@itzpr3d4t0r itzpr3d4t0r changed the title Add Circle collidepoint() Add Circle collidepoint() Oct 27, 2023
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 👍

Tested it works at colliding with the current mouse position:

import pygame

from pygame import Color
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")

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    if circle_1.collidepoint(pygame.mouse.get_pos()):
        circle_col = Color("blue")
    else:
        circle_col = Color("red")

    screen.blit(white_background, (0, 0))

    pygame.draw.circle(screen, circle_col, (circle_1.x, circle_1.y), circle_1.r)

    pygame.display.flip()


pygame.quit()

Copy link
Member

@novialriptide novialriptide left a comment

Choose a reason for hiding this comment

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

LGTM, I see nothing out of the ordinary here.

@novialriptide novialriptide merged commit 484cb28 into pygame-community:main Nov 2, 2023
@itzpr3d4t0r itzpr3d4t0r deleted the circle_collidepoint branch November 2, 2023 08:38
@itzpr3d4t0r itzpr3d4t0r mentioned this pull request Nov 2, 2023
89 tasks
@itzpr3d4t0r itzpr3d4t0r added this to the 2.4.0 milestone Nov 2, 2023
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.

3 participants