It looks like you’re using the wrong code to try and solve this level.
In Basin Stampede you want to check whether the Yaks are above or below you, and move accordingly. Not move up if they are close, down if they are far.
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.
hero.pos.y - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y + 3
pass
hero.moveXY(xPos, yPos)
that was a great hint but the code doesn’t work still this is my code.
# 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.
yPos - 3
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
yPos + 3
pass
hero.moveXY(xPos, yPos)
the problem of the code is in the running corner it only lights up the hero.move(xpos, ypos)
Try this, instead of just using the if enemy: conditional, try putting if enemy and hero.distanceTo(enemy) < 12:. That way, when the yaks get closer than the given distance, it triggers the while True loop to iterate through the if conditional at a specific event. Also, the code isn’t using the reassigned values of yPos in the conditional statements. However, if you change yPos - 3 and yPos + 3 to hero.moveXY(xPos, yPos - 3) and hero.moveXY(xPos, yPos + 3) respectively, the hero then moves properly.
You may have to adjust the numbers a little bit (I did) but with these changes you should see the correct movement of the hero.
Hi! I don’t understand what’s wrong with my code. I looked the hints over and over. Please help.
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.
enemy.pos.y > hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
enemy.pos.y < hero.pos.y
pass
hero.moveXY(xPos, yPos)
I actually figured it out.
For anyone who needs help, here are some hints and pointers.
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.y = #subtract 3 from the hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)
@Rachel699 please do not revive dead topics unless you have problems at the same level. I see that you needed help, and that you solved your problem, so just try to remember that for the future.
I ned heeelp this is my code: 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.y = #subtract 3 from the hero.pos.y
pass
elif enemy.pos.y < hero.pos.y:
# If the Yak is below you, add 3 to yPos.
hero.pos.y = #add 3 to hero.pos.y
pass
hero.moveXY(xPos, yPos)