FantasyRun/world.gd

38 lines
782 B
GDScript

extends Node3D
@onready var character = $Character as Character
var change_distance: float
var tiles: Array[Tile]
var tile_index: int = 0
var current_tile: Tile:
get = get_current_tile
func _ready() -> void:
tiles.assign(Utils.get_nodes_of_class(self, Tile))
if tiles.size() == 0:
printerr("There are no Tiles in the scene.")
return
if character.tile == null:
character.tile = current_tile
func _process(delta: float) -> void:
if tiles.size() == 0:
return
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 has_next_tile() -> bool:
return tile_index + 1 < tiles.size()
func get_current_tile() -> Tile:
return tiles[tile_index]