def execute(self, actor): moved = False while not moved: if self.path is None: x, y = self.points[self.index] self.path = actor.find_path(x, y) if self.path is not None and self.path.has_next(): if can_move(actor, self.path.get()): self.path.next() return 'Success' else: self.path = None else: self.index = (self.index + 1) % len(self.points) self.path = None
def execute(self, actor): perception = actor.components['Perception'] if perception.sound is None: return 'Failed' print 'Investigate : ' + str(perception.sound.loudness) path = actor.find_path(perception.sound.x, perception.sound.y) if path is not None and path.has_next(): if can_move(actor, path.get()): path.next() return 'Success' perception.sound = None return 'Failed'
def execute(self, actor): enemies = actor.components['Perception'].get_enemies() #print 'Attack: ', actor.name, ' ', len(enemies) if len(enemies) is 0: return 'Failed' enemy = enemies[0] if can_attack(actor, enemy): #actor.attack(enemy) return 'Success' path = actor.find_path(enemy.body.x, enemy.body.y) if path is not None and path.has_next(): if can_move(actor, path.get()): path.next() return 'Success' return 'Failed'
def move(direction): global hero can_move(hero, direction)