MobSpawner.gd 719 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. class_name MobSpawner
  2. extends Path2D
  3. # Responsible of enemy life-cycle
  4. signal reset
  5. export (Array, PackedScene) var mobs
  6. func spawn():
  7. $MobSpawnLocation.set_offset(randi())
  8. var newRotation = $MobSpawnLocation.rotation + rand_range(PI / 4, 3 * PI / 4)
  9. var Mob = _pick_a_mob()
  10. var newMob = Mob.instance()
  11. newMob.attack($MobSpawnLocation.position, newRotation)
  12. connect("reset", newMob, "_on_Spawner_reset")
  13. add_child(newMob)
  14. func _on_MobTimer_timeout():
  15. spawn()
  16. $MobTimer.start()
  17. func _on_HUD_start_game():
  18. emit_signal("reset")
  19. func _on_Main_game_started():
  20. $MobTimer.start()
  21. func _on_Main_game_over():
  22. $MobTimer.stop()
  23. func _pick_a_mob() -> PackedScene:
  24. mobs.shuffle()
  25. return mobs.front()