I really need help with the level Wild Horses. Here is my code:
loop {
// How do you find the nearest friendly unit?
// horse = ?
var horse = this.findByType("horse");
if (horse) {
var x1 = this.pos.x - 7;
var x2 = this.pos.x + 7;
var y = this.pos.y;
// var y1 = this.pos.y - 1;
if (x1 >= 7) {
// Move to the horse's y position but use x1 for the x position.
this.moveXY(x1, horse.y);
// x1 += 7;
// this.moveXY(x1, y);
}
else if (x2 <= 79) {
// Move to the horse's y position but use x2 for the x position.
this.moveXY(x2, y);
// x2 -= 7;
// this.moveXY(x2, y);
}
var distance = this.distanceTo(horse);
if (distance <= 15) {
this.say("Whoa");
// Move to the red x to return the horse to the farm.
this.moveXY(27, 54);
// Move back out into the pasture to begin looking for the next horse.
this.moveXY(28, 18);
}
}
}