-1

So I have a list of rectangles (bricks) and I'm trying to make it collide with the ball_rect: When I execute the code, it gives me the error: "TypeError: Argument must be a sequence of objects."

bricks = [brick := Brick(6, 450, brick_width,brick_height,0),     #I've made a function for those
brick := Brick(76, 450, brick_width,brick_height,0)]

for BRICK in bricks:
 brick_rect = pygame.Rect(BRICK.x, BRICK.y, brick.width, BRICK.height)  #
        pygame.draw.rect(screen, LEVELS[BRICK.level], brick_rect)
        if ball_rect.collideobjects(BRICK):   #When I do so, I have the error stated above
             yVel *= -1

  • `ball_rect.colliderect(brick_rect)` or `ball_rect.collideobjects(bricks, key=lambda b: pygame.Rect(b.x, b.y, b.width, b.height))` – Rabbid76 Aug 26 '23 at 17:57
  • Don't use `brick :=` in your initializer. You aren't using it, and it's silly to set the same variable multiple times. The `:=` operator is, in general, best forgotten. Your key problem is in the name `collectobjects`, which is a plural. It expects to compare against a list of things. – Tim Roberts Aug 26 '23 at 18:13

0 Answers0