diff options
Diffstat (limited to 'Scenes/Dungeon.gd')
-rw-r--r-- | Scenes/Dungeon.gd | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd index d8aeb36..d20fcc4 100644 --- a/Scenes/Dungeon.gd +++ b/Scenes/Dungeon.gd @@ -22,6 +22,7 @@ func build_floor(): var rand_pos = Vector2(-5, 0) tiles_entities[rand_pos] = player + player.target_position = Vector3() for i in range(4): rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3) @@ -31,6 +32,8 @@ func build_floor(): for key in tiles_entities: tiles_entities[key].translation = tile_to_pos(key) + if tiles_entities[key].get("target_position") != null: + tiles_entities[key].target_position = tile_to_pos(key) func tile_to_pos(tile : Vector2): return Vector3(tile.x, 0, -tile.y) @@ -38,6 +41,14 @@ func tile_to_pos(tile : Vector2): func pos_to_tile(pos: Vector3): return Vector2(round(pos.x), round(-pos.z)) +func _process(delta): + for tile in tiles_entities.keys(): + if tiles_entities[tile].get("target_position") != null: + var entity = tiles_entities[tile] + var new_pos = entity.target_position + var cur_pos = entity.translation + entity.translation = lerp(cur_pos, new_pos, delta * 8) + func _input(event): if event is InputEventKey and event.is_pressed() and not event.is_echo(): if event.scancode == KEY_UP: @@ -50,12 +61,16 @@ func _input(event): move_player(Vector2(-1,0)) func move_player(dir: Vector2): - var curr_tile = pos_to_tile(player.translation) + var curr_tile = pos_to_tile(player.target_position) var new_tile = curr_tile + dir + print(new_tile) + if tiles_entities.has(new_tile): return tiles_entities.erase(curr_tile) tiles_entities[new_tile] = player - player.translation = tile_to_pos(new_tile) + + player.target_position = tile_to_pos(new_tile) + player.get_node("Mesh").roll(dir) |