-
Notifications
You must be signed in to change notification settings - Fork 0
/
hud.py
150 lines (121 loc) · 4.71 KB
/
hud.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# coding: utf8
from bearlibterminal import terminal as blt
import renderer
from map_common import distance_to, tiles_distance_to, get_map_desc, map_check_for_creature, Directions
import game_vars
import constants
import handle_input
# need the refs
#def initialize_player(player):
# global PLAYER
# PLAYER = player
# debugging rooms
def get_room_index():
room_index = -1
for r in game_vars.level.rooms:
if r.contains((game_vars.player.x, game_vars.player.y)):
room_index = game_vars.level.rooms.index(r)
break
return room_index
def room_index_str():
index = get_room_index()
if index != -1:
return str(index)
else:
return "None"
def get_room_from_index(index):
if index != -1:
return game_vars.level.rooms[index]
def get_room_data():
index = get_room_index()
if index != -1:
room = get_room_from_index(index)
return "Center: " + str(room.center()) + " x " + str(room.x1) + " y " + str(room.y1) +\
" x2 " + str(room.x2) + " y2 " + str(room.y2) +\
" width " + str(room.x2-room.x1) + " height " + str(room.y2-room.y1)
else:
return "None"
# descriptions
def show_npc_desc(pix_x, pix_y):
w = 4
h = 10
iso_x, iso_y = renderer.pix_to_iso(pix_x, pix_y)
taken = map_check_for_creature(iso_x, iso_y)
if taken is not None and taken.creature.player is None:
hp_perc = (taken.creature.hp*100.0/taken.creature.max_hp) # *100.0
blt.layer(1)
# draw the npc
blt.puts(w, h, u"%c %s" % (taken.char, taken.creature.name_instance) )
blt.puts(w,h+2, "Enemy hp: " + str(taken.creature.hp) + " " + str(hp_perc) + "%")
# chance to hit
melee = game_vars.player.creature.melee*1.0/100.0
not_dodged = (100-taken.creature.dodge)*1.0/100.0
blt.puts(w, h+3, "Chance to hit: %.2f + %.2f = %.2f " % (melee, not_dodged, melee*not_dodged) )
blt.layer(0)
def show_tile_desc(pix_x, pix_y, fov_map):
if not hasattr(game_vars.level, 'map_desc'):
return
w = 4
h = 8
iso_x, iso_y = renderer.pix_to_iso(pix_x, pix_y)
dist = round(distance_to((iso_x, iso_y), (game_vars.player.x, game_vars.player.y)), 2)
tiles_dist = tiles_distance_to((iso_x, iso_y), (game_vars.player.x, game_vars.player.y))
blt.layer(1)
blt.puts(w,h+1, "Dist: real:" + str(dist) + " tiles: " + str(tiles_dist) + " ft: " + str(tiles_dist*5) + " ft.")
blt.puts(w, h, get_map_desc(iso_x, iso_y, fov_map, game_vars.level.current_explored, game_vars.level.map_desc))
blt.layer(0)
DIR_TO_ARROW = {
Directions.EAST: '↘',
Directions.WEST: '↖',
Directions.NORTH: '↗',
Directions.SOUTH: '↙',
Directions.NORTHEAST: '→',
Directions.SOUTHEAST: '↓',
Directions.NORTHWEST: '↑',
Directions.SOUTHWEST: '←',
# bug fix
Directions.CENTER: '.'
}
def draw_hud(pix_x, pix_y):
# hud bars
blt.layer(1)
# draw body parts' hp
x = 2
for p in game_vars.player.creature.body_parts:
renderer.draw_bar(x,15,p.max_hp, str(p.name), p.hp, p.max_hp, "red", "darker red")
x += p.max_hp+1
#renderer.draw_bar(2, 15, 20, "HP", game_vars.player.creature.hp, game_vars.player.creature.max_hp, "red", "darker red",
# str(game_vars.player.creature.hp))
renderer.draw_bar(2, 17, 20, "Nutrition", game_vars.player.creature.player.nutrition, 500, "green", "darker green")
renderer.draw_bar(2, 19, 20, "Thirst", game_vars.player.creature.player.thirst, 300, "blue", "darker blue")
blt.color(4294967295)
# compass
blt.puts(2, 21, "[color=yellow] ↑ NW (%s key) " % (handle_input.get_up_key()))
# debug
# on top of map
blt.layer(1)
blt.puts(2, 4, "[color=red] player position: %d %d" % (game_vars.player.x, game_vars.player.y))
blt.puts(2, 5, "[color=red] camera offset: %d %d" % (game_vars.camera.offset[0], game_vars.camera.offset[1]))
blt.puts(2, 6, "[color=red] vi keys: %s " % (str(constants.VI_KEYS)))
# queue
x = 25
y = 1
for i in range (len(game_vars.player.creature.move_queue)-1):
m = game_vars.player.creature.move_queue[i]
blt.puts(x, y, DIR_TO_ARROW[m]) #str(m))
x += 2
# add max length of (x,y) string
#x += 8
# overlay queue on map
blt.layer(3)
render_pos = constants.RENDER_POSITIONS
from renderer import draw_iso
for i in range(len(game_vars.player.creature.path_moves)-1):
p, m = game_vars.player.creature.path_moves[i]
x,y = p
x,y = draw_iso(x, y, render_pos)
blt.puts(x,y, DIR_TO_ARROW[m])
blt.layer(1)
# this works on map tiles
show_tile_desc(pix_x, pix_y, game_vars.fov_map)
show_npc_desc(pix_x, pix_y)