Player now keeps track of the movement delay

This commit is contained in:
Marcin Kostrzewski 2020-05-09 22:54:15 +02:00
parent 752c3daa24
commit a76965cd91
3 changed files with 33 additions and 23 deletions

View File

@ -49,7 +49,7 @@ class AutomaticMovement:
def updatePlayerCoords(self): def updatePlayerCoords(self):
if self.actualTarget is not None and self.nextMove is not None: if self.actualTarget is not None and self.nextMove is not None:
self.player.move(self.nextMove) if self.player.move(self.nextMove):
self.movesList.remove(self.nextMove) self.movesList.remove(self.nextMove)
if len(self.movesList) != 0: if len(self.movesList) != 0:
self.nextMove = self.movesList[0] self.nextMove = self.movesList[0]

View File

@ -24,14 +24,27 @@ class Player(Entity):
# If a player dies, the death reason is stored here # If a player dies, the death reason is stored here
self.deathReason = None self.deathReason = None
# Tracks time between every move
self.movementTimer = 0
# Player can move only so fast
self.moveTimeout = 100
# Move; movement - Enum # Move; movement - Enum
# Returns true if the move is successful
def move(self, movement): def move(self, movement):
# Can move if timeout has elapsed
if self.movementTimer > self.moveTimeout:
self.movementTimer = 0
# Rotation # Rotation
if movement.value != Movement.FORWARD.value: if movement.value != Movement.FORWARD.value:
self.updateRotation(movement) self.updateRotation(movement)
# Else move # Else move
else: else:
self.moveForward() self.moveForward()
return True
else:
return False
# Deprecated - use move() instead # Deprecated - use move() instead
def moveForward(self): def moveForward(self):
@ -130,7 +143,8 @@ class Player(Entity):
self.timeAlive += self.timer.get_time() self.timeAlive += self.timer.get_time()
# Player gets tired every once in a while # Player gets tired every once in a while
#self.applyTimeFatigue(self.timer.get_time()) # COMMENTED FOR A_STAR_TEST #self.applyTimeFatigue(self.timer.get_time()) # COMMENTED FOR A_STAR_TEST
self.timer.tick() # Adds frametime to movementTimer
self.movementTimer += self.timer.tick()
self.determineLife() self.determineLife()

View File

@ -102,12 +102,8 @@ class Game:
# Call update() method for each entity # Call update() method for each entity
self.spritesList.update() self.spritesList.update()
# TODO: Move this to player.update() # A*
if self.moveTimer > 0:
self.moveTimer -= self.deltaTime
else:
self.movement.updatePlayerCoords() self.movement.updatePlayerCoords()
self.moveTimer = self.moveTime
# Draw all sprites # Draw all sprites
self.spritesList.draw(self.screen.pygameScreen) self.spritesList.draw(self.screen.pygameScreen)