class_name Moorhuhn
extends Area2D

signal killed

@export
var explosion: PackedScene

var direction := Vector2.ONE

var speed := 10

func _ready() -> void:
	var angle := randi_range(0, 360)
	direction = direction.rotated(deg_to_rad(angle))

	speed += randi_range(5, 10)


func _process(delta: float) -> void:
	position += direction * speed * delta


func _on_input_event(viewport: Node, event: InputEvent, shape_idx: int) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.is_released():
			var expl_inst = explosion.instantiate()
			expl_inst.position = position
			get_parent().add_child(expl_inst)

			killed.emit()

			queue_free()
