-
Notifications
You must be signed in to change notification settings - Fork 0
/
movement.py
48 lines (41 loc) · 851 Bytes
/
movement.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
def move_to(x, y):
# quick_print('Moving to', x, y)
while get_pos_x() != x or get_pos_y() != y:
move_towards(x, y)
def get_move_dir_x(x):
diff = x - get_pos_x() # -6
alt = get_pos_x() - x - get_world_size() # 6
if (diff < 0):
if abs(alt) < abs(diff):
return East
else:
return West
if (diff > 0):
if abs(alt) < abs(diff):
return West
else:
return East
return None
def get_move_dir_y(y):
diff = y - get_pos_y() # -6
alt = get_pos_y() - y - get_world_size() # 6
if (diff < 0):
if abs(alt) < abs(diff):
return North
else:
return South
if (diff > 0):
if abs(alt) < abs(diff):
return South
else:
return North
return None
def distance_to_y(y):
return abs(get_pos_y() - y)
def move_towards(x, y):
h = get_move_dir_x(x)
v = get_move_dir_y(y)
if h != None:
move(h)
if v != None:
move(v)