How to use the tcod.console_set_default_foreground 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 libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
for x in range(SAMPLE_SCREEN_WIDTH):
            xcoef = float(x) / (SAMPLE_SCREEN_WIDTH - 1)
            top = libtcod.color_lerp(tc_cols[TOPLEFT], tc_cols[TOPRIGHT], xcoef)
            bottom = libtcod.color_lerp(tc_cols[BOTTOMLEFT], tc_cols[BOTTOMRIGHT],
                                        xcoef)
            for y in range(SAMPLE_SCREEN_HEIGHT):
                ycoef = float(y) / (SAMPLE_SCREEN_HEIGHT - 1)
                curColor = libtcod.color_lerp(top, bottom, ycoef)
                libtcod.console_set_char_background(sample_console, x, y, curColor,
                                         libtcod.BKGND_SET)
        textColor = libtcod.console_get_char_background(sample_console,
                                             SAMPLE_SCREEN_WIDTH // 2, 5)
        textColor.r = 255 - textColor.r
        textColor.g = 255 - textColor.g
        textColor.b = 255 - textColor.b
        libtcod.console_set_default_foreground(sample_console, textColor)
        for x in range(SAMPLE_SCREEN_WIDTH):
            for y in range(SAMPLE_SCREEN_HEIGHT):
                col = libtcod.console_get_char_background(sample_console, x, y)
                col = libtcod.color_lerp(col, libtcod.black, 0.5)
                c = libtcod.random_get_int(None, ord('a'), ord('z'))
                libtcod.console_set_default_foreground(sample_console, col)
                libtcod.console_put_char(sample_console, x, y, c,
                                         libtcod.BKGND_NONE)
    else:
        # same, but using the ConsoleBuffer class to speed up rendering
        buffer = libtcod.ConsoleBuffer(SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT)  # initialize buffer
        c = libtcod.random_get_int(None, ord('a'), ord('z'))
        for x in range(SAMPLE_SCREEN_WIDTH):
            xcoef = float(x) / (SAMPLE_SCREEN_WIDTH - 1)
            top = libtcod.color_lerp(tc_cols[TOPLEFT], tc_cols[TOPRIGHT], xcoef)
            bottom = libtcod.color_lerp(tc_cols[BOTTOMLEFT], tc_cols[BOTTOMRIGHT], xcoef)
github BraininaBowl / RoguelikePy2019 / render_functions.py View on Github external
libtcod.console_blit(messages_pane, 0, y-log_height-log_scroll, panel_width-3, log_height, panel, 2, 4)

#    libtcod.console_set_default_background(panel, colors.get('dark'))
#    libtcod.console_set_default_foreground(panel, colors.get('light'))
#    libtcod.console_put_char(panel, panel_width-1, 5, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width-2, 4, tiles.get('up_tile'), libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-3, 5, " ", libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-1, 5+log_height, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width-2, 4+log_height, tiles.get('down_tile'), libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-3, 5+log_height, " ", libtcod.BKGND_SET)

    # Print the inventory items
#    libtcod.console_set_default_background(panel, colors.get('light'))
#    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    libtcod.console_print_ex(panel, int(panel_width / 2), 5+log_height, libtcod.BKGND_SET, libtcod.CENTER, "-------- Backpack --------")
    libtcod.console_set_default_foreground(panel, colors.get('green'))
    libtcod.console_print_ex(panel, int(panel_width / 2), 6+log_height, libtcod.BKGND_SET, libtcod.CENTER, "<> select | [u]se | [d]rop")

    libtcod.console_set_default_background(inventory_pane, colors.get('light'))
    libtcod.console_clear(inventory_pane)
    y = 1
    for item in player.inventory.items:
        if y == inv_selected + 1:
            libtcod.console_set_default_background(inventory_pane, colors.get('dark'))
            libtcod.console_set_default_foreground(inventory_pane, colors.get('light'))
        else:
            libtcod.console_set_default_background(inventory_pane, colors.get('light'))
            libtcod.console_set_default_foreground(inventory_pane, colors.get('dark'))
        if player.equipment.main_hand == item:
            libtcod.console_print_ex(inventory_pane, 0, y, libtcod.BKGND_SET, libtcod.LEFT,'{0} ({1}) (main)'.format(item.name, item.number))
        elif player.equipment.off_hand == item:
            libtcod.console_print_ex(inventory_pane, 0, y, libtcod.BKGND_SET, libtcod.LEFT,'{0} ({1}) (off)'.format(item.name, item.number))
github JnyJny / hackstar / hackstar / entity.py View on Github external
def draw(self, console: int = 0, blank: bool = True) -> None:
        """Draw this entity at it's (x,y) coordinates on the specified console.
        :param int console:
        :param bool blank:
        """
        tcod.console_set_default_foreground(console, self.fg)
        tcod.console_put_char(console, self.x, self.y, str(self), tcod.BKGND_NONE)
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
mouse=libtcod.Mouse()
while not libtcod.console_is_window_closed():
    libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS|libtcod.EVENT_MOUSE,key,mouse)
    # render the sample
    samples[cur_sample].func(first, key, mouse)
    first = False
    libtcod.console_blit(sample_console,
                         0, 0, SAMPLE_SCREEN_WIDTH, SAMPLE_SCREEN_HEIGHT,
                         0, SAMPLE_SCREEN_X, SAMPLE_SCREEN_Y)
    # render credits
    if not credits_end:
        credits_end = libtcod.console_credits_render(60, 43, 0)
    # render sample list
    for i in range(len(samples)):
        if i == cur_sample:
            libtcod.console_set_default_foreground(None, libtcod.white)
            libtcod.console_set_default_background(None, libtcod.light_blue)
        else:
            libtcod.console_set_default_foreground(None, libtcod.grey)
            libtcod.console_set_default_background(None, libtcod.black)
        libtcod.console_print_ex(None, 2, 46 - (len(samples) - i),
                                   libtcod.BKGND_SET, libtcod.LEFT, samples[i].name)
    # render stats
    libtcod.console_set_default_foreground(None, libtcod.grey)
    libtcod.console_print_ex(None, 79, 46, libtcod.BKGND_NONE, libtcod.RIGHT,
                                'last frame : %3d ms (%3d fps)' %
                                (int(libtcod.sys_get_last_frame_length() *
                                     1000.0), libtcod.sys_get_fps()))
    libtcod.console_print_ex(None, 79, 47, libtcod.BKGND_NONE, libtcod.RIGHT,
                                'elapsed : %8d ms %4.2fs' %
                                (libtcod.sys_elapsed_milli(),
                                 libtcod.sys_elapsed_seconds()))
