enemies = self.findEnemies()
enemyIndex = 0
# Wrap this logic in a while loop to attack all enemies.
while enemyIndex < len(enemies):
enemy = enemies[enemyIndex]
# "!=" means "not equal to."
if enemy.type != "sand-yak":
# While the enemy's health is greater than 0, attack it!
while enemy.health > 0:
enemyIndex += 1
# Between waves, move back to the center.
The code above has been corrected, but I would suggest you think about a couple of things as it is not a great answer unless you are over geared for the level.
- Is there a better order in which to attack the mobs?
Currently, you could end up zigzagging all over the field. Do you have access to findNearest(), the health property and/or distanceTo() for example?
- When your targets are outside of your current range, in which direction should you move or use moveXY?
If you do not have access to .move, think about what this does:
Fx = (self.pos.x * 9 + enemy.pos.x)/10
Fy = (self.pos.y*9 + enemy.pos.y)/10
You might also look into Vector math in terms of deciding where to go next. I will admit to that maybe being overkill for this level, but it will come in handy later.
Apologies on formatting above, on )$&&@: tablet device. Sigh … also just realized how old this thread was. Apology for the necromancy.