def findCloser(self, creatureXY, xy): baseDistance = g.distance(creatureXY, xy) possible = None for diff in ((1, 1), (0, 1), (-1, 1), (1, -1), (0, -1), (-1, -1), (1, 0), (-1, 0)): if self.isClear(creatureXY, diff): if not self.hasCreature(creatureXY, diff): dist = g.distance([creatureXY[0]+diff[0], creatureXY[1]+diff[1]], xy) if dist < baseDistance: return diff elif dist == baseDistance: possible = diff return possible
def run(self, xy): for creatureEntry in self.creatures: if g.distance(creatureEntry.xy, xy) <= 8: if ((not creatureEntry.aware) and self.visibleTiles.count(creatureEntry.xy) != 0): creatureEntry.aware = True if creatureEntry.aware == True: target = self.findCloser(creatureEntry.xy, xy) if target == None: continue if self.hasPlayer(creatureEntry.xy, target): play.currPlayer.attack(creatureEntry.attack) continue elif not self.hasCreature(creatureEntry.xy, target): self.data[creatureEntry.xy[1]][creatureEntry.xy[0]].enemyPlaced = False creatureEntry.xy[0] += target[0] creatureEntry.xy[1] += target[1] self.data[creatureEntry.xy[1]][creatureEntry.xy[0]].enemyPlaced = True