How to use the tcod.map_is_in_fov function in tcod

To help you get started, we’ve selected a few tcod examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BraininaBowl / RoguelikePy2019 / item_functions.py View on Github external
def cast_confuse(*args, **kwargs):
    entities = kwargs.get('entities')
    fov_map = kwargs.get('fov_map')
    target_x = kwargs.get('target_x')
    target_y = kwargs.get('target_y')

    results = []

    if not libtcod.map_is_in_fov(fov_map, target_x, target_y):
        results.append({'consumed': False, 'message': Message('You cannot target a tile outside your field of view.')})
        return results

    for entity in entities:
        if entity.x == target_x and entity.y == target_y and entity.ai:
            confused_ai = ConfusedMonster(entity.ai, 10)

            confused_ai.owner = entity
            entity.ai = confused_ai

            results.append({'consumed': True, 'message': Message('The eyes of the {0} look vacant, as he starts to stumble around!'.format(entity.name))})

            break
    else:
        results.append({'consumed': False, 'message': Message('There is no targetable enemy at that location.')})
github ChadAMiller / roguelike-2019 / render_functions.py View on Github external
def get_names_under_mouse(mouse, entities, fov_map):
    (x, y) = (mouse.cx, mouse.cy)

    names = [entity.name for entity in entities if entity.x == x and entity.y == y and libtcod.map_is_in_fov(fov_map, entity.x, entity.y) and entity.render_order != RenderOrder.INVISIBLE]
    names = ', '.join(names)

    return names.capitalize()
