"""A timer for games with set-rate FPS.
"""

import pygame

class Timer:
	"""A timer for games with set-rate FPS"""
	
	def __init__(self,fps):
		"""Initialize the timer with the desired FPS."""
		self.wait = 1000/fps
		self.nt = pygame.time.get_ticks()
		
	def tick(self):
		"""Wait correct amount of time each frame.  Call this once per frame."""
		self.ct = pygame.time.get_ticks()
		if self.ct < self.nt:
			pygame.time.wait(self.nt-self.ct)
			self.nt+=self.wait
		else: 
			self.nt = pygame.time.get_ticks()+self.wait



# vim: set filetype=python sts=4 sw=4 noet si :
