extends Area2D

@export var speed = 70
@export var damage = 1
@export var knockback_strength = 0.5


func _physics_process(delta):
	var direction = Vector2.RIGHT.rotated(self.rotation)     
	self.position += direction * speed * delta

func _on_area_entered(area: Area2D) -> void:
	if self.get_parent().is_in_group("Virus"):
		# Prevent friendly fire
		return
	var area_parent = area.get_parent()
	if (area_parent.is_in_group("Virus")):
		area_parent.take_hit(damage, self.position.direction_to(area.position) * 50, knockback_strength)
		self.queue_free()

func _on_body_entered(body):
	if self.get_parent() == body:
		return
	body.take_hit(damage, self.position.direction_to(body.position) * 50, knockback_strength)
	self.queue_free()

func _on_timer_timeout() -> void:
	self.queue_free()
