63 lines
1.4 KiB
GDScript
63 lines
1.4 KiB
GDScript
extends Path3D
|
|
class_name WaveManager
|
|
|
|
@export var level : Level
|
|
var current_wave : Wave
|
|
var current_troop : Troop
|
|
|
|
var enemies_to_spawn : int = 0
|
|
var wave_on_going : bool = false
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
if GameManager.wave > 0 || level.auto_start:
|
|
spawn_manager()
|
|
|
|
|
|
func spawn_next_wave() -> void:
|
|
if level.waves.is_empty():
|
|
EventBus.player_has_won.emit()
|
|
return
|
|
|
|
current_wave = level.waves.pop_front()
|
|
GameManager.wave += 1
|
|
$WaveTimer.start(current_wave.wait_time_before_launch_wave)
|
|
|
|
|
|
func spawn_troop() -> void:
|
|
for n in current_troop.number_to_spawn:
|
|
var tempEnemy = current_troop.enemy.instantiate()
|
|
add_child(tempEnemy)
|
|
GameManager.enemies_alive += 1
|
|
|
|
|
|
func spawn_manager() -> void:
|
|
#Send next troop
|
|
if !$WaveTimer.is_stopped() || !$TroopTimer.is_stopped():
|
|
return
|
|
|
|
if !current_wave:
|
|
spawn_next_wave()
|
|
return
|
|
|
|
if !current_wave.troops.is_empty():
|
|
current_troop = current_wave.troops.pop_front()
|
|
if (current_troop.spawn_delay == 0):
|
|
spawn_troop()
|
|
else:
|
|
$TroopTimer.wait_time = current_troop.spawn_delay
|
|
$TroopTimer.start()
|
|
|
|
wave_on_going = true
|
|
if GameManager.enemies_alive == 0 && current_wave.troops.is_empty():
|
|
wave_on_going = false
|
|
spawn_next_wave()
|
|
elif !current_wave.wait_for_enemy_kills:
|
|
spawn_next_wave()
|
|
|
|
|
|
func _on_wave_timer_timeout() -> void:
|
|
pass
|
|
|
|
func _on_troop_timer_timeout() -> void:
|
|
spawn_troop()
|