Use pygame.time.Clock
Usage:
You first create a Clock. Then once every frame, you should call Clock.tick()
, which will return the amount of milliseconds passed since the last call. This way you can increment a milliseconds_passed variable, and also check, when a certain amount of time has passed.
I recommend to make a subclass of Clock, and add a millisenonds_passed variable, which will avoid any clutter in your code.
EDIT:
There are a few mistakes in your code.
Firstly, Clock.tick()
is not called once every frame. It is called once every frame when the dog collides with the ball. Move it preferably to your run method.
Secondly, you are not getting the return value of your clock. As I wrote, it returns the amount of milliseconds passed since the last call. So create a new variable, that will be increased by what that method returns. Lastly what you will need is a simple check, you could even do it in the same if statement. Like this:
if rect.colliderect(rect2) == True and self.time_passed/1000 > 5: