2

Hi I'm trying to make a simple 2d car game with pygame and I'm trying to add collisions between two cars, but i keep getting this error:

Traceback (most recent call last):
  File "C:\Users\emilio pinto\Desktop\Running car proj\Running car.py", line 69, in <module>
    if pygame.Rect.collidelist(car1,car2) >= 0:
TypeError: Argument must be a sequence of rectstyle objects.

I'm pretty sure that i've been using the .Rect module good, anyway these are the variables and how i'm trying to use them:


car1=pygame.Rect((xCar, yCar), (60, 30))
car2=pygame.Rect((xCar2, yCar2), (60, 30))

    if pygame.Rect.collidelist(car1,car2) >= 0:
        running=False
        screen.fill((0,0,0))
        screen.blit(loseText, (142, 90))
        screen.blit(loseText2,(110, 170))
        pygame.display.flip()
        if keys[pygame.K_SPACE]:
            running=True
            continue
Emilio P.
  • 23
  • 2

1 Answers1

2

This should solve your problem:

if pygame.Rect.colliderect(car1,car2) >= 0:

explanation:

You're using either the wrong function, or the wrong parameters for that function.

Use Rect.colliderect for two objects: https://www.pygame.org/docs/ref/rect.html#pygame.Rect.colliderect

Or use Rect.collidelist for a list of objects. Therefore you must put car1 and car2 inside a list object. https://www.pygame.org/docs/ref/rect.html#pygame.Rect.collidelist

aronadaal
  • 9,083
  • 1
  • 19
  • 33