How to use the tcod.console_print_ex 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 Wolfenswan / RoguelikeTut-TCOD / gui / menu.py View on Github external
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:
        text = '(' + chr(letter_index) + ') ' + option_text
        tcod.console_print_ex(window, 0, y, tcod.BKGND_NONE, tcod.LEFT, text)
        y += 1
        letter_index += 1

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    #draw_console_borders(window)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
github BraininaBowl / RoguelikePy2019 / menus.py View on Github external
# print the header, with auto-wrap
    libtcod.console_set_default_foreground(window, colors.get(foreground))
    libtcod.console_set_default_background(window, colors.get(background))
    libtcod.console_clear(window)
    libtcod.console_print_rect_ex(window, 1, 1, width, height, libtcod.BKGND_SET, libtcod.LEFT, header)

    # print all the options
    y = header_height
    letter_index = ord('a')
    for option_text in options:
        text = '(' + chr(letter_index) + ') ' + option_text
        libtcod.console_print_ex(window, 1, y, libtcod.BKGND_SET, libtcod.LEFT, text)
        y += 1
        letter_index += 1
    libtcod.console_print_ex(window, 1, y, libtcod.BKGND_SET, libtcod.LEFT, " ")

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    libtcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 1.0)
github BraininaBowl / RoguelikePy2019 / render_functions.py View on Github external
entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)

    for entity in entities_in_render_order:
        draw_entity(con, entity, fov_map, anim_frame, game_map, game_state)

    libtcod.console_blit(con, 0,0,map_width*3, map_height*2, 0, -cam_x, -cam_y)



    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)
github clamytoe / roguelike / roguelike / menus.py View on Github external
# 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

    # blit the contents of "window" to the root console
    x = int(screen_width / 2 - width / 2)
    y = int(screen_height / 2 - height / 2)
    tcod.console_blit(window, 0, 0, width, height, 0, x, y, 1.0, 0.7)
github BraininaBowl / RoguelikePy2019 / render_functions.py View on Github external
#        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
#    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:
github clamytoe / roguelike / roguelike / render_functions.py View on Github external
player.fighter.max_hp,
        tcod.light_red,
        tcod.darker_red,
    )

    tcod.console_print_ex(
        panel,
        1,
        3,
        tcod.BKGND_NONE,
        tcod.LEFT,
        f"Dungeon level: {game_map.dungeon_level}",
    )

    tcod.console_set_default_foreground(panel, tcod.light_gray)
    tcod.console_print_ex(
        panel,
        1,
        0,
        tcod.BKGND_NONE,
        tcod.LEFT,
        get_names_under_mouse(mouse, entities, fov_map),
    )

    tcod.console_blit(panel, 0, 0, screen_width, panel_height, 0, 0, panel_y)

    if game_state in (GameStates.SHOW_INVENTORY, GameStates.DROP_INVENTORY):
        if game_state == GameStates.SHOW_INVENTORY:
            inventory_title = (
                "Press the key next to an item to use it, or ESC to cancel.\n"
            )
        else:
github adonutwithsprinklez / RoguelikeMe / src / DisplayClass.py View on Github external
def drawText(self, drawInfo):
        if drawInfo[4] == "left":
            alignment = libtcod.LEFT
        elif drawInfo[4] == "right":
            alignment = libtcod.RIGHT
        elif drawInfo[4] == "center":
            alignment = libtcod.CENTER
        libtcod.console_print_ex(
            drawInfo[0], drawInfo[2], drawInfo[3], libtcod.BKGND_NONE, alignment, drawInfo[1])
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
'elapsed : %8d ms %4.2fs' %
                                (libtcod.sys_elapsed_milli(),
                                 libtcod.sys_elapsed_seconds()))

    cur_renderer=libtcod.sys_get_renderer()
    libtcod.console_set_default_foreground(None,libtcod.grey)
    libtcod.console_set_default_background(None,libtcod.black)
    libtcod.console_print_ex(None,42,46-(libtcod.NB_RENDERERS+1),libtcod.BKGND_SET, libtcod.LEFT, "Renderer :")
    for i in range(libtcod.NB_RENDERERS) :
        if i==cur_renderer :
            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,42,46-(libtcod.NB_RENDERERS-i),libtcod.BKGND_SET,libtcod.LEFT,renderer_name[i])

    # key handler
    if key.vk == libtcod.KEY_DOWN:
        cur_sample = (cur_sample+1) % len(samples)
        first = True
    elif key.vk == libtcod.KEY_UP:
        cur_sample = (cur_sample-1) % len(samples)
        first = True
    elif key.vk == libtcod.KEY_ENTER and key.lalt:
        libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
    elif key.vk == libtcod.KEY_PRINTSCREEN or key.c == 'p':
        print ("screenshot")
        if key.lalt :
            libtcod.console_save_apf(None,"samples.apf")
            print ("apf")
        else :
github eyeCube / Softly-Roguelike / src / orangio.py View on Github external
def update_render_text(self):
        tcod.console_clear(self.console)
        tcod.console_print_ex(
            self.console,0,0,
            tcod.BKGND_NONE,tcod.LEFT,
            self.text )
        self.blit_console()