-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_functions.py
50 lines (37 loc) · 2.08 KB
/
render_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import tcod as libtcod
def render_all(con, entities, game_map, fov_map, fov_recompute, screen_width, screen_height, colors):
if fov_recompute:
for y in range(game_map.height):
for x in range(game_map.width):
visible = libtcod.map_is_in_fov(fov_map, x, y)
wall = game_map.tiles[x][y].block_sight
room = game_map.tiles[x][y].room
if visible:
if wall:
libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
elif room:
libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), libtcod.BKGND_SET)
else:
libtcod.console_set_char_background(con, x, y, colors.get('corridor'), libtcod.BKGND_SET)
game_map.tiles[x][y].explored = True
elif game_map.tiles[x][y].explored:
if wall:
libtcod.console_set_char_background(con, x, y, colors.get('dark_wall'), libtcod.BKGND_SET)
elif room:
libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)
else:
libtcod.console_set_char_background(con, x, y, colors.get('corridor'), libtcod.BKGND_SET)
# Draw all entities in the list
for entity in entities:
draw_entity(con, entity, fov_map)
libtcod.console_blit(con, 0, 0, screen_width, screen_height, 0, 0, 0)
def clear_all(con, entities):
for entity in entities:
clear_entity(con, entity)
def draw_entity(con, entity, fov_map):
if libtcod.map_is_in_fov(fov_map, entity.x, entity.y):
libtcod.console_set_default_foreground(con, entity.color)
libtcod.console_put_char(con, entity.x, entity.y, entity.char, libtcod.BKGND_NONE)
def clear_entity(con, entity):
# erase the character that represents this object
libtcod.console_put_char(con, entity.x, entity.y, ' ', libtcod.BKGND_NONE)