def draw_player_stats(): """ Print player info and stats in the side panel. """ tile = object_at(player.x, player.y) if not tile: tile = game_map[player.x][player.y] # the object/tile name player is standing on libtcod.console_print_ex(0, 2 + (C.MAP_WIDTH / 2), C.SCREEN_HEIGHT - 2, libtcod.BKGND_NONE, libtcod.CENTER, "%c%s%c" % (C.COL5, tile.name, C.COLS)) # player hearts if player.weak: heart_colors = [libtcod.red]* 10 else: heart_colors = (libtcod.red, libtcod.red, libtcod.orange, libtcod.orange , libtcod.amber, libtcod.amber, libtcod.lime, libtcod.lime , libtcod.chartreuse, libtcod.chartreuse) for heart in range(player.get_hearts()): libtcod.console_put_char_ex( 0, heart + C.STAT_HEART_LEFT, C.STAT_HEART_TOP ,chr(3), heart_colors[heart], None) texts = [ "level: %s" % (player.level) ,"score: %s" % (player.score) ,player.inventory_name(prefix="carrying: ") ] if len(player.quests) > 0: texts.append("+ %s" % (player.quests[-1].title)) # level, score, inventory libtcod.console_print_ex( 0, C.STAT_HEART_LEFT, 1 ,libtcod.BKGND_NONE, libtcod.LEFT ,"\n".join(texts) ) # player health status if player.weak: libtcod.console_print_ex(0, C.MAP_WIDTH, C.STAT_HEART_TOP ,libtcod.BKGND_NONE, libtcod.RIGHT ,"%c*weakness*%c" % (C.COL1, C.COLS)) elif player.thirsty: libtcod.console_print_ex(0, C.MAP_WIDTH, C.STAT_HEART_TOP ,libtcod.BKGND_NONE, libtcod.RIGHT ,"%c*thirstys*%c" % (C.COL2, C.COLS)) elif player.hungry: libtcod.console_print_ex(0, C.MAP_WIDTH, C.STAT_HEART_TOP ,libtcod.BKGND_NONE, libtcod.RIGHT ,"%c*hungrys*%c" % (C.COL2, C.COLS)) elif player.mustpiddle: libtcod.console_print_ex(0, C.MAP_WIDTH, C.STAT_HEART_TOP ,libtcod.BKGND_NONE, libtcod.RIGHT ,"%c*piddles*%c" % (C.COL2, C.COLS))
def render_all(): global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground, fov_recompute if fov_recompute: #recompute FOV if needed fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, 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(fov_map, x, y) wall = map[x][y].block_sight if not visible: if map[x][y].explored: if wall: libtcod.console_put_char_ex( con, x, y, '#', color_dark_wall, libtcod.black) else: libtcod.console_put_char_ex( con, x, y, '.', color_dark_ground, libtcod.black) else: if wall: libtcod.console_put_char_ex(con, x, y, '#', color_light_wall, libtcod.black) else: libtcod.console_put_char_ex(con, x, y, '.', color_light_ground, libtcod.black) map[x][y].explored = True #draw everything for stuff in objects: if stuff != player: stuff.draw() player.draw() #we are "blitting" our offscreen console oot the root console libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) #render GUI libtcod.console_set_background_color(panel, libtcod.black) libtcod.console_clear(panel) #print game messages y = 1 for (line, color) in game_msgs: libtcod.console_set_foreground_color(panel, color) libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line) y += 1 #show player stats render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) #blit onto root console libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def draw_map(): """ Draw the map tiles onto the canvas. """ for y in range(C.MAP_HEIGHT - 0): for x in range(C.MAP_WIDTH - 0): tile = game_map[x][y] if player.wizard or libtcod.map_is_in_fov(fov_map, x, y): tile.seen = True libtcod.console_put_char_ex(canvas, x, y, tile.char, tile.fgcolor, tile.bgcolor) elif tile.seen: libtcod.console_put_char_ex(canvas, x, y, tile.char ,libtcod.black, libtcod.darkest_grey)
def render_all(): global fov_map, color_dark_wall, color_light_wall, color_dark_ground, color_light_ground, fov_recompute if fov_recompute: #recompute FOV if needed fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, 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(fov_map, x, y) wall = map[x][y].block_sight if not visible: if map[x][y].explored: if wall: libtcod.console_put_char_ex(con, x, y, '#', color_dark_wall, libtcod.black) else: libtcod.console_put_char_ex(con, x, y, '.', color_dark_ground, libtcod.black) else: if wall: libtcod.console_put_char_ex(con, x, y, '#', color_light_wall, libtcod.black) else: libtcod.console_put_char_ex(con, x, y, '.', color_light_ground, libtcod.black) map[x][y].explored = True #draw everything for stuff in objects: if stuff != player: stuff.draw() player.draw() #we are "blitting" our offscreen console oot the root console libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) #render GUI libtcod.console_set_background_color(panel, libtcod.black) libtcod.console_clear(panel) #print game messages y = 1 for (line, color) in game_msgs: libtcod.console_set_foreground_color(panel, color) libtcod.console_print_left(panel, MSG_X, y, libtcod.BKGND_NONE, line) y += 1 #show player stats render_bar(1, 1, BAR_WIDTH, 'HP', player.fighter.hp, player.fighter.max_hp, libtcod.light_red, libtcod.darker_red) #blit onto root console libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def draw_objects(): """ Place all map objects on the canvas. """ # items and non-NPC's for obj in [e for e in game_objects if not isinstance(e, cls.AnimalBase)]: if obj.x > 0: #TODO replace with a visible property if player.wizard or libtcod.map_is_in_fov(fov_map, obj.x, obj.y): player.msg("You see %c%s%c" % (C.COL3, obj.name, C.COLS) , allow_duplicates=False) libtcod.console_put_char_ex(canvas, obj.x, obj.y, obj.char, obj.fgcolor, obj.bgcolor) # NPC's for obj in [e for e in game_objects if isinstance(e, cls.AnimalBase) and not isinstance(e, cls.Player)]: if obj.x > 0: #TODO replace with a visible property if player.wizard or libtcod.map_is_in_fov(fov_map, obj.x, obj.y): player.msg("You see %c%s%c" % (C.COL4, obj.name, C.COLS) , allow_duplicates=False) if obj.see_message: player.msg("%c%s%c" % (C.COL2, obj.see_message, C.COLS) ,allow_duplicates=False) # draw the NPC background color to match the map libtcod.console_put_char_ex(canvas, obj.x, obj.y, obj.char, obj.fgcolor , game_map[obj.x][obj.y].bgcolor) # draw player to match the map background libtcod.console_put_char_ex(canvas, player.x, player.y, player.char, player.fgcolor , game_map[player.x][player.y].bgcolor)
def render(self): for y in xrange(self.__height): for x in xrange(self.__width): visible = self.is_in_fov(x, y) tile = self.__map[y][x] if not visible: if tile.explored: if tile.blocks_sight: libtcod.console_put_char_ex(self.__con, x, y, '#', self.dark_color, self.bg_color) else: libtcod.console_put_char_ex(self.__con, x, y, '.', self.dark_color, self.bg_color) else: if tile.blocks_sight: libtcod.console_put_char_ex(self.__con, x, y, '#', self.lighted_color, self.bg_color) else: libtcod.console_put_char_ex(self.__con, x, y, '.', self.lighted_color, self.bg_color) tile.explored = True
def clear(self): #erase the ghosts when moving around libtcod.console_put_char_ex(con, self.x, self.y, ' ', libtcod.light_grey, libtcod.BKGND_NONE)
def blit_player_stats(): """ Draw player stats and quests screen. """ libtcod.console_clear(0) icon = libtcod.image_load(os.path.join('data', 'images', 'stats-frame.png')) libtcod.image_blit_rect(icon, 0, C.MAP_LEFT, C.MAP_TOP, -1, -1, libtcod.BKGND_SET) if player.carrying: if player.carrying.quest_id: inv_item = "%c%s%c\n%c*quest item*%c" % \ (C.COL3, player.carrying.name, C.COLS, C.COL4, C.COLS) else: inv_item = "%c%s%c" % (C.COL3, player.carrying.name, C.COLS) else: inv_item = "" labels = ( "" ,"" ,"%clevel%c:" % (C.COL5, C.COLS) ,"%cscore%c:" % (C.COL5, C.COLS) ,"%cmoves%c:" % (C.COL5, C.COLS) ,"%cinventory%c:" % (C.COL5, C.COLS) ) values = [ "%cTop Dog%c" % (C.COL5, C.COLS) ,"" ,str(player.level) ,str(player.score) ,str(player.moves) ,inv_item ] # name, score, inventory libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT, C.STATS_SCREEN_TOP, libtcod.BKGND_NONE, libtcod.RIGHT, "\n".join(labels)) libtcod.console_print_ex(0, C.STATS_SCREEN_LEFT + 2, C.STATS_SCREEN_TOP, libtcod.BKGND_NONE, libtcod.LEFT, "\n".join(values)) # quests values = [] if len(player.quests) > 0: values = ["%cQUESTS%c\n" % (C.COL5, C.COLS)] for q in player.quests: values.append("+ %s" % (q.title)) # hungry, thirsty, piddle, inventory if player.weak: values.append("+ %cweak%c, [e]at food" % (C.COL1, C.COLS)) if player.hungry: values.append("+ %chungry%c, [e]at *food*" % (C.COL2, C.COLS)) if player.thirsty: values.append("+ %cthirsty%c, [d]rink water" % (C.COL2, C.COLS)) libtcod.console_print_ex(0, 4, C.SCREEN_HEIGHT / 2, libtcod.BKGND_NONE, libtcod.LEFT, "\n".join(values)) # player hearts if player.weak: heart_colors = [libtcod.red]* 10 else: heart_colors = (libtcod.red, libtcod.red, libtcod.orange, libtcod.orange , libtcod.amber, libtcod.amber, libtcod.lime, libtcod.lime , libtcod.chartreuse, libtcod.chartreuse) for heart in range(player.get_hearts()): libtcod.console_put_char_ex( 0, heart + C.STAT_HEART_LEFT, C.STAT_HEART_TOP ,chr(3), heart_colors[heart], None)
def screenPrint(self, x, y, cell): libtcod.console_put_char_ex(0, x, y, cell.character, cell.fgColour, cell.bgColour)