def draw(self): '''Draws the object to the background console.''' # ONLY draw objects _if_ they are in view of the player if libtcod.map_is_in_fov(self.map.fov_map, self.x, self.y): libtcod.console_set_foreground_color(self.con, self.color) libtcod.console_put_char(self.con, self.x, self.y, self.char, libtcod.BKGND_NONE)
def render_bar(self, x, y, twidth, name, value, maxv, color, bcolor): '''A generic status bar.''' bar_width = int(float(value) / maxv * twidth) # Draw the background libtcod.console_set_background_color(self.panel, bcolor) libtcod.console_rect(self.panel, x, y, twidth, 1, False) # Draw the top bar libtcod.console_set_background_color(self.panel, color) if bar_width > 0: libtcod.console_rect(self.panel, x, y, bar_width, 1, False) # Add the text labels libtcod.console_set_foreground_color(self.panel, libtcod.white) libtcod.console_print_center(self.panel, x+twidth/2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maxv))
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)