MobSpawner.gd 612 B

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