extends Sprite2D

@onready var anim:AnimationPlayer = $AnimationPlayer
@onready var audio_player:AudioStreamPlayer2D = $AudioStreamPlayer2D
@onready var stream:CollisionShape2D = $Area2D/CollisionShape2D

@export var geyser_speed:float = 30
@export var geyser_timer:float = 2
var velocity
@export var debug = false
@export var horizontal = false


func _ready() -> void:
	velocity = Vector2(0, -geyser_speed).rotated(get_rotation())
	anim.play('RESET')
	$Timer.wait_time = geyser_timer
	$Timer.start()


func _on_timer_timeout() -> void:
	stream.disabled = !stream.disabled
	anim.stop()
	if not stream.disabled: 
		anim.play('geyser')
		audio_player.play()
	else: anim.play('geyser_2')
	
	
func _on_area_2d_body_entered(body: Node2D) -> void:
	if body is not Player:
		body.velocity = velocity
		if not horizontal: body.destino = position


func _on_area_2d_body_exited(body: Node2D) -> void:
	if body is not Player: 
		body.velocity -= velocity
