while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
hero.pos - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos + 3
pass
hero.moveXY(xPos, yPos)
in order to change the value of yPos or xPos, you need to redefine them.
so, instead of “hero.pos - 3” (which you have on line 9)
you want: “yPos = yPos - 3”
and on line 13, instead of “hero.pos + 3” you want “xPos = xPos + 3”
Keep moving right, but adjust up and down as you go.
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Adjust y up or down to get away from yaks.
if enemy.pos.y > hero.pos.y:
# If the Yak is above you, subtract 3 from yPos.
xPos = xPos - 3
yPos = yPos - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
xPos = xPos + 3
yPos = yPos + 3
pass
hero.moveXY(xPos, yPos)
Sigue moviéndote a la derecha, pero ajusta hacia arriba y hacia abajo a medida que avanzas.
while True:
enemy = hero.findNearestEnemy()
xPos = hero.pos.x + 5
yPos = 17
if enemy:
# Ajusta ‘y’ sube o baja para alejarte de los yaks.
if enemy.pos.y > hero.pos.y:
# Si el Yak está por encima de ti, resta 3 de yPos.
y = y + -1
pass
elif enemy.pos.y < hero.pos.y:
# Si el Yak está debajo de ti, agrega 3 a yPos
y = y - +1
pass
hero.moveXY(xPos, yPos)