コード例 #1
0
    def render_ui(self, player):
        #prepare to render the GUI panel
        libtcod.console_set_background_color(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, self.create_color(COLOR_STATUS_TEXT), HP_BAR_PERCENT)
        self.render_bar(1, 2, 13, 10, player.mp, player.base_mp,
                        MP_BAR, libtcod.darker_red, self.create_color(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)
        #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)

        #print the game messages, one line at a time
        y = 0
        for (line, level) in gl.__msgs__:
            if level < 1 and not gl.__wizard_mode__:
                continue
            libtcod.console_set_foreground_color(self.panel_msg, self.message_colours.get(level, libtcod.white))
            libtcod.console_print_left(self.panel_msg, 0, y, libtcod.BKGND_NONE, line.ljust(SCREEN_WIDTH, ' '))
            y += 1
        libtcod.console_blit(self.panel_msg, 0, 0, SCREEN_WIDTH, MSG_PANEL_HEIGHT, 0, 0, MSG_PANEL_Y )
        libtcod.console_flush()
コード例 #2
0
 def render_stats_two_column(self, x, y, text1, value, x2, text2, value2, lbl_color, value_color):
     libtcod.console_set_foreground_color(self.panel, self.create_color(lbl_color))
     libtcod.console_print_left(self.panel, x, y, libtcod.BKGND_NONE, text1 + ':')
     libtcod.console_print_left(self.panel, x2, y, libtcod.BKGND_NONE, text2 + ':')
     libtcod.console_set_foreground_color(self.panel, self.create_color(value_color))
     libtcod.console_print_left(self.panel, x + len(text1) + 1, y, libtcod.BKGND_NONE, str(value))
     libtcod.console_print_left(self.panel, x2 + len(text2) + 1, y, libtcod.BKGND_NONE, str(value2))
コード例 #3
0
    def render_all(self, map, player):
        if gl.__fov_recompute__:
            gl.__fov_recompute__ = False
            map.recompute_fov()

            for y in range(map.map_height):
                for x in range(map.map_width):
                    seen = map.map[y][x].seen | gl.__wizard_mode__
                    visible = libtcod.map_is_in_fov(map.fov_map, x, y)
                    #if tile is seen or visible to player - print it
                    if seen or visible:
                        libtcod.console_print_left(self.con, x, y, libtcod.BKGND_NONE, map[y][x].char)
                        #if it's not in LOS, but seen - print in dim color
                    if not visible:
                        if seen:
                            libtcod.console_set_fore(self.con, x, y, self.create_color(map[y][x].dim_color))
                            libtcod.console_set_back(self.con, x, y, self.create_color(map[y][x].dim_color_back),
                                                     libtcod.BKGND_SET)
                    else:
                        #if it's in LOS - print and mark as seen
                        libtcod.console_set_fore(self.con, x, y, self.create_color(map[y][x].color))
                        libtcod.console_set_back(self.con, x, y, self.create_color(map[y][x].color_back), libtcod.BKGND_SET)
                        #if current tile is visible for now - mark as seen
                        map[y][x].seen = True

        for critter in map.map_critters:
            if libtcod.map_is_in_fov(map.fov_map, critter.x, critter.y) or gl.__wizard_mode__:
                libtcod.console_set_foreground_color(self.con, self.create_color(critter.color))
                self.print_critter(critter.x, critter.y, critter.char)

        libtcod.console_set_foreground_color(self.con, self.create_color(player.color))
        self.print_critter(player.x, player.y, player.char)

        if gl.__wizard_mode__:
            libtcod.console_print_left(self.con, 0, 0, libtcod.BKGND_NONE, 'WIZ MODE')
        libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
        libtcod.console_flush()
コード例 #4
0
    def render_bar(self, x, y, x2, total_width, value, maximum, bar_color, dim_color, text_color, color_lvls):
        TEXT_PAD = 8
        tick_price = int(maximum / total_width)

        #render the background first
        libtcod.console_set_background_color(self.panel, dim_color)
        formated_str = "HP: %i/%i" % (value, maximum)
        #if displayed value == 0 - skip rendering bar
        if maximum == 0:
            return
        libtcod.console_set_foreground_color(self.panel, text_color)
        libtcod.console_print_left(self.panel, x, y, libtcod.BKGND_NONE, formated_str)
        libtcod.console_set_foreground_color(self.panel, self.create_color(bar_color[0]))
        libtcod.console_print_left(self.panel, x2, y, libtcod.BKGND_NONE, '[' + ''.ljust(total_width, '_') + ']')
        active_ticks = value * tick_price
        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_foreground_color(self.panel, self.create_color(bar_color[severity]))
        libtcod.console_print_left(self.panel, x2 + 1 ,y, libtcod.BKGND_NONE, '#'.center(active_ticks, '#'))
コード例 #5
0
 def clear_critter(self, x, y):
     libtcod.console_print_left(self.con, x, y, libtcod.BKGND_NONE, ' ')
コード例 #6
0
 def print_critter(self, x, y, char):
     libtcod.console_print_left(self.con, x, y, libtcod.BKGND_NONE, char)