FantasyRun/Tiles/Tile.gd

67 lines
1.4 KiB
GDScript

extends Node3D
class_name Tile
signal left_screen(tile: Tile)
@onready var spawn_point: Marker3D = $SpawnPoint as Marker3D
var paths: Array[TilePath]
var path_index: int = 0
var on_screen_notifier: VisibleOnScreenNotifier3D
var path: TilePath:
get = get_current_path
var follow: PathFollow3D:
get:
return path.follow
var progress_marker: Marker3D:
get:
return path.marker
var marker_position: Vector3:
get:
return progress_marker.global_position
var marker_rotation: Vector3:
get:
return progress_marker.global_rotation
func _ready() -> void:
on_screen_notifier = Utils.get_first_node_of_type(self, VisibleOnScreenNotifier3D) as VisibleOnScreenNotifier3D
on_screen_notifier.screen_exited.connect(_on_screen_exited)
load_path()
func _process(delta: float) -> void:
if has_next_path():
paths[path_index+1].follow.v_offset = path.follow.v_offset
if is_equal_approx(follow.progress_ratio, 1) and has_next_path():
get_next_path().receive_marker(progress_marker)
path_index += 1
func load_path() -> void:
paths.append($MainPath)
func get_current_path() -> TilePath:
return paths[path_index]
func has_next_path() -> bool:
return path_index + 1 < paths.size()
func get_next_path() -> TilePath:
if has_next_path():
return paths[path_index+1]
return null
func _on_screen_exited():
if is_equal_approx(follow.progress_ratio, 1) and not has_next_path():
left_screen.emit(self)