def draw(self, dungeon, player, monsters, items, messages, draw_not_fov): #render the screen if draw_not_fov is True: is_in_fov_func = lambda pos: True else: is_in_fov_func = player.is_in_fov dungeon.draw_ui(self.con, is_in_fov_func) objects = items + monsters for obj in objects: if player.is_in_fov(obj.position) or draw_not_fov: draw_object(self.con, obj) draw_object(self.con, player) #prepare to render the GUI panel libtcod.console_set_default_background(self.panel, libtcod.black) libtcod.console_clear(self.panel) #show the player's stats self.hp_bar.update(player.hp, player.max_hp) self.hp_bar.draw(self.panel, Rect(1, 2, BAR_WIDTH, 1)) libtcod.console_print_ex(self.panel, 1, 3, libtcod.BKGND_NONE, libtcod.LEFT, "Attack: " + str(player.power)) libtcod.console_print_ex(self.panel, 1, 4, libtcod.BKGND_NONE, libtcod.LEFT, "Defense: " + str(player.defense)) #print the game messages, one line at a time y = 1 for line in messages: libtcod.console_set_default_foreground(self.panel, libtcod.white) libtcod.console_print_ex(self.panel, MSG_X, y, libtcod.BKGND_NONE, libtcod.LEFT, line) y += 1 self.flush(dungeon, player, monsters, items)
def draw(self, console, level, is_in_fov_func): #go through all tiles, and set their background color for y in range(MAP_HEIGHT): for x in range(MAP_WIDTH): wall = level.is_blocked((x, y)) visible = is_in_fov_func((x, y)) color = libtcod.black if visible: color = COLORS.light_wall if wall else COLORS.light_ground elif level.explored[x][y]: color = COLORS.dark_wall if wall else COLORS.dark_ground libtcod.console_set_char_background(console, x, y, color, libtcod.BKGND_SET) #draw stairs stairs = level.stairs if stairs is not None and is_in_fov_func(stairs): draw_object(console, Stairs(stairs))