Use Dijkstra algorithm to describe monster paths
This commit is contained in:
@ -17,20 +17,15 @@ class Monster(FightingEntity):
|
||||
target = entity
|
||||
break
|
||||
|
||||
if target:
|
||||
# A Dijkstra algorithm has ran that targets the player.
|
||||
# With that way, monsters can simply follow the path.
|
||||
# If they can't move and they are already close to the player,
|
||||
# They hit.
|
||||
if target and (self.y, self.x) in target.paths:
|
||||
# Move to target player
|
||||
y, x = self.vector(target)
|
||||
if abs(y) > abs(x): # Move vertically
|
||||
if y > 0:
|
||||
self.move_down()
|
||||
else:
|
||||
self.move_up()
|
||||
else: # Move horizontally
|
||||
if x > 0:
|
||||
self.move_right()
|
||||
else:
|
||||
self.move_left()
|
||||
if self.distance_squared(target) <= 1:
|
||||
next_y, next_x = target.paths[(self.y, self.x)]
|
||||
moved = self.check_move(next_y, next_x, True)
|
||||
if not moved and self.distance_squared(target) <= 1:
|
||||
self.hit(target)
|
||||
else:
|
||||
for _ in range(100):
|
||||
|
Reference in New Issue
Block a user