extends Line2D
class_name Trail

@export var player: Player
@export var trail_length := 25
@export var trail_duration := 1.0

@onready var trail_timer: Timer = %TrailTimer

var pointers_array: Array[Vector2] = []
var is_active := false

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if not is_active:
		return
		
	pointers_array.append(player.global_position)
	if pointers_array.size() > trail_length:
		pointers_array.pop_front()
	
	points = pointers_array

func start_trail() -> void:
	is_active = true
	clear_points()
	pointers_array.clear()
	trail_timer.start(trail_duration)


func _on_trail_timer_timeout() -> void:
	is_active = false
	clear_points()
	pointers_array.clear()
	
