mirror of
https://github.com/n0remac/game-jam-2020.git
synced 2025-12-07 13:13:15 -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
|
# Constants used to scale our sprites from their original size
|
||||||
CHARACTER_SCALING = 1
|
CHARACTER_SCALING = 1
|
||||||
TILE_SCALING = 2
|
TILE_SCALING = 1
|
||||||
TILE_SIZE = TILE_WIDTH * TILE_SCALING
|
TILE_SIZE = TILE_WIDTH * TILE_SCALING
|
||||||
|
|
||||||
# The number of pixels across the level
|
# The number of pixels across the level
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ class Game(arcade.Window):
|
|||||||
t2 = time.time()
|
t2 = time.time()
|
||||||
print(f'Path acquired in {round(t2 - t1, 4)}s')
|
print(f'Path acquired in {round(t2 - t1, 4)}s')
|
||||||
self.draw_path(path)
|
self.draw_path(path)
|
||||||
|
mob.tick(path)
|
||||||
|
|
||||||
self.fps.tick()
|
self.fps.tick()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
@@ -40,11 +40,25 @@ class Mob(arcade.Sprite):
|
|||||||
return (round(self.center_x / Config.TILE_SIZE),
|
return (round(self.center_x / Config.TILE_SIZE),
|
||||||
round(self.center_y / 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.
|
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]]:
|
def get_path(self, end: Tuple[int, int] = None) -> List[Tuple[int, int]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user