Example #1
0
    def render(self, level, x, y, minx, miny, maxx, maxy, fov_map, main_area, *args, **kwargs):
        """
        Renders current level.

        Takes the level map and draws each tile on it, according to
        its properties.

        Since the map may be bigger (or smaller) than the screen, it
        makes some calculations to center (or try it at best) on the
        given (x,y) coordinates.

        TODO:
          - draw level objects. It just draws the map (and the player
            but just in a testing manner)
          - instead of drawing from level.mapa, ui.py should call a
            draw routing in the wrapper, which should receive the
            contents to be drawn in a specific area, without any game
            details being revealed here. This would also remove the
            previous message() method

        Arguments:
          level       : the world.level with the map to render
          (x,y)       : the coordinates to be the center of the drawing
          (minx,miny) : the minimum coordinates from the map to be drawn
          (maxx,maxy) : the maximum coordinates from the map to be drawn
          fov_map
          main_area   : the area where the map is to be drawn
        """
        from world.tile import TILETYPES
        libtcod.console_clear(main_area['con'])

        map_ = level.mapa

        # determine console coordinates to begin rendering according to map size
        (conx, cony) = ((main_area['w'] - map_.w)//2 if map_.w < main_area['w'] else 0,
                        (main_area['h'] - map_.h)//2 if map_.h < main_area['h'] else 0)

        # draw map tiles
        for my, cy in zip(range(miny, maxy), range(cony, map_.h + cony)):
            for mx, cx in zip(range(minx, maxx), range(conx, map_.w + conx)):
                try:
                    visible = libtcod.map_is_in_fov(fov_map, mx, my)
                    tile = map_.mapa[mx][my]
                except Exception as e:
                    continue
                # it's out of the player's FOV, player will see it only if explored
                if not visible:
                    if tile.explored:
                        # draw map tile with char/color <- modifications for explored/not visible
                        libtcod.console_put_char_ex(main_area['con'],
                                                    cx, cy,
                                                    ' ' if TILETYPES[tile.tipo]['just_color'] else TILETYPES[tile.tipo]['char'].encode('utf8'),
                                                    libtcod.white,
                                                    getcolorbyname(TILETYPES[tile.tipo]['nv_color']))
                    else:
                        libtcod.console_put_char_ex(main_area['con'],
                                                    cx, cy,
                                                    ' ',
                                                    libtcod.black,
                                                    libtcod.black)
                # it's visible
                else:
                    # draw map tile with char/color <- as is since it is visible
                    libtcod.console_put_char_ex(main_area['con'],
                                                cx, cy,
                                                ' ' if TILETYPES[tile.tipo]['just_color'] else TILETYPES[tile.tipo]['char'].encode('utf8'),
                                                libtcod.white,
                                                getcolorbyname(TILETYPES[tile.tipo]['color']))
                    # since now it's visible, mark it as explored
                    tile.explored = True
        for p in level.players:
            libtcod.console_set_char(main_area['con'],
                                     conx+x-minx, cony+y-miny,
                                     '@')

        # draw objects in map...

        # blit contents
        self.flush(main_area)
Example #2
0
 def draw_char(self, char, coord=(0, 0)):
     y, x = coord
     symbol, (fg, bg) = char
     libtcod.console_put_char_ex(self.win, x, y, symbol, self.color_map[fg], self.color_map[bg])