class_name MobSpawner
extends Path2D
# Responsible of enemy life-cycle


signal reset

export (Array, PackedScene) var mobs


func spawn():
	$MobSpawnLocation.set_offset(randi())
	var newRotation = $MobSpawnLocation.rotation + rand_range(PI / 4, 3 * PI / 4)

	var Mob = _pick_a_mob()
	var newMob = Mob.instance()
	newMob.attack($MobSpawnLocation.position, newRotation)

	connect("reset", newMob, "_on_Spawner_reset")

	add_child(newMob)


func _on_MobTimer_timeout():
	spawn()
	$MobTimer.start()


func _on_HUD_start_game():
	emit_signal("reset")


func _on_Main_game_started():
	$MobTimer.start()


func _on_Main_game_over():
	$MobTimer.stop()


func _pick_a_mob() -> PackedScene:
	mobs.shuffle()
	return mobs.front()
