-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal_variables.py
49 lines (38 loc) · 1.19 KB
/
global_variables.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 math
"""
This file contains global variables and methods.
"""
TICKS_PER_TURN = 26771144400 # LCM(1:26)
def distance_to(location, target, manhattan=True):
xl, yl = location
xt, yt = target
if manhattan:
distance = abs(xl - xt) + abs(yl - yt)
else:
distance = math.sqrt( (xl - xt)*(xl - xt) + (yl - yt)*(yl - yt) )
return distance
def fill_in_line(line):
new_line = []
new_line.append(line.pop(0))
while(len(line)):
x1, y1 = new_line[-1]
x2, y2 = line[0]
if (x1 - x2)*(y1 - y2) == 0:
# These points are good.
new_line.append(line.pop(0))
else:
# These points are diagonal. Insert a new point, with a new x value but the same y value.
dx = x2 - x1
new_point = (x1 + dx, y1)
new_line.append(new_point)
# Remove the tile where the line starts.
if new_line:
new_line.pop(0)
return new_line
def get_blocking_entity(entities, location):
x, y = location
for entity in entities:
if entity.location and entity.location.x == x and entity.location.y == y:
return entity
else:
return None