Ejemplo n.º 1
0
 def render_ui(self, player):
     cc = self.create_color
     #prepare to render the GUI panel
     libtcod.console_set_default_background(self.panel, libtcod.black)
     libtcod.console_clear(self.panel)
     #show the player's HP
     self.render_bar(1, 1, 13, 10, player.hp, player.base_hp,
                     HP_BAR, libtcod.darker_red, cc(COLOR_STATUS_TEXT), HP_BAR_PERCENT)
     self.render_bar(1, 2, 13, 10, player.mp, player.base_mp,
                     MP_BAR, libtcod.darker_red, cc(COLOR_STATUS_TEXT), MP_BAR_PERCENT)
     self.render_stats_two_column(1, 3, "AC", player.base_ac, 13, "EVADE", "player.evade", COLOR_STATUS_TEXT,
                                  COLOR_STATUS_VALUES)
     self.render_stats_two_column(1, 4, "Str", "str", 13, "To", "tough", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES)
     self.render_stats_two_column(1, 5, "Dex", "des", 13, "Int", "int", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES)
     self.render_stats_two_column(1, 6, "XL", player.xl, 13, "EXP", "%d/%d" % (player.xp, util.xp_for_lvl(player.xl))
                                  , COLOR_STATUS_TEXT, COLOR_STATUS_VALUES)
     self.render_stats_two_column(1, 7, "Turns", gl.__turn_count__, 13, "", "", COLOR_STATUS_TEXT, COLOR_STATUS_VALUES)
     #blit the contents of "panel" to the root console
     libtcod.console_blit(self.panel, 0, 0, RIGHT_PANEL_WIDTH, RIGHT_PANEL_HEIGHT, 0, RIGHT_PANEL_X, 0)
Ejemplo n.º 2
0
    def render_bar(self, x, y, x2, total_width, value, maximum, bar_color, dim_color, text_color, color_lvls):
        TEXT_PAD = 8
        #this is totaly incorrect! should be total_width/maximum instead
        tick_price = 0.0
        tick_price = float(total_width) / float(maximum)

        libtcod.console_set_default_background(self.panel, dim_color)
        formated_str = "HP: %i/%i" % (value, maximum)
        #if displayed value == 0 - skip rendering bar
        if not maximum:
            return
        libtcod.console_set_default_foreground(self.panel, text_color)
        libtcod.console_print(self.panel, x, y, formated_str)
        libtcod.console_set_default_foreground(self.panel, self.create_color(bar_color[0]))
        libtcod.console_print(self.panel, x2, y, '[' + ''.ljust(total_width, '_') + ']')
        active_ticks = min(int(value * tick_price), total_width)
        severity = 0
        #now choose apropriate color depending on how much value left (compared to maximum)
        for color_lvl in color_lvls:
            if active_ticks <= maximum * color_lvl:
                severity += 1
        #now render the bar on top
        libtcod.console_set_default_foreground(self.panel, self.create_color(bar_color[severity]))
        libtcod.console_print(self.panel, x2 + 1 ,y, '#'.center(active_ticks, '#'))