extends Node3D

@onready var bubble_shadow: AnimatedSprite3D = $BubbleShadow
@onready var bubble: AnimatedSprite3D = $Bubble
@onready var shine: AnimatedSprite3D = $Shine
@onready var explode: AnimatedSprite3D = $Explode

@onready var active: bool = true
@export var respawn_time: float = 10.0

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

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
	pass


func pickup():
	if active == true:
		active = false
		GameVariables.bubble_pickup.emit()
		pickup()
		bubble_shadow.visible = false
		bubble.visible = false
		shine.visible = false
		explode.visible = true
		explode.play("")
		await get_tree().create_timer(respawn_time).timeout
		respawn()


func respawn():
	active = true
	bubble_shadow.visible = true
	bubble.visible = true
	shine.visible = true
	explode.visible = false



func _on_collision_area_entered(area: Area3D) -> void:
	if area.has_method("bubbly"):
		pickup()
