-1

So I'm doing a code, where if the ball(rectangle) hits a brick (rectangle), the brick disappear I did a list of multiple bricks

 bricks_list = [brick := Brick(6, brick_y, brick_width,brick_height),  # Brick is a class I did
brick := Brick(76, brick_y, brick_width,brick_height)]

for BRICK in bricks_list:
        brick_rect = pygame.Rect(BRICK.x, BRICK.y, brick.width, BRICK.height)
        if ball_rect.colliderect(brick_rect):
             yVel *= -1
             bricks_list.remove(BRICK)
        else:
             brick_rectangle = pygame.draw.rect(screen, LEVELS[BRICK.level], brick_rect)

BUT everytime the ball hits any brick, the brick just vanishes for few milliseconds and reappear just after

I was expecting the brick to disappear and not show on the screen again

  • Do you have a 2nd account? The code in this question looks almost identical: https://stackoverflow.com/questions/76984172/make-collide-a-rectangle-and-objects-of-a-list-pygame. Note that you are not allowed to create a second account to ask a question just to get around the fact that you are currently not allowed to ask new questions with your first account. – Rabbid76 Aug 27 '23 at 07:40

0 Answers0