console_tetris/timer.py

19 lines
404 B
Python

from time import time
class Timer:
def __init__(self) -> None:
self.running = False
self.old = 0
def control_fps(self, fps: int) -> int:
if not self.running:
self.old = time()
return
delay_between_frames = 1 / fps
now = time()
while now - self.old < delay_between_frames:
now = time()
self.old = now