github clamytoe / roguelike / roguelike / render_functions.py View on Github external
:param message_log: MessageLog object with Messages
    :param screen_width: Width of the screen
    :param screen_height: Height of the screen
    :param bar_width: Width of the health bar
    :param panel_height: Height of the panel
    :param panel_y: Placement of the panel with respect to the main console window
    :param mouse: Mouse pointer object
    :param colors: GameMap color values
    :param game_state: GameState
    :return: None
    """
    # Draw all the tiles in the game map
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = tcod.map_is_in_fov(fov_map, x, y)
                wall = game_map.tiles[x][y].block_sight

                if visible:
                    if wall:
                        tcod.console_set_char_background(
                            con, x, y, colors.get("light_wall"), tcod.BKGND_SET
                        )
                    else:
                        tcod.console_set_char_background(
                            con, x, y, colors.get("light_ground"), tcod.BKGND_SET
                        )

                    game_map.tiles[x][y].explored = True
                elif game_map.tiles[x][y].explored:
                    if wall:
                        tcod.console_set_char_background(
github Wolfenswan / RoguelikeTut-TCOD / components / AI / basicAI.py View on Github external
def take_turn(self, game, fov_map):

        results = []
        target = game.player
        game_map = game.map
        entities = game.entities
        monster = self.owner

        # First check if anything has been planned for this turn #
        turn_plan = monster.turnplan.planned_turns.get(game.turn)
        if turn_plan:
            turn_plan_resuls = monster.turnplan.execute_plan(game.turn)
            results.extend(turn_plan_resuls)

        # Otherwise check if the monster can see the player #
        elif tcod.map_is_in_fov(fov_map, monster.x, monster.y):
            monster.color_bg = None  # some special attacks modify a character's background color, this resets it

            #results.extend(self.movement.move_decision(game))
            # Consider using a skill #
            if monster.skills:
                monster.cooldown_skills()
                available_skills = monster.available_skills(game)
                if available_skills:
                    skill = choice(available_skills)
                    skill_results = skill.execute(game)
                    results.extend(skill_results)
                    return results

            if monster.distance_to_ent(target) >= 2:
                monster.move_astar(target, entities, game_map)
github clamytoe / roguelike / roguelike / item_functions.py View on Github external
def cast_confuse(*args, **kwargs):
    entities = kwargs.get("entities")
    fov_map = kwargs.get("fov_map")
    target_x = kwargs.get("target_x")
    target_y = kwargs.get("target_y")

    results = []

    if not tcod.map_is_in_fov(fov_map, target_x, target_y):
        results.append(
            {
                "consumed": False,
                "message": Message(
                    "You cannot target a tile outside of your field of view.",
                    tcod.yellow,
                ),
            }
        )
        return results

    for entity in entities:
        if entity.x == target_x and entity.y == target_y and entity.ai:
            confused_ai = ConfusedMonster(entity.ai, 10)

            confused_ai.owner = entity
github Wolfenswan / RoguelikeTut-TCOD / rendering / render_main.py View on Github external
def draw_tile(game, con, fov_map, tile_x, tile_y, screen_x, screen_y, debug=False):
    tile = game.map.tiles[(tile_x, tile_y)]
    visible = tcod.map_is_in_fov(fov_map, tile_x, tile_y) or debug

    wall = tile.block_sight and not tile.walkable

    if visible:
        char = chr(178) if wall else '.'

        fg_color = darken_color_by_fov_distance(game.player, colors.light_fov, tile_x, tile_y, randomness=0)
        if tile.gibbed:
            fg_color =  darken_color_by_fov_distance(game.player, colors.corpse, tile_x, tile_y, randomness = 0)
        if debug:
            fg_color = colors.light_fov

        #tcod.console_put_char(con, screen_x, screen_y, char, tcod.BKGND_NONE)
        tcod.console_put_char_ex(con, screen_x, screen_y, char, fg_color, colors.black)
        tile.explored = 50
github Wolfenswan / RoguelikeTut-TCOD / rendering / render_main.py View on Github external
def draw_entity(game, con, entity, fov_map, debug=False):
    if entity.render_order == RenderOrder.ALWAYS or tcod.map_is_in_fov(fov_map, *entity.pos) or debug:
        x, y = pos_on_screen(*entity.pos, game.player)

        tcod.console_put_char(con, x, y, entity.char)
        # print(entity.char, entity.blocks)
        # Set the entity colors #
        color = entity.color
        if entity is not game.cursor:
            color = darken_color_by_fov_distance(game.player, entity.color, entity.x, entity.y)

        if debug:
            color = entity.color

        tcod.console_set_char_foreground(con, x, y, color)
        if entity.color_bg is not None:
            tcod.console_set_char_background(con, x, y, entity.color_bg)
github eyeCube / Softly-Roguelike / tilemap.py View on Github external
def _draw_what_player_sees(self, pc, sight):
        world=rog.world()
        seer=world.component_for_entity(pc, cmp.SenseSight)
        pos=world.component_for_entity(pc, cmp.Position)
        rend=world.component_for_entity(pc, cmp.Draw)

        sight = 100#TEMPORARY!!!!!

        for     x in range( max(0, pos.x-sight), min(self.w, pos.x+sight+1) ):
            for y in range( max(0, pos.y-sight), min(self.h, pos.y+sight+1) ):
##                print("tile at {} {} has light level {}".format(x ,y, self.get_light_value(x,y)))
                
                if not rog.in_range(pos.x,pos.y, x,y, sight):
                    continue
                if not libtcod.map_is_in_fov(seer.fov_map, x,y):
                    continue

                ent=self.thingat(x, y)

                if (not (x==pos.x and y==pos.y)
                        and self.get_light_value(x,y) == 0
                        and not rog.on(pc,NVISION) ):
                    self._draw_silhouettes(pc, x,y, ent, sight)
                    continue
                
                if ent:
                    libtcod.console_put_char(
                        self.con_map_state, x,y,
                        rend.char)
                    libtcod.console_set_char_foreground(
                        self.con_map_state, x,y, rend.fgcol)
github clamytoe / roguelike / roguelike / render_functions.py View on Github external
def get_names_under_mouse(mouse, entities, fov_map):
    x, y = (mouse.cx, mouse.cy)

    names = [
        entity.name
        for entity in entities
        if entity.x == x
        and entity.y == y
        and tcod.map_is_in_fov(fov_map, entity.x, entity.y)
    ]
    names = ", ".join(names)

    return names.capitalize()
github ChadAMiller / roguelike-2019 / item_functions.py View on Github external
def cast_fireball(*args, **kwargs):
    entities = kwargs.get('entities')
    fov_map = kwargs.get('fov_map')
    damage = kwargs.get('damage')
    radius = kwargs.get('targeting_radius')
    target_x = kwargs.get('target_x')
    target_y = kwargs.get('target_y')

    results = []

    if not libtcod.map_is_in_fov(fov_map, target_x, target_y):
        results.append({'consumed': False, 'message': Message('You cannot target a tile outside your field of view.', libtcod.yellow)})
        return results

    results.append({'consumed': True, 'message': Message('The fireball explodes, burning everything within {0} tiles!'.format(radius), libtcod.orange)})

    for entity in entities:
        if entity.distance(target_x, target_y) <= radius and entity.try_component('fighter'):
            results.append({'message': Message('The {0} gets burned for {1} hit points.'.format(entity.name, damage), libtcod.orange)})
            results.extend(entity.fighter.take_damage(damage))

    return results