Example #1
0
def render_map(root_console: tcod.console.Console,
               map_console: tcod.console.Console, game_map: GameMap,
               entities: list, start_x: int, start_y: int, colours: dict,
               fov_recompute: bool):
    # render map tiles only when a change has occurred
    if fov_recompute:
        for y in range(game_map.height):
            for x in range(game_map.width):
                visible = game_map.fov(x, y)
                wall = not game_map.walkable(x, y)

                # if tile can be seen now, light it up
                if visible:
                    if wall:
                        tcod.console_set_char_background(
                            map_console, x, y, colours.get('light_wall'),
                            tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            map_console, x, y, colours.get('light_ground'),
                            tcod.BKGND_SET)
                # if we've previously seen this tile
                elif game_map.explored(x, y):
                    if wall:
                        tcod.console_set_char_background(
                            map_console, x, y, colours.get('dark_wall'),
                            tcod.BKGND_SET)
                    else:
                        tcod.console_set_char_background(
                            map_console, x, y, colours.get('dark_ground'),
                            tcod.BKGND_SET)

    # render entities onto map
    entities_in_render_order = sorted(entities,
                                      key=lambda e: e.render_order.value)
    for entity in entities_in_render_order:
        draw_entity(map_console, entity, game_map)

    # copy to the actual screen
    map_console.blit(root_console, start_x, start_y, 0, 0, game_map.width,
                     game_map.height)
    return
Example #2
0
def draw_entity(con: tcod.console.Console, entity: Entity, game_map: GameMap):
    if game_map.fov(entity.x, entity.y):
        con.default_fg = entity.colour
        tcod.console_put_char(con, entity.x, entity.y, entity.char,
                              tcod.BKGND_NONE)
    return