Files
Yamato/Source/MyProject3/SpaceShooterGameMode.h

123 lines
3.7 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;
void IncrementKillCount();
void RestartGame();
int32 GetKillCount() const { return KillCount; }
float GetRemainingTime() const { return RemainingTime; }
float GetGameDuration() const { return GameDuration; }
bool IsGameOver() const { return bIsGameOver; }
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;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Game Rules")
float GameDuration = 30.0f; // 3 minutes default
UPROPERTY(BlueprintReadOnly, Category = "Game Stats")
int32 KillCount;
UPROPERTY(BlueprintReadOnly, Category = "Game Stats")
float RemainingTime;
UPROPERTY(BlueprintReadOnly, Category = "Game State")
bool bIsGameOver;
private:
FTimerHandle EnemySpawnTimer;
FTimerHandle DifficultyTimer;
float CurrentSpawnInterval;
ESpawnPattern CurrentPattern;
int32 CurrentWaveCount;
float GameTime;
void SpawnEnemy();
void SpawnEnemyWave();
void SpawnEnemyFormation();
void SpawnEnemyFlanking();
FVector GetRandomSpawnLocation();
void UpdateDifficulty();
FVector GetPlayerLocation();
void RotateTowardsPlayer(AEnemySpaceship* Enemy, const FVector& PlayerLocation);
// New helper method to ensure minimum spawn distance
FVector EnsureMinimumSpawnDistance(const FVector& ProposedLocation, const FVector& PlayerLocation);
void EndGame();
void UpdateGameTimer();
FTimerHandle GameTimerHandle;
};