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

@@ -28,7 +28,7 @@ class Config(object):
# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 1
TILE_SCALING = 2
TILE_SCALING = 1
TILE_SIZE = TILE_WIDTH * TILE_SCALING
# The number of pixels across the level

View File

@@ -126,6 +126,7 @@ class Game(arcade.Window):
t2 = time.time()
print(f'Path acquired in {round(t2 - t1, 4)}s')
self.draw_path(path)
mob.tick(path)
self.fps.tick()
except Exception:

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]]:
"""