Hi, fixed you indentations.
Indentations save lifes
and in this case, your indentations are completly messed up.
enemy = self.findNearestEnemy()
distance = self.distanceTo(enemy.pos)
if distance < 10:
item = self.findNearestItem()
distance = self.distanceTo(item.pos)
So far so good. To get the position to an item, you can simply use
self.distanceTo(item). To get the distance to a position, there is (as far as I know) no function. So you have to calculate it manually.
posX = self.pos.x
posY = self.pos.y
pointX = 39
pointY = 40
# c = Math.sqrt( [x2-x1]^2 + [y2-y1]^2 )
distanceToPoint = Math.sqrt( (pointX - posX)*(pointX - posX) + (pointY - posY)*(pointY - posY) )
Edit: Sadly the code-block is not wide enough to show the
distanceToPoint in one line. Please remeber this.