示例#1
0
    def draw_tile(self, tile, x, y, in_fov):
        bk_color = tile.bk_color
        fg_color = tile.fg_color

        if in_fov:
            bk_color = bk_color * 2
            fg_color = fg_color * 2

        libtcod.console_set_char_background(
            self.con, x, y, bk_color, libtcod.BKGND_SET)
        libtcod.console_set_default_foreground(self.con, fg_color)
        libtcod.console_put_char(
            self.con, x, y, tile.char, libtcod.BKGND_NONE)
示例#2
0
    def draw_tile(self, x, y, tile, in_fov):
        con = self.map_console
        tile_disp = TILE_DISPS[tile.tile_type]

        if in_fov:
            tile.explored = True

        color_mult = 1.0 if in_fov else 0.5
        bg = tile_disp.bg * color_mult if tile_disp.bg else None
        fg = tile_disp.fg * color_mult if tile_disp.fg else None

        if tile.explored:
            if tile_disp.char == ' ':
                libtcod.console_set_char_background(con, x, y, bg,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_char(con, x, y, ' ')
            else:
                libtcod.console_set_char_background(con, x, y, bg,
                                                    libtcod.BKGND_SET)
                libtcod.console_set_default_foreground(con, fg)
                libtcod.console_put_char(con, x, y, tile_disp.char,
                                         libtcod.BKGND_NONE)
        else:
            libtcod.console_set_char_background(con, x, y, libtcod.black,
                                                libtcod.BKGND_SET)
            libtcod.console_set_char(con, x, y, ' ')
def render_all():
    global fov_map, color_dark_wall, color_light_wall
    global color_dark_ground, color_light_ground
    global fov_recompute

    if fov_recompute:
        # recompute FOV if needed (the player moved or something)
        fov_recompute = False
        libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS,
                                FOV_LIGHT_WALLS, FOV_ALGO)

        # go through all tiles, and set their background color
        # according to the FOV
        for y in range(MAP_HEIGHT):
            for x in range(MAP_WIDTH):
                visible = libtcod.map_is_in_fov(fov_map, x, y)
                wall = map[x][y].block_sight
                if not visible:
                    # if it's not visible right now, the player can
                    # only see it if it's explored
                    if map[x][y].explored:
                        if wall:
                            libtcod.console_set_char_background(con, x, y,
                                                                color_dark_wall,
                                                                libtcod.BKGND_SET)
                        else:
                            libtcod.console_set_char_background(con, x, y,
                                                                color_dark_ground,
                                                                libtcod.BKGND_SET)
                else:
                    # it's visible
                    if wall:
                        libtcod.console_set_char_background(con, x, y,
                                                            color_light_wall,
                                                            libtcod.BKGND_SET)
                    else:
                        libtcod.console_set_char_background(con, x, y,
                                                            color_light_ground,
                                                            libtcod.BKGND_SET)
                        # since it's visible, explore it
                    map[x][y].explored = True

    # draw all objects in the list, except the player. we want it to
    # always appear over all other objects! so it's drawn later.
    for object in objects:
        if object != player:
            object.draw()
    player.draw()

    # blit the contents of "con" to the root console
    libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0)

    # prepare to render the GUI panel
    libtcod.console_set_default_background(panel, libtcod.black)
    libtcod.console_clear(panel)

    # print the game messages, one line at a time
    y = 1
    for (line, color) in game_msgs:
        libtcod.console_set_default_foreground(panel, color)
        libtcod.console_print_ex(panel, MSG_X, y, libtcod.BKGND_NONE,
                                 libtcod.LEFT, line)
        y += 1

    # show the player's stats
    render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp,
               libtcod.light_red, libtcod.darker_red)
    libtcod.console_print_ex(panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT,
                             'Dungeon level ' + str(dungeon_level))

    # display names of objects under the mouse
    libtcod.console_set_default_foreground(panel, libtcod.light_gray)
    libtcod.console_print_ex(panel, 1, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             get_names_under_mouse())

    # blit the contents of "panel" to the root console
    libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0,
                         PANEL_Y)
示例#4
0
    libtcod.line(rect.x1, rect.y1, rect.x1, rect.y2, listener)
    libtcod.line(rect.x2, rect.y1, rect.x2, rect.y2, listener)
    libtcod.line(rect.x1, rect.y2, rect.x2, rect.y2, listener)

    if tree.left is not None:
        trace_sections(tree.left)
    if tree.right is not None:
        trace_sections(tree.right)

trace_sections(tree)

libtcod.console_set_custom_font(
    'terminal12x12_gs_ro.png',
    libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)

libtcod.console_init_root(
    SCREEN_WIDTH, SCREEN_HEIGHT, 'rogue-one', False, libtcod.RENDERER_GLSL)

for x in range(SCREEN_WIDTH):
    for y in range(SCREEN_HEIGHT):
        col = libtcod.Color(60 * map[x][y], 60 * map[x][y], 60 * map[x][y])
        libtcod.console_set_char_background(0, x, y, col)
        libtcod.console_set_default_foreground(0, libtcod.dark_grey)
        libtcod.console_put_char(0, x, y, ".")

libtcod.console_flush()

libtcod.console_wait_for_keypress(True)

exit()