# Follow me on youtube channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q
# Help peasants to escape.
# Follow me on youtube channel Phy Tu
# Help with programming on Python, school math, physics
# https://www.youtube.com/channel/UCP5ycahCEZ24qmRRgNnko5Q
def onSpawn(event):
remainingPeasants = 3
while remainingPeasants > 0:
pet.moveXY(40, 55)
peasant = pet.findNearestByType("peasant")
if peasant:
pet.carryUnit(peasant, 40, 34)
remainingPeasants -= 1
enemy = pet.findNearestByType('munchkin')
if enemy:
pet.carryUnit(enemy, 40, 19)
pet.on("spawn", onSpawn)
while True:
enemy = None
enemies = hero.findEnemies()
for element in enemies:
if element.pos.x>30 and element.pos.x<50:
enemy = element
break
if enemy:
hero.attack(enemy)