forked from itsapi/pycraft
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpathfinding.py
More file actions
36 lines (25 loc) · 725 Bytes
/
pathfinding.py
File metadata and controls
36 lines (25 loc) · 725 Bytes
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
import mobs, terrain, player
def pathfind_towards_delta(entity, delta, map_):
updated = False
kill_entity = False
ex = entity['x']
ey = entity['y']
x_vel = entity['x_vel']
x_vel += delta / 100
if abs(x_vel) > 1:
x_vel = x_vel / abs(x_vel)
dx = round(x_vel)
if (ex + dx - 1 not in map_.keys() or
ex + dx not in map_.keys() or
ex + dx + 1 not in map_.keys()):
kill_entity = True
else:
dx, dy = player.get_pos_delta(dx, ex, ey, map_)
ex, ey = ex + dx, ey + dy
if not terrain.is_solid(map_[ex][ey + 1]):
ey += 1
entity['x'] = ex
entity['y'] = ey
entity['x_vel'] = x_vel
updated = True
return updated, kill_entity