Please help me, I’ve looked at other forums and taken their advice, but I just can’t pass the level.
(I have the long sword and 361 health points. The problem is that the humans keep dying.)
loop:
currentHealth = self.health
healingThreshold = self.maxHealth / 3
enemy = self.findNearest(self.findEnemies())
distance = self.findFriends()
if currentHealth < 100:
self.moveXY(65, 45)
self.say("heal me")
if enemy:
self.move({"x": enemy.pos.x, "y":enemy.pos.y})
if self.isReady("cleave"):
if self.distanceTo(enemy) < 6:
self.cleave()
else:
self.attack(enemy)
if distance > 5:
self.shield()
you define healingThreshold but you don’t use it (hint: compare it with your current health)
if you use distance to hold the distance to your enemy, then use it and don’t calculate it again:
if self.distanceTo(enemy) < 6:
if you need healing and there is an enemy, you’ll try to do both (hint: use elif) – this is not really a “problem”
you attack your enemy (this will automatically move your hero to the enemy, except if you have a ranged weapon), and then you check if the enemy is more than 5 units away:
self.attack(enemy) # this moves you to the enemy
if distance > 5: # so you will never shield
self.shield()
Thank you so much, I did what you suggested and I still didn’t beat it, but I bought the flags that were allowed in the level, added the find flag code, and I beat it!
Also, to answer @ChronistGilver 's question, I was trying to shield my ‘friends’ but it didn’t really work. I guess I forgot to erase it.