extends Node var tile_set: FR_TileSet = preload("res://tile_set1.tres") as FR_TileSet var tiles: Array[Tile] var tile_index: int = 0 var run_started: bool = false var tile_parent: Node var character: Character var min_turn: int = 3 var max_turn: int = 10 var turn_counter: int = randi_range(min_turn, max_turn) var current_tile: Tile: get = get_current_tile func _ready() -> void: pass func _process(delta: float) -> void: 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) as Character get_current_tiles() if tiles.size() == 0: add_first_tile() character.tile = current_tile run_started = true func get_current_tiles() -> void: tiles.assign(Utils.get_nodes_of_class(get_tree().root, Tile)) for tile in tiles: tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT) func generate_tile(tiles: Array[PackedScene]) -> Tile: var index = randi_range(0, tiles.size()-1) var tile_scene: PackedScene = tiles[index] var tile: Tile = tile_scene.instantiate() as Tile tile.left_screen.connect(tile_left_screen, CONNECT_ONE_SHOT) return tile func add_first_tile() -> void: var tile: Tile = generate_tile(tile_set.strait_tiles) tiles.append(tile) tile_parent.add_child(tile) tile.global_position = Vector3.ZERO tile.global_rotation = Vector3.ZERO func add_tile() -> void: var last_tile: Tile = tiles[tiles.size()-1] var tile: Tile if turn_counter <= 0: tile = generate_tile(tile_set.turn_tiles) turn_counter = randi_range(min_turn, max_turn) else: tile = generate_tile(tile_set.strait_tiles) turn_counter -= 1 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] func tile_left_screen(tile: Tile): var index: int = tiles.find(tile) tiles.remove_at(index) if index < tile_index: tile_index -= 1 await get_tree().create_timer(1.0).timeout tile.queue_free()