def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar bar_width = int(float(value) / maximum * total_width) #background first libtcod.console_set_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #put bar at top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #some text and values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
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_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #now render the bar on top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #finally, some centered text with the values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))