def render(self, pokeball: Pokeball, percent_complete: float, message: str) -> libtcod.console:
        """
            Render the area and return the full console
        """
        rows_complete = int(len(CatchGraphicRenderer.graphic) * (percent_complete / 100))

        libtcod.console_clear(self.console)
        libtcod.console_set_default_background(self.console, settings.CATCH_GRAPHIC_BG_COLOR)
        libtcod.console_set_default_foreground(self.console, settings.LINE_COLOR)
        libtcod.console_print_frame(self.console, 0, 0, CatchGraphicRenderer.width, CatchGraphicRenderer.height)

        for y, row in enumerate(CatchGraphicRenderer.graphic):
            for x, cell in enumerate(row):
                if cell[0] != '':
                    if len(CatchGraphicRenderer.graphic) - y <= rows_complete:
                        if cell[1] == "upper":
                            color = pokeball.top_color
                        elif cell[1] == "lower":
                            color = pokeball.bottom_color
                        else:
                            color = cell[1]
                    else:
                        color = libtcod.gray

                    libtcod.console_set_default_foreground(self.console, color)
                    libtcod.console_put_char(self.console, x + self.x_offset, y + self.y_offset, cell[0])

        if message:
            libtcod.console_print_rect_ex(self.console,
                                          CatchGraphicRenderer.width // 2, CatchGraphicRenderer.height - 3, 
                                          CatchGraphicRenderer.width - 2, 2, 
                                          libtcod.BKGND_NONE, libtcod.CENTER, message)

        return self.console
    def render(self, creature: Creature, prev_level: int) -> libtcod.console:
        """
            Returns a full console that can be blitted onto something else
            anywhere the calling code chooses.
        """
        libtcod.console_clear(self.console)
        libtcod.console_set_default_background(self.console, settings.LEVEL_UP_BG_COLOR)
        self._render_lines()
        self._render_summary(creature, prev_level)
        self._render_stats(creature, prev_level)

        return self.console
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) // maximum * total_width)
 
    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)
 
    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
 
    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width // 2, y, libtcod.BKGND_NONE, libtcod.CENTER,
        name + ': ' + str(value) + '/' + str(maximum))
Example #4
0
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color):
    #render a bar (HP, experience, etc). first calculate the width of the bar
    bar_width = int(float(value) / maximum * total_width)
 
    #render the background first
    libtcod.console_set_default_background(panel, back_color)
    libtcod.console_rect(panel, x, y, total_width, 1, False, libtcod.BKGND_SCREEN)
 
    #now render the bar on top
    libtcod.console_set_default_background(panel, bar_color)
    if bar_width > 0:
        libtcod.console_rect(panel, x, y, bar_width, 1, False, libtcod.BKGND_SCREEN)
 
    #finally, some centered text with the values
    libtcod.console_set_default_foreground(panel, libtcod.white)
    libtcod.console_print_ex(panel, x + total_width // 2, y, libtcod.BKGND_NONE, libtcod.CENTER,
        name + ': ' + str(value) + '/' + str(maximum))
Example #5
0
def render_tooltip(x, y, text):

    if len(text) + 2 > 58:
        print(text)
        raise Exception(
            "Tooltip text is too long. Must be 58 characters or less, string was "
            + (str(len(text))) + " characters.")

    ttcon = libtcod.console.Console(len(text) + 4, 3)
    libtcod.console_set_default_background(ttcon, libtcod.Color(102, 102, 102))
    libtcod.console_set_default_foreground(ttcon, libtcod.black)

    libtcod.console_clear(ttcon)

    libtcod.console_print_ex(ttcon, 0, 0, libtcod.BKGND_NONE, libtcod.LEFT,
                             chr(201))
    libtcod.console_print_ex(ttcon,
                             len(text) + 3, 0, libtcod.BKGND_SET, libtcod.LEFT,
                             chr(187))
    libtcod.console_print_ex(ttcon, 0, 2, libtcod.BKGND_SET, libtcod.LEFT,
                             chr(200))
    libtcod.console_print_ex(ttcon,
                             len(text) + 3, 2, libtcod.BKGND_SET, libtcod.LEFT,
                             chr(188))
    libtcod.console_print_ex(ttcon, 0, 1, libtcod.BKGND_SET, libtcod.LEFT,
                             chr(186))
    libtcod.console_print_ex(ttcon,
                             len(text) + 3, 1, libtcod.BKGND_SET, libtcod.LEFT,
                             chr(186))
    for tx in range(1, len(text) + 3):
        libtcod.console_print_ex(ttcon, tx, 0, libtcod.BKGND_SET, libtcod.LEFT,
                                 chr(205))
        libtcod.console_print_ex(ttcon, tx, 2, libtcod.BKGND_SET, libtcod.LEFT,
                                 chr(205))

    libtcod.console_set_default_foreground(ttcon, libtcod.white)
    libtcod.console_print_ex(ttcon, 2, 1, libtcod.BKGND_NONE, libtcod.LEFT,
                             str(text).capitalize())

    while ((y - 3) < 1):
        y = +1
    while ((x + len(text) + 4) > 59):
        x -= 1
    libtcod.console_blit(ttcon, 0, 0, 0, 0, 0, x, y)
def test_console_defaults(console, fg, bg):
    libtcodpy.console_set_default_foreground(console, fg)
    libtcodpy.console_set_default_background(console, bg)
    libtcodpy.console_clear(console)
    assert_char(console, 0, 0, None, fg, bg)
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)
 
    #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)
Example #8
0
 def default_background_color(self, color):
     tcod.console_set_default_background(self._c, color)