Need help with the Crux of the desert level

// Figure out which direction the ogres are coming from.

int main() {
    while(true) {
        auto enemy = hero.findNearestEnemy();
        if(enemy) {
            // Left: enemy.pos.x is less than hero.pos.x
            auto isLeft = hero.pos.x  > enemy.pos.x;
            // Above: enemy.pos.y is greater than hero.pos.y
            auto isAbove = hero.pos.y < enemy.pos.y;
            // Right: enemy.pos.x is greater than hero.pos.x
            auto isRight = hero.pos.x < enemy.pos.y;
            // Below: enemy.pos.y is less than hero.pos.y
            auto isBelow = hero.pos.y > enemy.pos.y;
            // If enemy isAbove and isLeft:
            // buildXY() a "fire-trap" at the X mark.
            if(isLeft && isAbove) {
                hero.buildXY("fire-trap", 20, 51);
            }
            // If enemy isAbove and isRight:
            // buildXY() a "fire-trap" at the X mark.
            if (isAbove && isRight) {
                hero.buildXY("fire-trap", 60, 51);
            }
            // If enemy isBelow and isLeft:
            // buildXY() a "fire-trap" at the X mark.
            if (isBelow && isLeft) {
                hero.buildXY("fire-trap", 20, 17);
            }
            // If enemy isBelow and isRight:
            // buildXY() a "fire-trap" at the X mark.
            if (isBelow && isRight) {
                hero.buildXY("fire-trap", 60, 17);
            }
        } 
        else {
            hero.moveXY(40, 34);
        }
    }
    return 0;
}

The hero needs to move back to (40, 34) after placing a fire trap as well or they will blow themselves up.

That’s the point of the else, it means that when no enemies are on screen it returns to those coordinates, the problem i’m experiencing is that there is around a 15 second buffer period until my code even begins to do something so asking to see if my coding is the problem

Oh i see now. It took me a little to find it but auto isRight = hero.pos.x < enemy.pos.y; has a y instead of an x for enemy.pos

Thank you, appreciate it.

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.