Пример #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_examine(self, player, map):
        libtcod.console_clear(self.con_full)
        _x, _y = self.viewport.look_x, self.viewport.look_y
        if (_x, _y) == self.viewport.playerxy:
            #starting point of view
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.con_full, 1, 0, 'This is you'.ljust(SCREEN_WIDTH, ' '))
            libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' '))
        else:
            visible = rlfl.has_flag(map.current.fov_map0, (_x, _y), rlfl.CELL_MEMO)
            if not visible:
                libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
                libtcod.console_print(self.con_full, 1, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' '))
                libtcod.console_print(self.con_full, 1, 1, 'Press e to go back to look-around mode'.ljust(SCREEN_WIDTH, ' '))
                return

            result = ''
            crit = map.critter_at(_x, _y)
            if crit:
                result +=  getattr(crit, 'description_' + player.time)
            tile_at = map.tile_at(_x, _y)
            result += tile_at.get_full_description(player.time)
            result += '\n\nPress e to go back to look-around mode.'
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.con_full, 0, 0, result.ljust(SCREEN_WIDTH, ' '))
            libtcod.console_blit(self.con_full, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
            libtcod.console_flush()
Пример #3
0
    def render(self):
        libtcod.console_clear(self.console)
        pages = len(self.content) / (self.height - 2)
        pages += 1 if len(self.content) % (self.height - 2) != 0 else 0
        x = 0
        y = 1
        if self.offset:
            libtcod.console_set_default_foreground(self.console, libtcod.dark_crimson)
            libtcod.console_print(self.console, 0, 0, "---  [-][PgDwn] Scroll up ---" .center(self.width))
        for line, rgb, newline in self.content[self.offset:]:
            libtcod.console_set_default_foreground(self.console, rgb)
            libtcod.console_print(self.console, x, y, line)
            if newline:
                x = 0
                y+= 1
            else:
                x += len(line)
        y = self.height - 1
        if pages > 1:
            libtcod.console_set_default_foreground(self.console, libtcod.dark_crimson)
            footer = "---  [+][PgDwn] Scroll down \t Line [%d]/[%d] ---" % (self.offset, len(self.content))
            libtcod.console_print(self.console, 0, y, footer.center(self.width))

        libtcod.console_blit(self.console, 0, 0, self.width, self.height, 0, 0, 0)
        libtcod.console_flush()
Пример #4
0
 def render_messages(self, map, player):
     if gl.__lookmode__:
         self.render_tile_description(map, player)
         libtcod.console_blit(self.panel_msg, 0, 0, SCREEN_WIDTH, MSG_PANEL_HEIGHT, 0, 0, MSG_PANEL_Y)
         return
     #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_default_foreground(self.panel_msg, self.message_colours.get(level, libtcod.white))
         libtcod.console_print(self.panel_msg, 0, y, line.ljust(SCREEN_WIDTH, ' '))
         y += 1
     libtcod.console_blit(self.panel_msg, 0, 0, SCREEN_WIDTH, MSG_PANEL_HEIGHT, 0, 0, MSG_PANEL_Y)
Пример #5
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)
Пример #6
0
 def render_intro(self, intro_text):
     libtcod.console_print(self.con2, SCREEN_WIDTH / 3, (SCREEN_HEIGHT /3) , intro_text)
     # do a cross-fading from off1 to off2
     for i in range(1, 110):
         libtcod.console_blit(self.con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0) # renders the first screen (opaque)
         libtcod.console_blit(self.con2, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0, i / 128.0,
                              i / 128.0) # renders the second screen (transparent)
         libtcod.console_flush()
     libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, self.key, self.mouse)
     for i in range(1, 128):
         libtcod.console_blit(self.con2, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0) # renders the first screen (opaque)
         libtcod.console_blit(self.con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0, i / 128.0,
                              i / 128.0) # renders the second screen (transparent)
Пример #7
0
 def render_dialog(self, title):
     libtcod.console_set_keyboard_repeat(1000, 500)
     libtcod.console_print_frame(self.con, 10, 10, 30, 3, True, libtcod.BKGND_NONE, title)
     line = ''
     while True:
         libtcod.console_print(self.con, 11, 11, ' '.rjust(len(line) + 2, ' '))
         libtcod.console_print(self.con, 11, 11, line + '_')
         libtcod.console_blit(self.con, 10, 10, 30, 3, 0, 10, 10)
         libtcod.console_flush()
         libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, self.key, self.mouse)
         key = self.key
         if key.c == 27:
             game_input.default_rate()
             return None
         if key.c == 13:
             game_input.default_rate()
             return line
         if key.c == 8:
             line = line[0:len(line) - 1]
         elif key.c != 0:
             line += chr(key.c)
Пример #8
0
 def render_intro(self, intro_text):
     libtcod.console_print_center(self.con2, SCREEN_WIDTH / 3, (SCREEN_HEIGHT /3) , libtcod.BKGND_ADD, intro_text)
     # do a cross-fading from off1 to off2
     for i in range(1, 110):
         libtcod.console_blit(self.con, 0, 0, 80, 50, 0, 0, 0) # renders the first screen (opaque)
         libtcod.console_blit(self.con2, 0, 0, 80, 50, 0, 0, 0, i / 128.0,
                              i / 128.0) # renders the second screen (transparent)
         libtcod.console_flush()
     libtcod.console_wait_for_keypress(True)
     for i in range(1, 128):
         libtcod.console_blit(self.con2, 0, 0, 80, 50, 0, 0, 0) # renders the first screen (opaque)
         libtcod.console_blit(self.con, 0, 0, 80, 50, 0, 0, 0, i / 128.0,
                              i / 128.0) # renders the second screen (transparent)
         libtcod.console_flush()
