Working on tyring to complete Crux of the dessert. I have tried it with and without the hero.movexy code after building a fire trap and get the following results:
Without the code the hero tries to move to the next X location to build a trap (not checking for enemy
With the code the hero returns to the center of the crux but then goes down the next line and builds a fire trap.
Thoughts?
while True:
enemy = hero.findNearestEnemy()
if enemy:
# An enemy is to the left if the hero's x is greater than the enemy's.
isLeft = hero.pos.x > enemy.pos.x
# An enemy is above if the enemy's y is greater than the hero's.
isAbove = hero.pos.y < enemy.pos.y
# Check if the enemy is to the right of the hero:
isRight = hero.pos.x > enemy.pos.x
# Check if the enemy is below the hero.
isBelow = hero.pos.y < enemy.pos.y
# If an enemy is above and to the left, build a fire-trap accordingly.
if isLeft and isAbove:
hero.buildXY("fire-trap", 40 - 20, 34 + 17)
# Check if an enemy is above and to the right:
if isRight and isAbove:
hero.buildXY("fire-trap", 40 + 20, 34 + 17)
# Check if an enemy is below and to the left:
if isLeft and isBelow:
hero.buildXY("fire-trap", 40 - 20, 34 - 17)
# Check if an enemy is below and to the right:
if isRight and isBelow:
hero.buildXY("fire-trap", 40 + 20, 34 - 17)
else:
hero.moveXY(40, 34)
Well I would try to help you more but I can not for the life of me find the level “Crux of the Dessert”. However I think I found one error at least. You have the wrong opperator direction. The isRight and isLeft actualy are the same statement i.e. both will be true or false. The same goes with the Above and Below sections. Your symbols are mixed up a little.
Should look like this:
When I try your suggestion my Hero moves to set traps at each location but doesn’t seem to be checking for an enemy. Just placing traps. The hero ends up getting stuck at 27,51 and being killed.
Got it. now. You were right I had the symbols mixed up and was missing a move at the end.
This is my code, and I don’t know what’s wrong with it. My character just builds one firetrap, then sits in the middle.
# Figure out which direction the ogres are coming from.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Left: enemy.pos.x is less than hero.pos.x
isLeft = enemy.pos.x < hero.pos.x
# Above: enemy.pos.y is greater than hero.pos
isAbove = enemy.pos.y > hero.pos.y
# Right: enemy.pos.x is greater than hero.pos.
isRight = enemy.pos.x > hero.pos.x
# Below: enemy.pos.y is less than hero.pos.y
isBelow = enemy.pos.y < hero.pos.y
# If enemy isAbove and isLeft:
# buildXY() a "fire-trap" at the X mark.
if isLeft and isAbove:
hero.buildXY("fire-trap", 40 - 20, 34 + 17)
# If enemy isAbove and isRight:
# buildXY() a "fire-trap" at the X mark.
if isLeft and isAbove:
hero.buildXY("fire-trap", 60, 51)
# If enemy isBelow and isLeft:
# buildXY() a "fire-trap" at the X mark.
if isBelow and isLeft:
hero.buildXY("fire-trap", 20, 17)
# If enemy isBelow and isRight:
# buildXY() a "fire-trap" at the X mark.
if isBelow and isRight:
hero.buildXY("fire-trap", 60, 17)
hero.moveXY(40, 34)
else:
hero.moveXY(40, 34)
# Figure out which direction the ogres are coming from.
while True:
enemy = hero.findNearestEnemy()
if enemy:
# Left: enemy.pos.x is less than hero.pos.x
isLeft = enemy.pos.x < hero.pos.x
# Above: enemy.pos.y is greater than hero.pos
isAbove = enemy.pos.y > hero.pos.y
# Right: enemy.pos.x is greater than hero.pos.
isRight = enemy.pos.x > hero.pos.x
# Below: enemy.pos.y is less than hero.pos.y
isBelow = enemy.pos.y < hero.pos.y
# If enemy isAbove and isLeft:
# buildXY() a "fire-trap" at the X mark.
if isLeft and isAbove:
hero.buildXY("fire-trap", 40 - 20, 34 + 17)
# If enemy isAbove and isRight:
# buildXY() a "fire-trap" at the X mark.
if isLeft and isAbove:
hero.buildXY("fire-trap", 60, 51)
# If enemy isBelow and isLeft:
# buildXY() a "fire-trap" at the X mark.
if isBelow and isLeft:
hero.buildXY("fire-trap", 20, 17)
# If enemy isBelow and isRight:
# buildXY() a "fire-trap" at the X mark.
if isBelow and isRight:
hero.buildXY("fire-trap", 60, 17)
hero.moveXY(40, 34)
else:
hero.moveXY(40, 34)