mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-06 03:13:12 -06:00
add tick function for mob movement
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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]]:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user