Implement basic combat system
This commit is contained in:
@@ -12,6 +12,13 @@ ASpaceShooterGameMode::ASpaceShooterGameMode()
|
||||
DefaultPawnClass = PlayerPawnBPClass.Class;
|
||||
}
|
||||
|
||||
// Find enemy blueprint class
|
||||
static ConstructorHelpers::FClassFinder<AEnemySpaceship> EnemyBPClass(TEXT("/Game/Blueprints/BP_EnemySpaceship"));
|
||||
if (EnemyBPClass.Class != nullptr)
|
||||
{
|
||||
EnemyClass = EnemyBPClass.Class;
|
||||
}
|
||||
|
||||
// Enable Tick()
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
@@ -52,14 +59,15 @@ void ASpaceShooterGameMode::SpawnEnemy()
|
||||
if (FoundEnemies.Num() < MaxEnemies)
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
if (World)
|
||||
if (World && EnemyClass)
|
||||
{
|
||||
FVector SpawnLocation = GetRandomSpawnLocation();
|
||||
FRotator SpawnRotation = FRotator::ZeroRotator;
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
||||
|
||||
World->SpawnActor<AEnemySpaceship>(AEnemySpaceship::StaticClass(), SpawnLocation,
|
||||
// Spawn using the Blueprint class instead of the C++ class directly
|
||||
AEnemySpaceship* NewEnemy = World->SpawnActor<AEnemySpaceship>(EnemyClass, SpawnLocation,
|
||||
SpawnRotation, SpawnParams);
|
||||
}
|
||||
}
|
||||
@@ -75,10 +83,13 @@ FVector ASpaceShooterGameMode::GetRandomSpawnLocation()
|
||||
// Generate random angle
|
||||
float Angle = FMath::RandRange(0.0f, 2.0f * PI);
|
||||
|
||||
// Generate random radius between min and max
|
||||
float Radius = FMath::RandRange(MinSpawnRadius, MaxSpawnRadius);
|
||||
|
||||
// Calculate spawn position in a circle around the player
|
||||
FVector SpawnLocation;
|
||||
SpawnLocation.X = PlayerLocation.X + SpawnRadius * FMath::Cos(Angle);
|
||||
SpawnLocation.Y = PlayerLocation.Y + SpawnRadius * FMath::Sin(Angle);
|
||||
SpawnLocation.X = PlayerLocation.X + Radius * FMath::Cos(Angle);
|
||||
SpawnLocation.Y = PlayerLocation.Y + Radius * FMath::Sin(Angle);
|
||||
SpawnLocation.Z = PlayerLocation.Z;
|
||||
|
||||
return SpawnLocation;
|
||||
|
||||
Reference in New Issue
Block a user