From f1e0c3c593c4ecb1176e79e63465bc968a4f3759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Czeka=C5=84ski?= Date: Sun, 26 Apr 2020 14:33:04 +0200 Subject: [PATCH] Add automatic player movement delay --- src/game/Game.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/game/Game.py b/src/game/Game.py index 7d9d400..d05809f 100644 --- a/src/game/Game.py +++ b/src/game/Game.py @@ -45,6 +45,13 @@ class Game: self.ingameTimer = Timer() self.ingameTimer.startClock() + self.deltaTime = 0 + self.lastTimePassed = self.ingameTimer.timePassed + + self.moveTimer = 0 + self.moveTime = 300 + + self.screen = Screen(self, self.config["window"]) print("OK") @@ -69,8 +76,17 @@ class Game: while self.running: # Update ingame clock self.ingameTimer.updateTime(self.pgTimer.tick()) + + self.deltaTime = self.ingameTimer.timePassed - self.lastTimePassed + self.lastTimePassed = self.ingameTimer.timePassed + self.spritesList.update() self.eventManager.handleEvents() - self.movement.updatePlayerCoords() + + if self.moveTimer > 0: + self.moveTimer -= self.deltaTime + else: + self.movement.updatePlayerCoords() + self.moveTimer = self.moveTime self.spritesList.draw(self.screen.pygameScreen) pygame.display.flip()