Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

Oasis, Desert, Python

I’m using Hattori with 856 health. My code is below…

while True:
    enemy = hero.findNearestEnemy()
    if enemy and hero.distanceTo(enemy) < 10:
        x = hero.pos.x - 10
        y = hero.pos.y
    else:
        x = hero.pos.x + 10
        y = hero.pos.y
    hero.moveXY(x, y)

At the end, my hero can’t properly dodge the Sand Yak.

image

I have used the same code above, and am left with -25 health.

PLEASE HELP!

You are taking a snapshot view of the hero’s x and y…this is a dynamic, which constantly changes as the hero moves. Instead, try taking a static view.

Your hero.pos.y is not going to change, so there is no need to redefine it after the first time. Instead, try something like this:

while True

define x
define y
if enemy and distance is less than 10, then
    redefine x, decrementing it by 10
oetherwise,
    redefine x, incrementing it by 10
moveXY