Merge branch 'master' of https://github.com/archfan7411/LD46
This commit is contained in:
commit
1a100ad208
9
Enemy.gd
9
Enemy.gd
@ -43,6 +43,8 @@ func make_dist_tree():
|
||||
dist += 1
|
||||
|
||||
func pathfind(player_pos):
|
||||
if get_pos() == player_pos:
|
||||
return null
|
||||
var dist_tree = make_dist_tree()
|
||||
if not player_pos in dist_tree:
|
||||
# The player cannot be reached.
|
||||
@ -80,13 +82,18 @@ func _physics_process(delta):
|
||||
mv_delta = 0
|
||||
var state = get_parent().get_state()
|
||||
var player_pos = state.player_pos
|
||||
var path = pathfind(player_pos)
|
||||
var goal_pos = state.goal_pos
|
||||
var target_pos = player_pos
|
||||
var path = pathfind(target_pos)
|
||||
if path == null:
|
||||
return
|
||||
var mv_target = path[-1]
|
||||
for offset in directions:
|
||||
if get_pos() + offset == mv_target:
|
||||
var old_pos = get_pos()
|
||||
self.translate(offset * Vector2(speed, speed))
|
||||
var new_pos = get_pos()
|
||||
state.move(old_pos, new_pos)
|
||||
break
|
||||
|
||||
func get_pos():
|
||||
|
2
State.gd
2
State.gd
@ -11,6 +11,7 @@ var enemy = null
|
||||
|
||||
var player_pos = Vector2()
|
||||
var enemy_pos = Vector2()
|
||||
var goal_pos = Vector2()
|
||||
|
||||
func _init(lvlmap, plr, enm):
|
||||
level_map = lvlmap
|
||||
@ -18,7 +19,6 @@ func _init(lvlmap, plr, enm):
|
||||
enemy = enm
|
||||
|
||||
func get_type(pos):
|
||||
print(level_map[pos.y][pos.x].type)
|
||||
return level_map[pos.y][pos.x].type
|
||||
|
||||
func clear_tile(pos):
|
||||
|
@ -10,5 +10,5 @@
|
||||
#.*...*..*# #
|
||||
#...*..*..# #
|
||||
#*...*..*.# #
|
||||
#.*..*...* #
|
||||
#.*..*.... #
|
||||
##############
|
Loading…
x
Reference in New Issue
Block a user