Files
Yamato/Source/MyProject3/SpaceShooterGameMode.h

102 lines
3.1 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "SpaceShooterGameMode.generated.h"
// Enum for different spawn patterns
UENUM(BlueprintType)
enum class ESpawnPattern : uint8
{
Random, // Randomly at screen edges
Wave, // Groups of enemies from one direction
Formation, // Specific formations (V-shape, line, etc.)
Flanking // Enemies from multiple sides simultaneously
};
// Struct to define a spawn point/zone
USTRUCT(BlueprintType)
struct FSpawnZone
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FVector Location;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float Radius = 100.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float SpawnWeight = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bActive = true;
};
UCLASS()
class MYPROJECT3_API ASpaceShooterGameMode : public AGameModeBase
{
GENERATED_BODY()
public:
ASpaceShooterGameMode();
virtual void StartPlay() override;
virtual void Tick(float DeltaTime) override;
protected:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
TSubclassOf<class AEnemySpaceship> EnemyClass;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float BaseEnemySpawnInterval = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
int32 MaxEnemies = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float ScreenSpawnMargin = 300.0f; // Increased from 100.0f
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float MinimumSpawnDistance = 4000.0f; // New property to ensure minimum spawn distance
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
TArray<FSpawnZone> SpawnZones;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
TArray<ESpawnPattern> SpawnPatterns;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
int32 WaveSize = 3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
float FormationSpacing = 150.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning|Difficulty")
float DifficultyScaling = 0.95f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning|Difficulty")
int32 DifficultyInterval = 30;
private:
FTimerHandle EnemySpawnTimer;
FTimerHandle DifficultyTimer;
float CurrentSpawnInterval;
ESpawnPattern CurrentPattern;
int32 CurrentWaveCount;
float GameTime;
void SpawnEnemy();
void SpawnEnemyWave();
void SpawnEnemyFormation();
void SpawnEnemyFlanking();
FVector GetScreenEdgeSpawnLocation();
FVector GetSpawnZoneLocation();
void UpdateDifficulty();
FVector GetPlayerLocation();
TArray<FVector2D> GetScreenBounds();
void RotateTowardsPlayer(AEnemySpaceship* Enemy, const FVector& PlayerLocation);
// New helper method to ensure minimum spawn distance
FVector EnsureMinimumSpawnDistance(const FVector& ProposedLocation, const FVector& PlayerLocation);
};