If A* destination is entity - disable stepping on it

Player shouldn't step on berry or rabbit, etc...
This commit is contained in:
Michał Czekański 2020-04-26 14:41:22 +02:00
parent f1e0c3c593
commit 1edaa1f74e

View File

@ -72,6 +72,11 @@ class AutomaticMovement:
if self.goalTest(elem.state): if self.goalTest(elem.state):
movesList = [] movesList = []
coordsWithUiOffset = [elem.state[0] + self.leftUiWidth, elem.state[0]]
if self.map.getEntityOnCoord(coordsWithUiOffset) is not None: # If goal was some entity - omit one forward movement, because player shouldn't step on entity.
elem = elem.parent
while elem.action is not None: while elem.action is not None:
movesList.append(elem.action) movesList.append(elem.action)
elem = elem.parent elem = elem.parent