Somehow I keep getting an error from trying to print over the edge of the console, but I can't see how. There's only two main rendering codes, one that renders the 'borders' of the interface, and one that renders everything else. Here's the code, I don't know what's causing it.
Relevant Constants
#actual size of the window
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50
#coordinates relevant to the GUI
MAP_X_OFFSET = 1
MAP_Y_OFFSET = 5
#size of the map
MAP_WIDTH = 67
MAP_HEIGHT = 43
and here's the two rendering routines
def render_all():
global fov_map, color_dark_wall, color_light_wall
global color_dark_ground, color_light_ground
global fov_recompute
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_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, chr(176), color_dark_wall, libtcod.black)
else:
libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, '.', color_dark_ground, libtcod.black)
else:
#it's visible
if wall:
libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, chr(176), color_light_wall, libtcod.black)
else:
libtcod.console_put_char_ex(con, x+MAP_X_OFFSET, y+MAP_Y_OFFSET, '.', color_light_ground, libtcod.black)
#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(3, 2, BAR_WIDTH, player.fighter.hp, player.fighter.max_hp,
libtcod.light_red, libtcod.darker_red)
#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())
#blit the contents of "panel" to the root console
libtcod.console_blit(panel, 0, 0, SCREEN_WIDTH, PANEL_HEIGHT, 0, 0, PANEL_Y)
#render the UI over everything else
render_UI()
def render_UI():
global gui
libtcod.console_print_left(gui, 0,4, libtcod.BKGND_SET, '+-------------------------------------------------------------------+----------+')
libtcod.console_print_left(gui, 0,49, libtcod.BKGND_SET, '+-------------------------------------------------------------------+----------+')
y = 5
while y < 48:
libtcod.console_print_left(gui, 0,y, libtcod.BKGND_SET, '| | |')
y += 1
libtcod.console_blit(gui, 0, 0, 80, 50, 0, 0, 0, 1, 0)
libtcod.console_flush()
So at the bottom left, even after the offsets, nothing should be printed outside the console. Yet I'm getting that error returned. It's strange though. Sometimes it works fine and there are no errors, sometimes it doesn't print anything and returns an error, and sometimes it will print the whole GUI and then return an error. The object draw/clear class also has the offset added in, but could never have an x/y value outside of the map of course.