extends Node var tile_set = preload("res://tile_set1.tres") as FR_TileSet var tiles: Array[Tile] var tile_index: int = 0 var run_started = false var tile_parent: Node var character: Character var current_tile: Tile: get = get_current_tile func _ready(): pass func _process(delta): if not run_started: return if tiles.size() == 0: return if tiles.size() < 15: add_tile() if is_equal_approx(current_tile.follow.progress_ratio, 1) and has_next_tile(): if current_tile.has_next_path(): return tile_index += 1 character.tile = current_tile func start_run(tile_parent: Node) -> void: self.tile_parent = tile_parent character = Utils.get_first_node_of_type(get_tree().root, Character) get_current_tiles() if tiles.size() == 0: var tile = generate_tile() tiles.append(tile) tile_parent.add_child(tile) character.tile = current_tile run_started = true func get_current_tiles() -> void: tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile)) func generate_tile() -> Tile: var index = randi_range(0, tile_set.strait_tiles.size()-1) var tile_scene: PackedScene = tile_set.strait_tiles[index] var tile = tile_scene.instantiate() return tile func add_tile() -> void: var last_tile = tiles[tiles.size()-1] var tile = generate_tile() tiles.append(tile) tile_parent.add_child(tile) tile.global_position = last_tile.spawn_point.global_position tile.global_rotation = last_tile.spawn_point.global_rotation func has_next_tile() -> bool: return tile_index + 1 < tiles.size() func get_current_tile() -> Tile: return tiles[tile_index]