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.
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "WaveSubsystem.h"
|
|
|
|
|
|
|
|
void UWaveSubsystem::Init(const TArray<UWave*> InWaves, const int32 CurrWave = 0)
|
|
|
|
{
|
|
|
|
CurrentWave = CurrWave;
|
|
|
|
Waves = InWaves;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHorizontalOffset, const 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;
|
|
|
|
}
|