class_name Hitbox extends Area2D
signal collided;

var from_player = true
var enabled = true

func _ready() -> void:
	collision_mask = 0xffff
	body_entered.connect(_on_body_entered)
	area_entered.connect(_on_area_entered)

func _on_area_entered(area : Area2D):
	if area is Hitbox:
		if area.from_player != from_player:
			collided.emit()

func _on_body_entered(body: Node) -> void:
	print(body)
	if not enabled: return
	if body is Enemy and from_player:
		body.damage()
		collided.emit()
		body.knockback()

	if body is Player and not from_player:
		body.damage()
		collided.emit()
	
	if body is StaticBody2D or body is Hitbox:
		collided.emit()
