Exemple #1
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()
Exemple #2
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)
Exemple #3
0
 def render_stats_two_column(self, x, y, text1, value, x2, text2, value2, lbl_color, value_color):
     libtcod.console_set_default_foreground(self.panel, self.create_color(lbl_color))
     libtcod.console_print(self.panel, x, y, text1 + ':')
     libtcod.console_print(self.panel, x2, y, text2 + ':')
     libtcod.console_set_default_foreground(self.panel, self.create_color(value_color))
     libtcod.console_print(self.panel, x + len(text1) + 1, y, str(value))
     libtcod.console_print(self.panel, x2 + len(text2) + 1, y,str(value2))
Exemple #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)
Exemple #5
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)
Exemple #6
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()
Exemple #7
0
    def render_tile_description(self, map, player):
        libtcod.console_clear(self.panel_msg)
        _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.panel_msg, 0, 0, 'Look-around mode. Use keys to move cursor'.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.panel_msg, 0, 0, 'You can\'t see this far'.ljust(SCREEN_WIDTH, ' '))
                return

            result = ''
            crit = map.critter_at(_x, _y)
            if crit:
                result += 'You see ' + crit.name + '.\n'
            tile_at = map.tile_at(_x, _y)
            result += tile_at.get_view_description()
            result += 'Press e to examine'
            libtcod.console_set_default_foreground(self.panel_msg, libtcod.white)
            libtcod.console_print(self.panel_msg, 0, 0, result.ljust(SCREEN_WIDTH, ' '))
Exemple #8
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, '#'))
Exemple #9
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()