From 4840b016db59c461dedf8166a3240718cbb868e9 Mon Sep 17 00:00:00 2001 From: Plaza521 <89989298+Plaza521@users.noreply.github.com> Date: Thu, 27 Oct 2022 19:59:23 +0300 Subject: [PATCH] refactor --- main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index e886677..8ca671f 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from player import Player import keyboard as kb from out import Out from os import system -from time import sleep +from time import sleep, time class Game: @@ -28,17 +28,23 @@ class Game: def play(self) -> None: system("clear||cls") - time_to_sleep = 1 / FPS + + start_time = time() + different_between_time = 1 / FPS while self.running: try: - sleep(time_to_sleep) + sleep(1 / FPS - different_between_time) + start_time = time() if not self.is_pause: self.pl.input() self.pl.update() self.out.draw() + end_time = time() + different_between_time = start_time - end_time + except IndexError as e: self.running = False print(e)