-
Notifications
You must be signed in to change notification settings - Fork 0
/
Misc.py
323 lines (298 loc) · 7.79 KB
/
Misc.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
""" Misc functions not attached to classes """
from random import randint
from math import sqrt
import pygame
def roll_damage(damage, modifier=1):
"""Rolls the damage using various dice rolls"""
if damage == 20:
return roll_d_20() * modifier
elif damage == 12:
return roll_d_12() * modifier
elif damage == 10:
return roll_d_10() * modifier
elif damage == 8:
return roll_d_8() * modifier
elif damage == 6:
return roll_d_6() * modifier
elif damage == 4:
return roll_d_4() * modifier
else:
return flip_coin() * modifier
def roll_d_8():
"""roll a d8"""
return randint(1, 8)
def roll_d_6():
"""roll a d6"""
return randint(1, 6)
def roll_d_4():
"""roll d4"""
return randint(1, 4)
def flip_coin():
"""flips a coin"""
return randint(0, 1)
def roll_d_20():
"""roll a d 20, original isn't it"""
return randint(1, 20)
def roll_d_10():
"""roll a d 10"""
return randint(1, 10)
def roll_d_12():
"""roll a d 12"""
return randint(1, 12)
def is_in_fov(mob, player):
"""check if a player and a mob can see eachother"""
if (player.x, player.y, player.z) in mob.fov:
return True
return False
def move_cost(c1, c2):
"""Calculate the cost of moving between spots on the map (Euclidean)"""
return sqrt((c1[0] - c2[0]) ** 2 + (c1[1] - c2[1]) ** 2)
def pick_wall_tile(tiles):
"""pick the specific wall / fog tiles based on the adjacent values"""
tl_corner = False
tr_corner = False
bl_corner = False
br_corner = False
left = False
right = False
top = False
bottom = False
if tiles[1][0] == 1:
top = True
if tiles[2][1] == 1:
right = True
if tiles[1][2] == 1:
bottom = True
if tiles[0][1] == 1:
left = True
if tiles[0][0] == 1:
tl_corner = True
if tiles[2][0] == 1:
tr_corner = True
if tiles[0][2] == 1:
bl_corner = True
if tiles[2][2] == 1:
br_corner = True
if (
left == False
and right == False
and top == False
and bottom == False
and tl_corner == False
and tr_corner == False
and bl_corner == False
and br_corner == False
):
# no floors around normal black tile
return 0
elif (
left
and right == False
and top == False
and bottom == False
and bl_corner
and br_corner
and tl_corner
and tr_corner == False
):
# left and bottom right corner
return 26
elif (
left
and right == False
and top == False
and bottom == False
and bl_corner
and br_corner == False
and tl_corner
and tr_corner
):
# left and top right corner
return 27
elif (
left == False
and right
and top == False
and bottom == False
and bl_corner
and br_corner
and tl_corner == False
and tr_corner
):
# right and bottom left corner
return 28
elif (
left == False
and right
and top == False
and bottom == False
and bl_corner == False
and br_corner
and tl_corner
and tr_corner
):
# right and top left corner
return 29
elif (
left == False
and right == False
and top == False
and bottom == False
and tl_corner
):
# top left corner
return 15
elif (
left == False
and right == False
and top == False
and bottom == False
and tr_corner
):
# top right corner
return 16
elif (
left == False
and right == False
and top == False
and bottom == False
and bl_corner
):
# bottom left corner
return 17
elif (
left == False
and right == False
and top == False
and bottom == False
and br_corner
):
# bottom right corner
return 18
elif left == False and right == False and bottom and top == False and tl_corner:
# bottom and top left corner
return 19
elif left == False and right == False and bottom and top == False and tr_corner:
# bottom and top right corner
return 20
elif (
left == False
and right == False
and bottom
and top == False
and tl_corner
and tr_corner
):
# bottom and top left / right corners
return 21
elif (
left == False
and right == False
and bottom == False
and top
and bl_corner
and br_corner == False
and tl_corner
and tr_corner
):
# top and bottom left corner
return 22
elif (
left == False
and right == False
and bottom == False
and top
and bl_corner == False
and br_corner
and tl_corner
and tr_corner
):
# top and bottom right
return 23
elif (
left == False
and right == False
and bottom == False
and top
and bl_corner
and br_corner
and tl_corner
and tr_corner
):
# top and bottom left / right corners
return 24
elif left == False and right == False and top == False and bottom:
# bottom has a floor
return 1
elif left and right == False and top == False and bottom:
# bottom and left have floors
return 2
elif left and right and top == False and bottom:
# bottom left and right have floors
return 3
elif left == False and right and top == False and bottom:
# bottom and right have floors
return 4
elif left and right == False and top and bottom:
# bottom, top and left have floors
return 5
elif left == False and right and top and bottom:
# bottom, top and right have floors
return 6
elif left and right == False and bottom == False and top == False:
# left has a floor
return 7
elif left and right and top == False and bottom == False:
# left and right have floors
return 8
elif left == False and right and top == False and bottom == False:
# right has a floor
return 9
elif left == False and right == False and top and bottom == False:
# top has a floor
return 10
elif left == False and right == False and top and bottom:
# top and bottom have a floor
return 11
elif left and right == False and top and bottom == False:
# top and left have floors
return 12
elif left and right and top and bottom == False:
# top, left and right have floors
return 13
elif left == False and right and top and bottom == False:
# top and right have floors
return 14
elif (
left
and right
and top
and bottom
and bl_corner
and br_corner
and tl_corner
and tr_corner
):
# walled in
return 25
else:
# Catch all go for black for now
return 0
def make_cursor(arrow):
"""generate a cursor"""
hotspot = None
for y in range(len(arrow)):
for x in range(len(arrow[y])):
if arrow[y][x] in ["x", ",", "O"]:
hotspot = x, y
break
if hotspot != None:
break
if hotspot == None:
raise Exception("No hotspot specified for cursor!")
s2 = []
for line in arrow:
s2.append(line.replace("x", "X").replace(",", ".").replace("O", "o"))
cursor, mask = pygame.cursors.compile(s2, "X", ".", "o")
size = len(arrow[0]), len(arrow)
return size, hotspot, cursor, mask