2024-10-01 19:45:11 -07:00
|
|
|
extends Tile
|
|
|
|
class_name TileTurn
|
|
|
|
|
|
|
|
@onready var area_3d = $Area3D as Area3D
|
2024-10-05 14:09:45 -07:00
|
|
|
@onready var path_forward = $PathForward as TilePath
|
|
|
|
@onready var path_right = $PathRight as TilePath
|
|
|
|
@onready var path_left = $PathLeft as TilePath
|
2024-10-04 10:01:33 -07:00
|
|
|
|
2024-10-01 19:45:11 -07:00
|
|
|
var connected = false
|
|
|
|
var current_direction = "forward"
|
2024-10-05 14:09:45 -07:00
|
|
|
var character: Character
|
|
|
|
|
|
|
|
var on_main_path: bool:
|
|
|
|
get:
|
|
|
|
return path_index == 0
|
2024-10-01 19:45:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2024-10-04 10:01:33 -07:00
|
|
|
paths.append($MainPath)
|
|
|
|
paths.append($PathForward)
|
2024-10-01 19:45:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
func _process(delta):
|
2024-10-05 14:09:45 -07:00
|
|
|
var character_found = false
|
2024-10-01 19:45:11 -07:00
|
|
|
for area in area_3d.get_overlapping_areas():
|
2024-10-05 14:09:45 -07:00
|
|
|
if area is Character:
|
|
|
|
character_found = true
|
|
|
|
if connected:
|
|
|
|
break
|
|
|
|
character = area as Character
|
2024-10-01 19:45:11 -07:00
|
|
|
character.turn.connect(turn)
|
|
|
|
connected = true
|
2024-10-05 14:09:45 -07:00
|
|
|
if not character_found and connected:
|
|
|
|
character.turn.disconnect(turn)
|
|
|
|
connected = false
|
2024-10-04 10:01:33 -07:00
|
|
|
super(delta)
|
2024-10-01 19:45:11 -07:00
|
|
|
|
|
|
|
|
|
|
|
func turn(direction):
|
2024-10-04 10:01:33 -07:00
|
|
|
if on_main_path:
|
|
|
|
current_direction = direction
|
|
|
|
paths[path_index+1] = get_path_by_direction(current_direction)
|
2024-10-01 19:45:11 -07:00
|
|
|
|
|
|
|
|
2024-10-05 14:09:45 -07:00
|
|
|
func get_path_by_direction(direction) -> TilePath:
|
2024-10-01 19:45:11 -07:00
|
|
|
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
|