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 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 render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar bar_width = int(float(value) / maximum * total_width) #background first libtcod.console_set_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #put bar at top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #some text and values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
def render_bar(x, y, total_width, name, value, maximum, bar_color, back_color): #render a bar (HP, experience, etc). first calculate the width of the bar bar_width = int(float(value) / maximum * total_width) #render the background first libtcod.console_set_background_color(panel, back_color) libtcod.console_rect(panel, x, y, total_width, 1, False) #now render the bar on top libtcod.console_set_background_color(panel, bar_color) if bar_width > 0: libtcod.console_rect(panel, x, y, bar_width, 1, False) #finally, some centered text with the values libtcod.console_set_foreground_color(panel, libtcod.white) libtcod.console_print_center(panel, x + total_width / 2, y, libtcod.BKGND_NONE, name + ': ' + str(value) + '/' + str(maximum))
def render_graphics(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute global emitters emitters = [] global glosnosc glosnosc = {} if fov_recompute: #recompute FOV if needed (the player moved or something) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #go through all tiles, and set their background color according to the FOV 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 it's not visible right now, the player can only see it if it's explored if map[x][y].explored: if wall: libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET) else: #it's visible if wall: libtcod.console_set_back(con, x, y, color_light_wall, libtcod.BKGND_SET ) else: libtcod.console_set_back(con, x, y, color_light_ground, libtcod.BKGND_SET ) #since it's visible, explore it map[x][y].explored = True #draw all objects in the list, except the player. we want it to #always appear over all other objects! so it's drawn later. for object in objects: if object != player: object.draw() player.draw() #blit the contents of "con" to the root console libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0) #prepare to render the GUI panel libtcod.console_set_background_color(panel, libtcod.black) libtcod.console_clear(panel) #print the game messages, one line at a time 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 the player's stats render_bar(1, 1, BAR_WIDTH, 'HP', player.hp, player.max_hp, libtcod.light_red, libtcod.darker_red) render_bar(1, 2, BAR_WIDTH, 'XP', player.xp, 100, libtcod.light_blue, libtcod.darker_blue) render_info(1, 4, BAR_WIDTH, 'Floor: ' + str(floor)) #display names of objects under the mouse libtcod.console_set_foreground_color(panel, libtcod.light_gray) libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse()) mouse = libtcod.mouse_get_status() (x1, y1) = (mouse.cx, mouse.cy) #print str(math.atan2(player.y-y1, player.x-x1)/math.pi*180) #blit the contents of "panel" to the root console libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
def render_graphics(): global fov_map, color_dark_wall, color_light_wall global color_dark_ground, color_light_ground global fov_recompute global emitters emitters = [] global glosnosc glosnosc = {} if fov_recompute: #recompute FOV if needed (the player moved or something) fov_recompute = False libtcod.map_compute_fov(fov_map, player.x, player.y, TORCH_RADIUS, FOV_LIGHT_WALLS, FOV_ALGO) #go through all tiles, and set their background color according to the FOV 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 it's not visible right now, the player can only see it if it's explored if map[x][y].explored: if wall: libtcod.console_set_back(con, x, y, color_dark_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(con, x, y, color_dark_ground, libtcod.BKGND_SET) else: #it's visible if wall: libtcod.console_set_back(con, x, y, color_light_wall, libtcod.BKGND_SET) else: libtcod.console_set_back(con, x, y, color_light_ground, libtcod.BKGND_SET) #since it's visible, explore it map[x][y].explored = True #draw all objects in the list, except the player. we want it to #always appear over all other objects! so it's drawn later. for object in objects: if object != player: object.draw() player.draw() #blit the contents of "con" to the root console libtcod.console_blit(con, 0, 0, MAP_WIDTH, MAP_HEIGHT, 0, 0, 0) #prepare to render the GUI panel libtcod.console_set_background_color(panel, libtcod.black) libtcod.console_clear(panel) #print the game messages, one line at a time 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 the player's stats render_bar(1, 1, BAR_WIDTH, 'HP', player.hp, player.max_hp, libtcod.light_red, libtcod.darker_red) render_bar(1, 2, BAR_WIDTH, 'XP', player.xp, 100, libtcod.light_blue, libtcod.darker_blue) render_info(1, 4, BAR_WIDTH, 'Floor: ' + str(floor)) #display names of objects under the mouse libtcod.console_set_foreground_color(panel, libtcod.light_gray) libtcod.console_print_left(panel, 1, 0, libtcod.BKGND_NONE, get_names_under_mouse()) mouse = libtcod.mouse_get_status() (x1, y1) = (mouse.cx, mouse.cy) #print str(math.atan2(player.y-y1, player.x-x1)/math.pi*180) #blit the contents of "panel" to the root console libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)