Added timer to main loop

This commit is contained in:
Marcin Kostrzewski 2020-04-05 21:54:35 +02:00
parent e78099deb1
commit d9c4e9b97b

View File

@ -36,6 +36,11 @@ class Game:
print("The screen cannot be in a vertical orientation. Exiting...") print("The screen cannot be in a vertical orientation. Exiting...")
exit(1) exit(1)
# Initialize timers
self.pgTimer = pygame.time.Clock()
self.ingameTimer = Timer()
self.ingameTimer.startClock()
self.screen = Screen(self, self.config["window"]) self.screen = Screen(self, self.config["window"])
print("OK") print("OK")
@ -45,6 +50,9 @@ class Game:
def mainLoop(self): def mainLoop(self):
while self.running: while self.running:
# Update ingame clock
self.ingameTimer.updateTime(self.pgTimer.tick())
self.eventManager.handleEvents() self.eventManager.handleEvents()
self.spritesList.draw(self.screen.pygameScreen) self.spritesList.draw(self.screen.pygameScreen)
pygame.display.flip() pygame.display.flip()