You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
12 months ago
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||
|
|
||
|
|
||
|
#include "WaveSubsystem.h"
|
||
|
|
||
|
void UWaveSubsystem::Init(TArray<UWave*> InWaves, int32 CurrWave = 0)
|
||
|
{
|
||
|
CurrentWave = CurrWave;
|
||
|
Waves = InWaves;
|
||
|
}
|
||
|
|
||
|
int32 UWaveSubsystem::SpawnWave(float InVerticalSpacing, float InHorizontalOffset, int InNumRows)
|
||
|
{
|
||
|
NumRows = InNumRows;
|
||
|
HorizontalOffset = InHorizontalOffset;
|
||
|
VerticalSpacing = InVerticalSpacing;
|
||
|
SpawnQueue = Waves[CurrentWave]->GetUnits();
|
||
|
const auto NumUnits = SpawnQueue.Num();
|
||
|
|
||
|
SpawnUnits();
|
||
|
GetWorld()->GetTimerManager().SetTimer(
|
||
|
SpawnTimerHandle,
|
||
|
this,
|
||
|
&UWaveSubsystem::SpawnUnits,
|
||
|
0.5f,
|
||
|
true);
|
||
|
|
||
|
CurrentWave++;
|
||
|
return NumUnits;
|
||
|
}
|
||
|
|
||
|
void UWaveSubsystem::SpawnUnits()
|
||
|
{
|
||
|
for(auto i = 0; i < NumRows; i++)
|
||
|
{
|
||
|
if(i + LastSpawnIndex >= SpawnQueue.Num())
|
||
|
{
|
||
|
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, HorizontalOffset, 0);
|
||
|
AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location);
|
||
|
if(NewEnemy != nullptr)
|
||
|
{
|
||
|
NewEnemy->Tags.Add(TEXT("enemy"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
LastSpawnIndex += NumRows;
|
||
|
}
|