Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_console_set_char_background(console, bg):
libtcodpy.console_set_char_background(console, 0, 0, bg, libtcodpy.BKGND_SET)
assert_char(console, 0, 0, bg=bg)
wall = game_map.tiles[x][y].block_sight
if visible:
if wall:
tcod.console_set_char_background(
con, x, y, colors.get("light_wall"), tcod.BKGND_SET
)
else:
tcod.console_set_char_background(
con, x, y, colors.get("light_ground"), tcod.BKGND_SET
)
game_map.tiles[x][y].explored = True
elif game_map.tiles[x][y].explored:
if wall:
tcod.console_set_char_background(
con, x, y, colors.get("dark_wall"), tcod.BKGND_SET
)
else:
tcod.console_set_char_background(
con, x, y, colors.get("dark_ground"), tcod.BKGND_SET
)
# Draw all entities in the list
entities_in_render_order = sorted(entities, key=lambda e: e.render_order.value)
for entity in entities_in_render_order:
draw_entity(con, entity, fov_map, game_map)
tcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
tcod.console_set_default_background(panel, tcod.black)
tcod.console_clear(panel)
def console_invert_color(con,x,y):
col1 = tcod.console_get_char_foreground(con,x,y)
col2 = tcod.console_get_char_background(con,x,y)
tcod.console_set_char_foreground(con, x,y, color_invert(col1))
tcod.console_set_char_background(con, x,y, color_invert(col2))
tcod.dijkstra_compute(self.dijk, self.px, self.py)
# get the maximum distance (needed for rendering)
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
d = tcod.dijkstra_get_distance(self.dijk, x, y)
if d > self.dijk_dist:
self.dijk_dist = d
# compute path from px,py to dx,dy
tcod.dijkstra_path_set(self.dijk, self.dx, self.dy)
self.recalculate = False
self.busy = 0.2
# draw the dungeon
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
if SAMPLE_MAP[x, y] == "#":
tcod.console_set_char_background(
sample_console, x, y, DARK_WALL, tcod.BKGND_SET
)
else:
tcod.console_set_char_background(
sample_console, x, y, DARK_GROUND, tcod.BKGND_SET
)
# draw the path
if self.using_astar:
for i in range(tcod.path_size(self.path)):
x, y = tcod.path_get(self.path, i)
tcod.console_set_char_background(
sample_console, x, y, LIGHT_GROUND, tcod.BKGND_SET
)
else:
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
def move(self, new):
tcod.console_set_char_foreground(
0, self.x + self.cursor_pos, self.y, WHITE)
tcod.console_set_char_background(
0, self.x + self.cursor_pos, self.y, BLACK)
self.flush=True
self.putCursor(new)
for x in range(SAMPLE_SCREEN_WIDTH):
d=libtcod.dijkstra_get_distance(path_dijk,x,y)
if d > path_dijk_dist:
path_dijk_dist=d
# compute path from px,py to dx,dy
libtcod.dijkstra_path_set(path_dijk,path_dx,path_dy)
path_recalculate = False
path_busy = 0.2
# draw the dungeon
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
if smap[y][x] == '#':
libtcod.console_set_char_background(sample_console, x, y, fov_dark_wall,
libtcod.BKGND_SET)
else:
libtcod.console_set_char_background(sample_console, x, y, fov_dark_ground,
libtcod.BKGND_SET)
# draw the path
if path_using_astar :
for i in range(libtcod.path_size(path)):
x,y = libtcod.path_get(path, i)
libtcod.console_set_char_background(sample_console, x, y,
fov_light_ground, libtcod.BKGND_SET)
else:
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
if smap[y][x] != '#':
libtcod.console_set_char_background(sample_console, x, y, libtcod.color_lerp(fov_light_ground,fov_dark_ground,
0.9 * libtcod.dijkstra_get_distance(path_dijk,x,y) / path_dijk_dist), libtcod.BKGND_SET)
for i in range(libtcod.dijkstra_size(path_dijk)):
x,y=libtcod.dijkstra_get(path_dijk,i)
libtcod.console_set_char_background(sample_console,x,y,fov_light_ground, libtcod.BKGND_SET )
def move(self, new):
tcod.console_set_char_foreground(
0, self.x + self.cursor_pos, self.y, WHITE)
tcod.console_set_char_background(
0, self.x + self.cursor_pos, self.y, BLACK)
self.flush=True
self.putCursor(new)
libtcod.BKGND_SET)
# draw the path
if path_using_astar :
for i in range(libtcod.path_size(path)):
x,y = libtcod.path_get(path, i)
libtcod.console_set_char_background(sample_console, x, y,
fov_light_ground, libtcod.BKGND_SET)
else:
for y in range(SAMPLE_SCREEN_HEIGHT):
for x in range(SAMPLE_SCREEN_WIDTH):
if smap[y][x] != '#':
libtcod.console_set_char_background(sample_console, x, y, libtcod.color_lerp(fov_light_ground,fov_dark_ground,
0.9 * libtcod.dijkstra_get_distance(path_dijk,x,y) / path_dijk_dist), libtcod.BKGND_SET)
for i in range(libtcod.dijkstra_size(path_dijk)):
x,y=libtcod.dijkstra_get(path_dijk,i)
libtcod.console_set_char_background(sample_console,x,y,fov_light_ground, libtcod.BKGND_SET )
# move the creature
path_busy -= libtcod.sys_get_last_frame_length()
if path_busy <= 0.0:
path_busy = 0.2
if path_using_astar :
if not libtcod.path_is_empty(path):
libtcod.console_put_char(sample_console, path_px, path_py, ' ',
libtcod.BKGND_NONE)
path_px, path_py = libtcod.path_walk(path, True)
libtcod.console_put_char(sample_console, path_px, path_py, '@',
libtcod.BKGND_NONE)
else:
if not libtcod.dijkstra_is_empty(path_dijk):
libtcod.console_put_char(sample_console, path_px, path_py, ' ',
libtcod.BKGND_NONE)
'''
get and apply the proper background color
for the tile containing a thing
'''
bgTile=self.get_bgcolor(x, y) #terrain, fires
bgCol=bgTile
if not rog.fireat(x,y):
if self.nthings(x, y) >= 2:
bgCol=COL['dkgreen']
elif (ent==rog.pc() and rog.settings().highlightPC ):
bgCol=COL[rog.settings().highlightColor]
elif not bgTile == self.BG_COLOR_MAIN:
bgCol=bgTile
else:
bgCol=rog.world().component_for_entity(ent, cmp.Draw).bgcol
libtcod.console_set_char_background(self.con_map_state, x,y, bgCol)