0

I have created a game that has two cars who race each other by tapping buttons quicker than the other. So i want to make it where after the race ends it prints out how long it took for the winner of the race to make it to the finish line. I have tried using pygame.time.get_ticks() however that gives the time of how long since pygame.init() was called.

Petras99
  • 45
  • 6

1 Answers1

0

You can use pygame.time.get_ticks().

Set a start time and an end time and measure the difference:

import pygame as py
py.init()
clock = py.time.Clock()

start_time = py.time.get_ticks()
print "started at:",start_time

for i in xrange(0,30): #wait 1 second
    clock.tick(30)

end_time = py.time.get_ticks()
print "finished at:",end_time

time_taken = end_time-start_time
print "time taken:",time_taken
DCA-
  • 1,262
  • 2
  • 18
  • 33