add tick function for mob movement

This commit is contained in:
Xevion
2020-04-21 18:18:25 -05:00
parent 02a650d72b
commit 9b133749af
3 changed files with 18 additions and 3 deletions

View File

@@ -40,11 +40,25 @@ class Mob(arcade.Sprite):
return (round(self.center_x / Config.TILE_SIZE),
round(self.center_y / Config.TILE_SIZE))
def tick(self) -> None:
def tick(self, path: Tuple[int, int] = None) -> None:
"""
A on_update function, the Mob should decide it's next actions here.
"""
pass
pos, next = self.nearestPosition(), path[0]
if next[0] > pos[0]:
self.change_x = Config.PLAYER_MOVEMENT_SPEED
elif next[0] < pos[0]:
self.change_x = -Config.PLAYER_MOVEMENT_SPEED
else:
self.change_x = 0
if next[1] > pos[1]:
self.change_y = Config.PLAYER_MOVEMENT_SPEED
elif next[1] < pos[1]:
self.change_y = Config.PLAYER_MOVEMENT_SPEED
else:
self.change_y = 0
def get_path(self, end: Tuple[int, int] = None) -> List[Tuple[int, int]]:
"""