{Solved} Bug possibly in The Dunes Level


#1

Hey guys I am having problems on The Dunes. I know I have posted on this level before but I decided to not bring that topic up because it has been left alone for a while. So my code was working perfectly and I was about to pass when my dad asked me why I needed:

x = hero.pos.x
y = hero.pos.y

He took it out and then put it back in. So know what happens is I dodge the first two yaks but when the third comes I move to the left way before it becomes 10m away and moves before the second yak is out of the way and hits it. And of course when you hit the yaks they hit you until you die. I think it is a bug. Here is my code:

while True:
    # Get hero's current x and y position.
    x = hero.pos.x
    y = hero.pos.y
    
    # Find the nearest yak.
    yak = hero.findNearestEnemy()
    
    # If the distanceTo the yak is less than 10:
    if hero.distanceTo(yak) < 10:
        # To move right, add 10 to hero's x position.
        hero.moveXY(25, 30)
        # Use moveXY(x, y) to move!
        if hero.distanceTo(yak) < 10:
            hero.moveXY(35, 30)
            if hero.distanceTo(yak) < 10:
                hero.moveXY(45, 30)
        pass
    

#2

The hero’s x position changes as your hero traverses the desert, so the x position is constantly changing.
Try using hero.moveXY(x + 10, y).


#3

Thanks @Hellenar it worked. So hero.moveXY(x + 10, y) is utilizing:

x = hero.pos.x
y = hero.pos.y

The way I did it before:
``
x = hero.pos.x
y = hero.pos.y

was not being used. I guess. Anyway thanks a lot for your help!

#4

Happy to help, as always :smile: