FantasyRun/Tiles/tile_turn.gd
Matthew Welch c1bb198be6 Start work on tile generator autoload
update tile positioning to work with the spawn points
2024-10-05 14:09:45 -07:00

53 lines
1.2 KiB
GDScript

extends Tile
class_name TileTurn
@onready var area_3d = $Area3D as Area3D
@onready var path_forward = $PathForward as TilePath
@onready var path_right = $PathRight as TilePath
@onready var path_left = $PathLeft as TilePath
var connected = false
var current_direction = "forward"
var character: Character
var on_main_path: bool:
get:
return path_index == 0
func _ready():
paths.append($MainPath)
paths.append($PathForward)
func _process(delta):
var character_found = false
for area in area_3d.get_overlapping_areas():
if area is Character:
character_found = true
if connected:
break
character = area as Character
character.turn.connect(turn)
connected = true
if not character_found and connected:
character.turn.disconnect(turn)
connected = false
super(delta)
func turn(direction):
if on_main_path:
current_direction = direction
paths[path_index+1] = get_path_by_direction(current_direction)
func get_path_by_direction(direction) -> TilePath:
if direction == "forward" and path_forward != null:
return path_forward
elif direction == "right" and path_right != null:
return path_right
elif direction == "left" and path_left != null:
return path_left
return null