Exemplo n.º 1
0
    def _combat(self, model, action_factory, rng):
        """
        Attack enemies
        """
        character = self.character
        player = model.player
        c_location = character.location
        p_location = player.location

        distance = ((c_location[0] - p_location[0]) ** 2 +
                    (c_location[1] - p_location[1]) ** 2) ** 0.5

        if distance == 1:
            direction = find_direction(c_location,
                                       p_location)
            pyherc.vtable['\ufdd0:attack'](character,
                                           direction)
        else:
            path, connections, updated = a_star(c_location,
                                                p_location,
                                                character.level)
            next_tile = path[1]

            direction = find_direction(character.location,
                                       next_tile)

            if pyherc.vtable['\ufdd0:is-move-legal'](character,
                                                     direction,
                                                     'walk',
                                                     action_factory):
                pyherc.vtable['\ufdd0:move'](character, direction, action_factory)
            else:
                character.tick = character.tick + 10
Exemplo n.º 2
0
    def _combat(self, model, action_factory, rng):
        """
        Attack enemies
        """
        character = self.character
        player = model.player
        c_location = character.location
        p_location = player.location

        distance = ((c_location[0] - p_location[0])**2 +
                    (c_location[1] - p_location[1])**2)**0.5

        if distance == 1:
            direction = find_direction(c_location, p_location)
            pyherc.vtable['\ufdd0:attack'](character, direction)
        else:
            path, connections, updated = a_star(c_location, p_location,
                                                character.level)
            next_tile = path[1]

            direction = find_direction(character.location, next_tile)

            if pyherc.vtable['\ufdd0:is-move-legal'](character, direction,
                                                     'walk', action_factory):
                pyherc.vtable['\ufdd0:move'](character, direction,
                                             action_factory)
            else:
                character.tick = character.tick + 10
Exemplo n.º 3
0
    def _patrol(self, model, action_factory, rng):
        """
        Patrol around the level
        """
        character = self.character
        level = self.character.level

        while (self.destination is None
               or character.location == self.destination):

            self.destination = find_free_space(level)

        path, connections, updated = a_star(character.location,
                                            self.destination,
                                            level)

        next_tile = path[1]

        direction = find_direction(character.location,
                                   next_tile)

        if pyherc.vtable['\ufdd0:is-move-legal'](character,
                                                 direction,
                                                 'walk',
                                                 action_factory):
            pyherc.vtable['\ufdd0:move'](character, direction, action_factory)
        else:
            character.tick = character.tick + 10
Exemplo n.º 4
0
def impl(context, character_name, location_name):
    character = get_character(context, character_name)
    place = get_location(context, location_name)

    path, connections, updated = a_star(whole_level,
                                        character.location, #TODO: adjacent nodes as first param
                                        place.location,
                                        character.level)
    assert len(path) > 1

    for tile in path[1:]:
        direction = find_direction(character.location,
                                   tile)
        pyherc.vtable['\ufdd0:move'](character,
                                     direction)
Exemplo n.º 5
0
    def _patrol(self, model, action_factory, rng):
        """
        Patrol around the level
        """
        character = self.character
        level = self.character.level

        while (self.destination is None
               or character.location == self.destination):

            self.destination = find_free_space(level)

        path, connections, updated = a_star(character.location,
                                            self.destination, level)

        next_tile = path[1]

        direction = find_direction(character.location, next_tile)

        if pyherc.vtable['\ufdd0:is-move-legal'](character, direction, 'walk',
                                                 action_factory):
            pyherc.vtable['\ufdd0:move'](character, direction, action_factory)
        else:
            character.tick = character.tick + 10