def draw(self): '''Draws the map to the offscreen console.''' global color_dark_wall, color_dark_ground global color_light_wall, color_light_ground for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): wall = self.map[x][y].block_sight if wall: libtcod.console_set_back(self.con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(self.con, x, y, color_dark_ground, libtcod.BKGND_SET) libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0)
def render_all(self): '''Renders all objects and tiles to the root console.''' global color_light_wall, color_dark_wall global color_light_ground, color_dark_ground if self.map.fov_recompute: self.map.fov_recompute = False libtcod.map_compute_fov(self.map.fov_map, self.map.player.x, self.map.player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): visible = libtcod.map_is_in_fov(self.map.fov_map, x, y) wall = self.map.map[x][y].block_sight if not visible: # Not visible, darken the tiles if self.map.map[x][y].explored: if wall: libtcod.console_set_back(self.con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(self.con, x, y, color_dark_ground, libtcod.BKGND_SET) else: # It's visible, light up the tiles if wall: libtcod.console_set_back(self.con, x, y, color_light_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(self.con, x, y, color_light_ground, libtcod.BKGND_SET) self.map.map[x][y].explored = True # Draw all objects to the screen for object in self.map.object_list: if object != self.map.player: object.draw() self.map.player.draw() # Blit the offscreen console to the root console and flush libtcod.console_blit(self.con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) # Display Player Stats libtcod.console_set_background_color(self.panel, libtcod.black) libtcod.console_clear(self.panel) # Print the message log y = 1 for (line, color) in game_msgs: libtcod.console_set_foreground_color(self.panel, color) libtcod.console_print_left(self.panel, MSG_X, y, libtcod.BKGND_NONE, line) y += 1 self.render_bar(1, 1, BAR_WIDTH, 'HP', self.map.player.fighter.hp, self.map.player.fighter.max_hp, libtcod.red, libtcod.darker_red) self.render_bar(1, 3, BAR_WIDTH, 'EXP', self.map.player.fighter.exp, self.map.player.fighter.max_exp, libtcod.dark_yellow, libtcod.darker_yellow) self.render_bar(1, 5, BAR_WIDTH, 'Level', self.map.player.fighter.level, 10, libtcod.blue, libtcod.dark_blue) # Check under mouse libtcod.console_set_foreground_color(self.panel, libtcod.light_grey) libtcod.console_print_left(self.panel, 1, 0, libtcod.BKGND_NONE, self.under_mouse()) libtcod.console_blit(self.panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)