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() 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(); UWorld* World = GetWorld();
if (!World || !EnemyClass) if (!World || !EnemyClass)
return; return;
@@ -191,9 +199,18 @@ void ASpaceShooterGameMode::SpawnEnemyWave()
CurrentWaveCount = 0; CurrentWaveCount = 0;
} }
} }
}
void ASpaceShooterGameMode::SpawnEnemyFormation() 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(); UWorld* World = GetWorld();
if (!World || !EnemyClass) if (!World || !EnemyClass)
return; return;
@@ -284,9 +301,18 @@ void ASpaceShooterGameMode::SpawnEnemyFormation()
// Switch back to random pattern after a formation spawn // Switch back to random pattern after a formation spawn
CurrentPattern = ESpawnPattern::Random; CurrentPattern = ESpawnPattern::Random;
} }
}
void ASpaceShooterGameMode::SpawnEnemyFlanking() 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(); UWorld* World = GetWorld();
if (!World || !EnemyClass) if (!World || !EnemyClass)
return; return;
@@ -337,6 +363,7 @@ void ASpaceShooterGameMode::SpawnEnemyFlanking()
// Return to random spawning // Return to random spawning
CurrentPattern = ESpawnPattern::Random; CurrentPattern = ESpawnPattern::Random;
} }
}
FVector ASpaceShooterGameMode::GetScreenEdgeSpawnLocation() FVector ASpaceShooterGameMode::GetScreenEdgeSpawnLocation()
{ {