Files
Yamato/Source/MyProject3/EnemySpaceship.h

113 lines
3.2 KiB
C++

#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnemySpaceship.generated.h"
// Define AI behavior states
UENUM(BlueprintType)
enum class EEnemyBehaviorState : uint8
{
Chase, // Actively pursue the player
Attack, // Stop and shoot at the player
Retreat, // Move away from player when too close
Strafe // Move sideways while attacking
};
UCLASS()
class MYPROJECT3_API AEnemySpaceship : public AActor
{
GENERATED_BODY()
public:
AEnemySpaceship();
protected:
virtual void BeginPlay() override;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
UStaticMeshComponent* EnemyMesh;
// Projectile spawn points
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
USceneComponent* ProjectileSpawnPoint;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MovementSpeed = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float AttackRange = 1500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float MinDistanceToPlayer = 500.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
float StrafeSpeed = 300.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float MaxHealth = 100.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float CurrentHealth = 100.0f;
// Projectile class to spawn
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
TSubclassOf<class AEnemyProjectile> ProjectileClass;
// Firing properties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float FireRate = 1.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float ProjectileSpeed = 2000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
float ProjectileDamage = 10.0f;
// AI behavior properties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
EEnemyBehaviorState CurrentBehaviorState = EEnemyBehaviorState::Chase;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float BehaviorChangeTime = 3.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
float StateChangeChance = 0.3f;
public:
virtual void Tick(float DeltaTime) override;
// Override TakeDamage to handle damage taken
virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent,
class AController* EventInstigator, AActor* DamageCauser) override;
private:
// Reference to player
class ASpaceshipPawn* PlayerPawn;
// Distance to player
float DistanceToPlayer;
// Fire control
FTimerHandle FireTimerHandle;
bool bCanFire = true;
// Strafe direction (1 = right, -1 = left)
float StrafeDirection = 1.0f;
// Timer for changing behavior
FTimerHandle BehaviorTimerHandle;
// Helper functions
void Fire();
void ResetFire();
void UpdateBehaviorState();
void ChangeBehaviorState();
void Die();
// AI behavior implementation functions
void PerformChase(float DeltaTime);
void PerformAttack(float DeltaTime);
void PerformRetreat(float DeltaTime);
void PerformStrafe(float DeltaTime);
};