Make sure max enemies applies properly

This commit is contained in:
2025-04-16 08:50:06 +05:30
parent 67ac9d1935
commit c292da805d

View File

@@ -138,6 +138,14 @@ void ASpaceShooterGameMode::SpawnEnemy()
void ASpaceShooterGameMode::SpawnEnemyWave()
{
// Count current enemies
TArray<AActor*> FoundEnemies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AEnemySpaceship::StaticClass(), FoundEnemies);
// Only spawn if we haven't reached the maximum
if (FoundEnemies.Num() < MaxEnemies)
{
UWorld* World = GetWorld();
if (!World || !EnemyClass)
return;
@@ -190,10 +198,19 @@ void ASpaceShooterGameMode::SpawnEnemyWave()
CurrentPattern = ESpawnPattern::Random;
CurrentWaveCount = 0;
}
}
}
void ASpaceShooterGameMode::SpawnEnemyFormation()
{
// Count current enemies
TArray<AActor*> FoundEnemies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AEnemySpaceship::StaticClass(), FoundEnemies);
// Only spawn if we haven't reached the maximum
if (FoundEnemies.Num() < MaxEnemies)
{
UWorld* World = GetWorld();
if (!World || !EnemyClass)
return;
@@ -283,10 +300,19 @@ void ASpaceShooterGameMode::SpawnEnemyFormation()
// Switch back to random pattern after a formation spawn
CurrentPattern = ESpawnPattern::Random;
}
}
void ASpaceShooterGameMode::SpawnEnemyFlanking()
{
// Count current enemies
TArray<AActor*> FoundEnemies;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AEnemySpaceship::StaticClass(), FoundEnemies);
// Only spawn if we haven't reached the maximum
if (FoundEnemies.Num() < MaxEnemies)
{
UWorld* World = GetWorld();
if (!World || !EnemyClass)
return;
@@ -336,6 +362,7 @@ void ASpaceShooterGameMode::SpawnEnemyFlanking()
// Return to random spawning
CurrentPattern = ESpawnPattern::Random;
}
}
FVector ASpaceShooterGameMode::GetScreenEdgeSpawnLocation()