refactor
parent
b6a097bbb3
commit
4840b016db
12
main.py
12
main.py
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue