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,17 +49,17 @@ class AutomaticMovement:
def updatePlayerCoords(self):
if self.actualTarget is not None and self.nextMove is not None:
self.player.move(self.nextMove)
self.movesList.remove(self.nextMove)
if len(self.movesList) != 0:
self.nextMove = self.movesList[0]
else:
if self.canPickup:
self.pickUp()
self.canPickup = False
self.movesList = None
self.nextMove = None
self.actualTarget = None
if self.player.move(self.nextMove):
self.movesList.remove(self.nextMove)
if len(self.movesList) != 0:
self.nextMove = self.movesList[0]
else:
if self.canPickup:
self.pickUp()
self.canPickup = False
self.movesList = None
self.nextMove = None
self.actualTarget = None
def a_Star(self):
print("A* in progress ...")

View File

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

View File

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