Player now keeps track of the movement delay
This commit is contained in:
parent
752c3daa24
commit
a76965cd91
@ -49,17 +49,17 @@ 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]
|
||||||
else:
|
else:
|
||||||
if self.canPickup:
|
if self.canPickup:
|
||||||
self.pickUp()
|
self.pickUp()
|
||||||
self.canPickup = False
|
self.canPickup = False
|
||||||
self.movesList = None
|
self.movesList = None
|
||||||
self.nextMove = None
|
self.nextMove = None
|
||||||
self.actualTarget = None
|
self.actualTarget = None
|
||||||
|
|
||||||
def a_Star(self):
|
def a_Star(self):
|
||||||
print("A* in progress ...")
|
print("A* in progress ...")
|
||||||
|
@ -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):
|
||||||
# Rotation
|
# Can move if timeout has elapsed
|
||||||
if movement.value != Movement.FORWARD.value:
|
if self.movementTimer > self.moveTimeout:
|
||||||
self.updateRotation(movement)
|
self.movementTimer = 0
|
||||||
# Else move
|
# Rotation
|
||||||
|
if movement.value != Movement.FORWARD.value:
|
||||||
|
self.updateRotation(movement)
|
||||||
|
# Else move
|
||||||
|
else:
|
||||||
|
self.moveForward()
|
||||||
|
return True
|
||||||
else:
|
else:
|
||||||
self.moveForward()
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.movement.updatePlayerCoords()
|
||||||
self.moveTimer -= self.deltaTime
|
|
||||||
else:
|
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user