Look at the documentation what Surface.get_rect()
does:
Returns a new rectangle covering the entire surface. This rectangle will always start at 0, 0 with a width. and height the same size as the image.
So the Rects
never collide, since the Rect
for the car always starts at 0, 0
. An easy fix is to simply set the starting position (top
and left
) of the car Rect
while calling get_rect()
.
Change
car_rect = player.get_rect()
to:
car_rect = player.get_rect(left=playerpos[0], top=playerpos[1])
(Another way is to use the Sprite
class, which basically combines a Surface
and a Rect
.)