My hero isn’t going to the nearest corrected position, and also when I’m jumping my peasants are getting pushed.
My loops are supposed to go column by column, but it seems that it’s not happening.
# Escape from the minefield.
# You need to pass the marked line. (x = 72).
trapDistance = 6
trapRange = 2
def findNearestHazard(gridPos):
position = Vector(gridPos.x, gridPos.y)
nearestDist = 9999
nearestHazard = None
for hazard in hero.findHazards():
dist = hazard.distanceTo(position)
if hazard.distanceTo(position) < nearestDist:
nearestHazard = hazard
nearestDist = dist
return nearestHazard
# Jump, Jump, JUMP!!!
allPositions = []
while True:
for x in range(4, 64, trapDistance):
for y in range(4, 64, trapDistance):
position = Vector(x, y)
hazard = findNearestHazard(position)
if hazard and hazard.distanceTo(position) > 1:
allPositions.append(position)
if hero.pos.x > 52:
hero.jumpTo(Vector(80, hero.pos.y))
elif allPositions and allPositions[-1] is not None:
hero.jumpTo(allPositions[-1])