class_name MobSpawner extends Path2D # Responsible of enemy life-cycle signal reset export (Array, PackedScene) var mob_list var _mob_storage: Array var _running_mob: Array func _ready(): assert(!mob_list.empty()) 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_SpawnTimer_timeout(): spawn() $SpawnTimer.start() func _on_NewMobTimer_timeout(): _add_mob() if _has_remaining_mob_in_storage(): $NewMobTimer.start() func _on_HUD_start_game(): _reset() func _on_Main_game_started(): _add_mob() $SpawnTimer.start() $NewMobTimer.start() func _on_Main_game_over(): $SpawnTimer.stop() $NewMobTimer.stop() func _pick_a_mob() -> PackedScene: assert(!_running_mob.empty()) _running_mob.shuffle() return _running_mob.front() func _add_mob(): assert(!_mob_storage.empty()) _running_mob.append(_mob_storage.pop_front()) func _has_remaining_mob_in_storage() -> bool: return !_mob_storage.empty() func _reset(): _mob_storage = mob_list.duplicate() _running_mob.clear() emit_signal("reset")