github JnyJny / hackstar / hackstar / engine.py View on Github external
def draw(self) -> None:
        """Draw game state to screen.
        """

        tcod.console_set_default_foreground(self.console, tcod.white)

        self.map.draw(self.console, self.colors)

        tcod.console_blit(self.console, 0, 0, self.w, self.h, 0, 0, 0)
github BraininaBowl / RoguelikePy2019 / render_functions.py View on Github external
libtcod.console_set_default_background(panel, colors.get('light'))
    libtcod.console_set_default_foreground(panel, colors.get('dark'))
    libtcod.console_clear(panel)

    # Print the game messages, one line at a time
    libtcod.console_print_ex(panel, int(panel_width / 2), 3, libtcod.BKGND_SET, libtcod.CENTER, "-------- Messages --------")


    libtcod.console_set_default_background(messages_pane, colors.get('light'))
    libtcod.console_clear(messages_pane)
    y = 1
    for message in message_log.messages:
        libtcod.console_set_default_foreground(messages_pane, message.color)
        libtcod.console_print_ex(messages_pane, message_log.x, y, libtcod.BKGND_NONE, libtcod.LEFT, message.text)
        y += 1
#    if log_scroll > y - log_height:
#        log_scroll = y - log_height
    libtcod.console_blit(messages_pane, 0, y-log_height-log_scroll, panel_width-3, log_height, panel, 2, 4)

#    libtcod.console_set_default_background(panel, colors.get('dark'))
#    libtcod.console_set_default_foreground(panel, colors.get('light'))
#    libtcod.console_put_char(panel, panel_width-1, 5, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width-2, 4, tiles.get('up_tile'), libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-3, 5, " ", libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-1, 5+log_height, " ", libtcod.BKGND_SET)
    libtcod.console_put_char(panel, panel_width-2, 4+log_height, tiles.get('down_tile'), libtcod.BKGND_SET)
#    libtcod.console_put_char(panel, panel_width-3, 5+log_height, " ", libtcod.BKGND_SET)

    # Print the inventory items
github clamytoe / roguelike / roguelike / menus.py View on Github external
def menu(con, header, options, width, screen_width, screen_height):
    if len(options) > 26:
        raise ValueError("Cannot have a menu with more than 26 options.")

    # calculate total height for the header (after auto-wrap) and one line per option
    header_height = tcod.console_get_height_rect(
        con, 0, 0, width, screen_height, header
    )
    height = len(options) + header_height

    # create an off-screen console that represents the menu's window
    window = tcod.console_new(width, height)

    # print the header, with auto-wrap
    tcod.console_set_default_foreground(window, tcod.white)
    tcod.console_print_rect_ex(
        window, 0, 0, width, height, tcod.BKGND_NONE, tcod.LEFT, header
    )

    # print all the options
    y = header_height
    letter_index = ord("a")
    for option_text in options:
        if option_text == "Inventory is empty.":
            text = f"( ) {option_text}"
        else:
            text = f"({chr(letter_index)}) {option_text}"
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1
github libtcod / python-tcod / examples / tutorial / part 1 - moving around.py View on Github external
#############################################
# Initialization & Main Loop
#############################################
 
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'python/libtcod tutorial', False)
libtcod.sys_set_fps(LIMIT_FPS)
 
playerx = SCREEN_WIDTH//2
playery = SCREEN_HEIGHT//2
 
while not libtcod.console_is_window_closed():
 
    libtcod.console_set_default_foreground(0, libtcod.white)
    libtcod.console_put_char(0, playerx, playery, '@', libtcod.BKGND_NONE)
 
    libtcod.console_flush()
 
    libtcod.console_put_char(0, playerx, playery, ' ', libtcod.BKGND_NONE)
 
    #handle keys and exit game if needed
    exit = handle_keys()
    if exit:
        break
github adonutwithsprinklez / RoguelikeMe / src / DisplayClass.py View on Github external
def drawChar(self, drawInfo):
        if drawInfo[1]:
            libtcod.console_set_default_foreground(drawInfo[0], drawInfo[1])
        libtcod.console_put_char(drawInfo[0], drawInfo[2], drawInfo[3],
                                 drawInfo[4], libtcod.BKGND_NONE)
        libtcod.console_set_default_foreground(drawInfo[0], libtcod.white)
github adonutwithsprinklez / RoguelikeMe / src / DisplayClass.py View on Github external
def drawChar(self, drawInfo):
        if drawInfo[1]:
            libtcod.console_set_default_foreground(drawInfo[0], drawInfo[1])
        libtcod.console_put_char(drawInfo[0], drawInfo[2], drawInfo[3],
                                 drawInfo[4], libtcod.BKGND_NONE)
        libtcod.console_set_default_foreground(drawInfo[0], libtcod.white)