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;
@@ -191,9 +199,18 @@ void ASpaceShooterGameMode::SpawnEnemyWave()
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;
@@ -284,9 +301,18 @@ 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;
@@ -337,6 +363,7 @@ void ASpaceShooterGameMode::SpawnEnemyFlanking()
// Return to random spawning
CurrentPattern = ESpawnPattern::Random;
}
}
FVector ASpaceShooterGameMode::GetScreenEdgeSpawnLocation()
{