How to use the tcod.console_put_char 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 / render_functions.py View on Github external
backcolor = colors.get('light')
                    game_map.tiles[x][y].explored = True
                else:
                    backcolor = colors.get('dark')

                libtcod.console_set_char_background(con, x * 3, y * 2, backcolor, libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 1, y * 2, backcolor, libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 2, y * 2, backcolor, libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3, y * 2 + 1, backcolor, libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 1, y * 2 + 1, backcolor, libtcod.BKGND_SET)
                libtcod.console_set_char_background(con, x * 3 + 2, y * 2 + 1, backcolor, libtcod.BKGND_SET)

                if (game_map.tiles[x][y].explored or visible) and wall:
                    libtcod.console_put_char(con, x*3, y*2, tiles.get('wall_tile'), libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x*3+1, y*2, tiles.get('wall_tile')+1, libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x*3+2, y*2, tiles.get('wall_tile')+2, libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x*3, y*2+1, tiles.get('wall_tile')+32, libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x*3+1, y*2+1, tiles.get('wall_tile')+33, libtcod.BKGND_NONE)
                    libtcod.console_put_char(con, x*3+2, y*2+1, tiles.get('wall_tile')+34, libtcod.BKGND_NONE)

    # Draw all entities in the list

    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'))
github BraininaBowl / RoguelikePy2019 / render_functions.py View on Github external
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
#    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:
github eyeCube / Softly-Roguelike / src / tilemap.py View on Github external
if not (ent and world.has_component(ent, cmp.Creature)):
            return
        pos=world.component_for_entity(ent, cmp.Position)  
        dist=maths.dist(pos.x,pos.y, tx,ty)
        dx=(tx - pos.x)/dist
        dy=(ty - pos.y)/dist
        xdest=tx + int(dx*sight)
        ydest=ty + int(dy*sight)
        libtcod.line_init(tx,ty, xdest,ydest)
        while True:
            x,y=libtcod.line_step()
            if x is None: return
            if maths.dist(pos.x,pos.y, x,y) > sight: return
            if self.get_blocks_sight(x,y):  return
            if self.get_perceived_light_value(x,y):
                libtcod.console_put_char(self.con_map_state, tx,ty, "?")
                return
github ChadAMiller / roguelike-2019 / render_functions.py View on Github external
def clear_entity(con, entity):
    # erase the character that represents this object
    libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)
github eyeCube / Softly-Roguelike / src / tilemap.py View on Github external
visibility=rog.visibility(
                                pc,sight,plight,camo,dist)
##                            print('visibility: ',visibility)
##                            print('stats: s{}, l{}, c{}, d{}'.format(sight, plight, camo, dist))
                        
                        if visibility<=0: continue
                        # render data based on visibility
                        rend=world.component_for_entity(ent, cmp.Draw)
                        char = rend.char if visibility > 1 else '?'
                        
                        if not entDrawn: # draw top entity
                            entDrawn = True
                            # get render data
                            fgcol=rend.fgcol
                            # render
                            libtcod.console_put_char(
                                self.con_map_state, x,y, char )
                            libtcod.console_set_char_foreground(
                                self.con_map_state, x,y, fgcol)
                            self._apply_rendered_bgcol(x,y, ent)
                            if world.has_component(ent, cmp.Creature):
                                continue # don't discover creatures
                        
                        if charDiscover is None:
                            charDiscover = char # we'll discover this entity
                            break # only discover one entity
                    # end for

                    self._discover_place(x,y, charDiscover)
                else:
                    libtcod.console_put_char_ex(self.con_map_state, x,y,
                        self.get_char(x, y),
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
torchs = 'on '
    if fov_light_walls :
        lights='on '
    if first:
        libtcod.sys_set_fps(30)
        # we draw the foreground only the first time.
        #  during the player movement, only the @ is redrawn.
        #  the rest impacts only the background color
        # draw the help text & player @
        libtcod.console_clear(sample_console)
        libtcod.console_set_default_foreground(sample_console, libtcod.white)
        libtcod.console_print(sample_console, 1, 1,
                               "IJKL : move around\nT : torch fx %s\nW : light walls %s\n+-: algo %s" %
                               (torchs,lights,fov_algo_names[fov_algo_num]))
        libtcod.console_set_default_foreground(sample_console, libtcod.black)
        libtcod.console_put_char(sample_console, fov_px, fov_py, '@',
                                 libtcod.BKGND_NONE)
        # draw windows
        for y in range(SAMPLE_SCREEN_HEIGHT):
            for x in range(SAMPLE_SCREEN_WIDTH):
                if smap[y][x] == '=':
                    libtcod.console_put_char(sample_console, x, y,
                                             libtcod.CHAR_DHLINE,
                                             libtcod.BKGND_NONE)
    if fov_recompute:
        fov_recompute = False
        if fov_torch:
            libtcod.map_compute_fov(fov_map, fov_px, fov_py, TORCH_RADIUS, fov_light_walls, fov_algo_num)
        else:
            libtcod.map_compute_fov(fov_map, fov_px, fov_py, 0, fov_light_walls, fov_algo_num)
    if fov_torch:
        # slightly change the perlin noise parameter
github libtcod / python-tcod / examples / samples_libtcodpy.py View on Github external
elif smap[y][x] == '=':
                    # window
                    libtcod.map_set_properties(path_map, x, y, True, False)
        path = libtcod.path_new_using_map(path_map)
        path_dijk = libtcod.dijkstra_new(path_map)
    if first:
        libtcod.sys_set_fps(30)
        # we draw the foreground only the first time.
        #  during the player movement, only the @ is redrawn.
        #  the rest impacts only the background color
        # draw the help text & player @
        libtcod.console_clear(sample_console)
        libtcod.console_set_default_foreground(sample_console, libtcod.white)
        libtcod.console_put_char(sample_console, path_dx, path_dy, '+',
                                 libtcod.BKGND_NONE)
        libtcod.console_put_char(sample_console, path_px, path_py, '@',
                                 libtcod.BKGND_NONE)
        libtcod.console_print(sample_console, 1, 1,
                                   "IJKL / mouse :\nmove destination\nTAB : A*/dijkstra")
        libtcod.console_print(sample_console, 1, 4,
                                    "Using : A*")
        # draw windows
        for y in range(SAMPLE_SCREEN_HEIGHT):
            for x in range(SAMPLE_SCREEN_WIDTH):
                if smap[y][x] == '=':
                    libtcod.console_put_char(sample_console, x, y,
                                             libtcod.CHAR_DHLINE,
                                             libtcod.BKGND_NONE)
        path_recalculate = True
    if path_recalculate:
        if path_using_astar :
            libtcod.path_compute(path, path_px, path_py, path_dx, path_dy)
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 Wolfenswan / RoguelikeTut-TCOD / rendering / render_main.py View on Github external
def clear_entity(con, entity):
    # erase the character that represents this object
    tcod.console_put_char(con, entity.x, entity.y, ' ', tcod.BKGND_NONE)