class_name Obstacle extends CharacterBody2D

@onready var sprite = $Sprite2D
@onready var lifeTimeTimer = $lifeTimeTimer
@onready var damageArea = $DamageArea
@onready var hit = $hit

@export var damage: int = 100
@export var minHealth: int = 1
@export var maxHealth: int = 100
@export var health: int
@export var lifeTime: int = 600

func _ready() -> void:
	health = maxHealth + damage + 1
	lifeTimeTimer.start(lifeTime)

func spawn(damage: int):
	pass


func _on_hurt_area_hurt(amount: int) -> void:
	hit.play()
	hurt(amount)

func hurt(amount: int):
	if health - amount <= minHealth:
		queue_free()
	else:
		health -= amount


func _on_life_time_timer_timeout() -> void:
	queue_free()


func _on_damage_area_area_entered(area: Area2D) -> void:
	damageArea.damageHurtArea(area, damage)
