MobSpawner.gd 739 B

123456789101112131415161718192021222324252627282930313233343536373839
  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.rotation = newRotation
  11. newMob.position = $MobSpawnLocation.position
  12. newMob.linear_velocity = Vector2(rand_range(newMob.min_speed, newMob.max_speed), 0).rotated(newRotation)
  13. connect("reset", newMob, "_on_Spawner_reset")
  14. add_child(newMob)
  15. func _on_MobTimer_timeout():
  16. spawn()
  17. $MobTimer.start()
  18. func _on_HUD_start_game():
  19. emit_signal("reset")
  20. func _on_Main_game_started():
  21. $MobTimer.start()
  22. func _on_Main_game_over():
  23. $MobTimer.stop()