rect collision with list of rects

Use pygame.Rect.collidelist to test whether a rectangle collides with one of a list of rectangles.

collidelist:

Test whether the rectangle collides with any in a sequence of rectangles. The index of the first collision found is returned. If no collisions are found an index of -1 is returned.

if player_rect.collidelist(tile_rects) >= 0:
    # [...]

Leave a Comment