-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_functions.py
49 lines (39 loc) · 2.17 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
import libtcodpy as libtcod
from enum import Enum
class RenderOrder(Enum):
CORPSE = 1
ITEM = 2
ACTOR = 3
def render_all(con, entities, player, 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
if visible:
if wall:
libtcod.console_set_char_background(con, x, y, colors.get('light_wall'), libtcod.BKGND_SET)
else:
libtcod.console_set_char_background(con, x, y, colors.get('light_ground'), 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)
else:
libtcod.console_set_char_background(con, x, y, colors.get('dark_ground'), libtcod.BKGND_SET)
entities_in_render_order = sorted(entities, key=lambda x: x.render_order.value)
for entity in entities_in_render_order:
draw_entity(con, entity, fov_map)
libtcod.console_set_default_foreground(con, libtcod.white)
libtcod.console_print_ex(con, 1, screen_height - 2, libtcod.BKGND_NONE, libtcod.LEFT,
'HP: {0:02}/{1:02}'.format(player.fighter.hp, player.fighter.max_hp))
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):
libtcod.console_put_char(con,entity.x,entity.y,' ',libtcod.BKGND_NONE)