Example #1
0
 def connect(x1, y1, x2, y2):
     T.path_compute(path, x1, y1, x2, y2)
     for i in range(T.path_size(path)):
         x, y = T.path_get(path, i)
         c = arr[x][y]
         if c == '#' or c == ' ':
             arr[x][y] = '.'
Example #2
0
    def followPath(self):
        direction = [0, 0]

        if self.path != None:
            if self.reachedEndOfPath():
                self.path = None
                return direction
            j = 0
            if not self.newPath:
                for i in range (libtcod.path_size(self.path)) :
                    pathx, pathy = libtcod.path_get(self.path, i)
                    if [self.owner.x, self.owner.y] == [pathx, pathy]:
                        j = i + 1
            if j == 0 and not self.newPath:
                self.path = None
            else:
                self.newPath = False
                tx, ty = libtcod.path_get(self.path, j)
                direction = [tx - self.owner.x, ty - self.owner.y]

        return direction
Example #3
0
def monster_move(level, monster):
    update_monster_state(level, monster)
    stationary = "S" in monster.flags
    is_active = monster.state == "ACTIVE"
    is_confused = monster.state.startswith("CONFUSED")
    if is_active or is_confused or is_flying_targeting(monster):
        x, y = movements[choice(list(movements))]
        _move(monster, x, y, level, stationary)
    elif monster.state == "TARGETING":
        diag = 1.95 if is_transparent(monster.location, level) else 0
        try:
            astar = tcod.path_new_using_map(level.map_grid, diag)
            tcod.path_compute(astar, monster.location.x, monster.location.y,
                              level.player.location.x, level.player.location.y)
            next_tile = tcod.path_get(astar, 0)
        except:
            print("ASTAR FAILURE")
            next_tile = (randint(-1, 1), randint(-1, 1))
        x, y = (next_tile[0] - monster.location.x,
                next_tile[1] - monster.location.y)
        _move(monster, x, y, level, stationary)

    close = distance_to(monster.location, level.player.location) > 2
    if "L" in monster.flags and close and in_fov(monster.location, level):
        update_screen(level)
        try:
            astar = tcod.path_new_using_map(level.map_grid, 1.95)
            tcod.path_compute(astar, level.player.location.x,
                              level.player.location.y, monster.location.x,
                              monster.location.y)
            next_tile = tcod.path_get(astar, 0)
        except:
            print("ASTAR FAILURE")
            next_tile = (randint(-1, 1), randint(-1, 1))
        x, y = (next_tile[0] - level.player.location.x,
                next_tile[1] - level.player.location.y)
        _move(level.player, x, y, level)
def test_astar(map_):
    astar = libtcodpy.path_new_using_map(map_)

    assert not  libtcodpy.path_compute(astar, *POINTS_AC)
    assert  libtcodpy.path_size(astar) == 0
    assert  libtcodpy.path_compute(astar, *POINTS_AB)
    assert  libtcodpy.path_get_origin(astar) == POINT_A
    assert  libtcodpy.path_get_destination(astar) == POINT_B
    libtcodpy.path_reverse(astar)
    assert libtcodpy.path_get_origin(astar) == POINT_B
    assert libtcodpy.path_get_destination(astar) == POINT_A

    assert libtcodpy.path_size(astar) != 0
    assert libtcodpy.path_size(astar) > 0
    assert not libtcodpy.path_is_empty(astar)

    for i in range(libtcodpy.path_size(astar)):
        x, y = libtcodpy.path_get(astar, i)

    while (x, y) != (None, None):
        x, y = libtcodpy.path_walk(astar, False)

    libtcodpy.path_delete(astar)
Example #5
0
def test_astar(map_):
    astar = libtcodpy.path_new_using_map(map_)

    assert not libtcodpy.path_compute(astar, *POINTS_AC)
    assert libtcodpy.path_size(astar) == 0
    assert libtcodpy.path_compute(astar, *POINTS_AB)
    assert libtcodpy.path_get_origin(astar) == POINT_A
    assert libtcodpy.path_get_destination(astar) == POINT_B
    libtcodpy.path_reverse(astar)
    assert libtcodpy.path_get_origin(astar) == POINT_B
    assert libtcodpy.path_get_destination(astar) == POINT_A

    assert libtcodpy.path_size(astar) != 0
    assert libtcodpy.path_size(astar) > 0
    assert not libtcodpy.path_is_empty(astar)

    for i in range(libtcodpy.path_size(astar)):
        x, y = libtcodpy.path_get(astar, i)

    while (x, y) != (None, None):
        x, y = libtcodpy.path_walk(astar, False)

    libtcodpy.path_delete(astar)
Example #6
0
 def reachedEndOfPath(self):
     pathx, pathy = libtcod.path_get(self.path, libtcod.path_size(self.path) - 1)
     return [self.owner.x, self.owner.y] == [pathx, pathy]