extends Actor
class_name Enemy

func _on_StompDetector_body_entered(body: Node) -> void:
	if !body.is_in_group("player"):
		return
	var incoming_vel_vector: Vector2 = body.velocity.normalized()
	print(rad2deg(abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation)))))
	if abs(incoming_vel_vector.angle_to(Vector2.DOWN.rotated(rotation))) > deg2rad(40):
		print("too shallow entry")
		return
	signalManager.emit_signal("got_stomped")
	remove_from_group("harmful")
	$StompDetector.remove_from_group("weakpoint")
	get_node("EnemyBody").disabled = true
	die()

func die() -> void:
	queue_free()
	# TODO make batterr
	levelState.kills += 1

func _on_EnemySkin_area_entered(area:Area2D) -> void:
	if area.is_in_group("harmful"):
		get_node("EnemyBody").disabled = true
		die()