Пример #9
0
 def render_yn_dialog(self, title, warn=False):
     if warn:
         libtcod.console_set_default_foreground(self.con, libtcod.red)
     else:
         libtcod.console_set_default_foreground(self.con, libtcod.white)
     libtcod.console_set_keyboard_repeat(1000, 500)
     libtcod.console_print_frame(self.con, 10, 10, 30, 3, True, libtcod.BKGND_NONE, title)
     line = ''
     #todo - adjust the size of window to match line's size
     while True:
         libtcod.console_print_ex(self.con, 11, 11, libtcod.BKGND_NONE, libtcod.LEFT, ' '.rjust(len(line) + 2, ' '))
         libtcod.console_print_ex(self.con, 11, 11, libtcod.BKGND_NONE, libtcod.LEFT, line + '_')
         libtcod.console_blit(self.con, 10, 10, 30, 3, 0, 10, 10)
         libtcod.console_flush()
         libtcod.sys_check_for_event(libtcod.KEY_PRESSED, self.key, self.mouse)
         key = self.key
         if chr(key.c) == 'y' or chr(key.c) == 'Y' or key.c == 13:
             game_input.default_rate()
             return True
         if chr(key.c) == 'n' or chr(key.c) == 'N' or key.c == 27:
             game_input.default_rate()
             return False
Пример #10
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()
Пример #11
0
    def render_map(self, map, player):
        #todo optimize (see http://umbrarumregnum.110mb.com/cookbook/node/24)
        if not self.viewport:
            self.viewport = Viewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, map)
        if gl.__fov_recompute__:
            gl.logger.debug('Recomputing fov')
            gl.__fov_recompute__ = False
            map.recompute_fov()

        consolex, consoley, xx = 0,0, 0
        self.viewport.update_coords(player.x, player.y)
        gl.logger.debug('Diplaying viewport from %d:%d to %d:%d' % (self.viewport.x, self.viewport.y, self.viewport.x2, self.viewport.y2))
        buffer = libtcod.ConsoleBuffer(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
        for y in xrange(self.viewport.y, self.viewport.y2):
            for x in xrange(self.viewport.x, self.viewport.x2):

                tile = map.tile_at(x, y)
                if not tile:
                    consolex += 1
                    continue
                xy = (x, y)
                seen = rlfl.has_flag(map.current.fov_map0, xy, rlfl.CELL_MEMO) | gl.__wizard_mode__
                #                visible = libtcod.map_is_in_fov(map.current.fov_map, x, y)
                visible = rlfl.has_flag(map.current.fov_map0, xy, rlfl.CELL_SEEN)
                del xy
                #if tile is seen or visible to player - print it
                char = None
                if seen or visible:
                    if tile.items and len(tile.items):
                        char = tile.items[-1].char
                    else:
                        char = tile.char
                    #                    libtcod.console_set_char(self.con, consolex, consoley, char)
                    #if it's not in LOS, but seen - print in dim color
                else:
                    char = ' '
                fc = tile.dim_color
                bc = None
                if not visible and not seen:
                    bc = BLACK
                else:
                    #if it's in LOS - print
                    fc = tile.color
                    if tile.items and len(tile.items) > 1:
                        bc = libtcod.desaturated_yellow
                    else:
                        bc = tile.color_back
                buffer.set(consolex, consoley, bc[0], bc[1], bc[2], fc[0], fc[1], fc[2], char)
                consolex += 1
            xx = consolex
            consolex = 0
            consoley += 1

        gl.logger.debug('Printing critters')
        for critter in map.critters:
            if not self.viewport.in_view(critter.x, critter.y):
                continue
            if critter.last_seen_at and not self.viewport.in_view(*critter.last_seen_at):
                continue
            fc = critter.color
            x, y = self.viewport.adjust_coords(critter.x, critter.y)
            if rlfl.has_flag(map.current.fov_map0, (critter.x, critter.y), rlfl.CELL_SEEN) or gl.__wizard_mode__:
                critter.last_seen_at = critter.x, critter.y
                buffer.set_fore(x, y, fc[0], fc[1], fc[2], critter.char)
            elif critter.last_seen_at is not None:
                color = dim_color(critter.color)
                fc = color
                buffer.set_fore(x, y, fc[0], fc[1], fc[2], critter.char)

        gl.logger.debug('Printing player')
        x, y = self.viewport.adjust_coords(player.x, player.y)
        buffer.set_fore(x, y, player.color[0], player.color[1], player.color[2], player.char)
        tile = map.tile_at(player.x, player.y)
        if tile.color_back > (200, 200, 200):
            buffer.set_back(x, y, 200, 200, 200)

        if gl.__wizard_mode__:
            libtcod.console_print(self.con, 0, VIEWPORT_HEIGHT - 1, 'WIZ MODE')

        for x in xrange(0, VIEWPORT_WIDTH):
            for y in xrange(0, VIEWPORT_HEIGHT):
                if x >= xx:
                    buffer.set_fore(x, y, 0, 0, 0, ' ')

        if gl.__lookmode__:
            buffer.set_back(self.viewport.look_x - self.viewport.x, self.viewport.look_y - self.viewport.y, 255, 255, 255)
        buffer.blit(self.con)
        libtcod.console_blit(self.con, 0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT, 0, 0, 0)
        libtcod.console_flush()