Add automatic player movement delay

This commit is contained in:
Michał Czekański 2020-04-26 14:33:04 +02:00
parent b8abacd4cc
commit f1e0c3c593

View File

@ -45,6 +45,13 @@ class Game:
self.ingameTimer = Timer() self.ingameTimer = Timer()
self.ingameTimer.startClock() self.ingameTimer.startClock()
self.deltaTime = 0
self.lastTimePassed = self.ingameTimer.timePassed
self.moveTimer = 0
self.moveTime = 300
self.screen = Screen(self, self.config["window"]) self.screen = Screen(self, self.config["window"])
print("OK") print("OK")
@ -69,8 +76,17 @@ class Game:
while self.running: while self.running:
# Update ingame clock # Update ingame clock
self.ingameTimer.updateTime(self.pgTimer.tick()) self.ingameTimer.updateTime(self.pgTimer.tick())
self.deltaTime = self.ingameTimer.timePassed - self.lastTimePassed
self.lastTimePassed = self.ingameTimer.timePassed
self.spritesList.update() self.spritesList.update()
self.eventManager.handleEvents() self.eventManager.handleEvents()
if self.moveTimer > 0:
self.moveTimer -= self.deltaTime
else:
self.movement.updatePlayerCoords() self.movement.updatePlayerCoords()
self.moveTimer = self.moveTime
self.spritesList.draw(self.screen.pygameScreen) self.spritesList.draw(self.screen.pygameScreen)
pygame.display.flip() pygame.display.flip()