Complete player and enemy movement.
This commit is contained in:
parent
d676ea01be
commit
248293aa65
4
Enemy.gd
4
Enemy.gd
@ -80,7 +80,7 @@ func _physics_process(delta):
|
||||
mv_delta = 0
|
||||
var state = get_parent().get_state()
|
||||
var player_pos = state.player_pos
|
||||
var path = pathfind(Vector2(1, 5))
|
||||
var path = pathfind(player_pos)
|
||||
if path == null:
|
||||
return
|
||||
var mv_target = path[-1]
|
||||
@ -92,4 +92,4 @@ func _physics_process(delta):
|
||||
func get_pos():
|
||||
var pos = self.global_position
|
||||
pos = Vector2(pos.x/50, pos.y/50)
|
||||
return pos
|
||||
return pos
|
||||
|
@ -17,10 +17,17 @@ func _physics_process(_delta):
|
||||
if Input.is_action_just_pressed(input):
|
||||
var offset = dir_offsets[input]
|
||||
var mv_target = get_pos() + offset
|
||||
var old_pos = get_pos()
|
||||
if state.get_type(mv_target) == "Empty":
|
||||
self.translate(offset * Vector2(speed, speed))
|
||||
var new_pos = get_pos()
|
||||
state.move(old_pos, new_pos)
|
||||
elif state.get_type(mv_target) == "Dirt" and not digging:
|
||||
self.translate(offset * Vector2(speed, speed))
|
||||
var new_pos = get_pos()
|
||||
state.move(old_pos, new_pos)
|
||||
elif state.get_type(mv_target) == "Dirt" and digging:
|
||||
state.set_pos(mv_target, "Empty")
|
||||
state.clear_tile(mv_target)
|
||||
state.player_pos = get_pos()
|
||||
|
||||
func get_pos():
|
||||
|
20
State.gd
20
State.gd
@ -21,6 +21,24 @@ func get_type(pos):
|
||||
print(level_map[pos.y][pos.x].type)
|
||||
return level_map[pos.y][pos.x].type
|
||||
|
||||
func clear_tile(pos):
|
||||
var old_instance = level_map[pos.y][pos.x]
|
||||
old_instance.queue_free()
|
||||
var new_instance = empty.instance()
|
||||
new_instance.global_position = Vector2(pos * Vector2(SPACE, SPACE))
|
||||
level_map[pos.y][pos.x] = new_instance
|
||||
|
||||
func move(pos1, pos2):
|
||||
var instance1 = level_map[pos1.y][pos1.x]
|
||||
var instance2 = level_map[pos2.y][pos2.x]
|
||||
instance2.queue_free()
|
||||
var new_instance = empty.instance()
|
||||
new_instance.global_position = Vector2(pos1 * Vector2(SPACE, SPACE))
|
||||
level_map[pos1.y][pos1.x] = new_instance
|
||||
level_map[pos2.y][pos2.x] = instance1
|
||||
|
||||
|
||||
|
||||
# We only expect having to set Empty and Rock types
|
||||
func set_pos(pos, type):
|
||||
if type == "Rock":
|
||||
@ -45,4 +63,4 @@ func set_pos(pos, type):
|
||||
set_pos(Vector2(pos.x, current_space), "Rock")
|
||||
else:
|
||||
current_space = y
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user