main
Plaza521 2022-10-27 19:59:23 +03:00 committed by GitHub
parent b6a097bbb3
commit 4840b016db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

12
main.py
View File

@ -3,7 +3,7 @@ from player import Player
import keyboard as kb import keyboard as kb
from out import Out from out import Out
from os import system from os import system
from time import sleep from time import sleep, time
class Game: class Game:
@ -28,17 +28,23 @@ class Game:
def play(self) -> None: def play(self) -> None:
system("clear||cls") system("clear||cls")
time_to_sleep = 1 / FPS
start_time = time()
different_between_time = 1 / FPS
while self.running: while self.running:
try: try:
sleep(time_to_sleep) sleep(1 / FPS - different_between_time)
start_time = time()
if not self.is_pause: if not self.is_pause:
self.pl.input() self.pl.input()
self.pl.update() self.pl.update()
self.out.draw() self.out.draw()
end_time = time()
different_between_time = start_time - end_time
except IndexError as e: except IndexError as e:
self.running = False self.running = False
print(e) print(e)