feat: add basic FPS base classes

This commit is contained in:
2025-12-04 00:47:52 +08:00
parent 9ad658d268
commit 6f7b761234
16 changed files with 421 additions and 112 deletions

View File

@@ -4,3 +4,5 @@ ProjectName=First Person Template
[/Script/EngineSettings.GeneralProjectSettings] [/Script/EngineSettings.GeneralProjectSettings]
ProjectID=CD31059C4BA9CB538B509492FA2A5B38 ProjectID=CD31059C4BA9CB538B509492FA2A5B38
CopyrightNotice=Copyright Majowaveon Games. All Rights Reserved.

View File

@@ -11,5 +11,6 @@ public class FirstPersonDemoTarget : TargetRules
DefaultBuildSettings = BuildSettingsVersion.V6; DefaultBuildSettings = BuildSettingsVersion.V6;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
ExtraModuleNames.Add("FirstPersonDemo"); ExtraModuleNames.Add("FirstPersonDemo");
CppStandard = CppStandardVersion.Cpp20;
} }
} }

View File

@@ -0,0 +1,7 @@
// Copyright Majowaveon Games. All Rights Reserved.
#include "DamageableInterface.h"
// Add default functionality here for any IDamageableInterface functions that are not pure virtual.

View File

@@ -0,0 +1,32 @@
// Copyright Majowaveon Games. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "DamageableInterface.generated.h"
// This class does not need to be modified.
UINTERFACE()
class UDamageableInterface : public UInterface {
GENERATED_BODY()
};
/**
* @class IDamageableInterface
* @brief 伤害组件
* @ingroup Battle
*/
class FIRSTPERSONDEMO_API IDamageableInterface {
GENERATED_BODY()
public:
/**
* @brief 响应伤害
* @note 实现类应重写此函数,再将**处理后**伤害参数交由生命组件处理;
* 为什么要多一层转发因为可能会涉及到护盾、伤害减免等逻辑HealthComponent不知道这些逻辑有其他组件持有或者有盾作为第二层血皮
* @param DamageAmount 伤害量
* @param InstigatorActor 造成伤害的Actor
*/
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) = 0;
};

View File

@@ -0,0 +1,29 @@
// Copyright Majowaveon Games. All Rights Reserved.
#include "Surviver_FPS/Battle/EnemyBase.h"
// Sets default values
AEnemyBase::AEnemyBase() {
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AEnemyBase::BeginPlay() {
Super::BeginPlay();
}
// Called every frame
void AEnemyBase::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AEnemyBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
void AEnemyBase::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
return;
}

View File

@@ -0,0 +1,42 @@
// Copyright Majowaveon Games. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "DamageableInterface.h"
#include "GameFramework/Pawn.h"
#include "EnemyBase.generated.h"
/**
* @class AEnemyBase
* @brief 敌人基类
* @ingroup Battle
* @todo 实现TakeDamage接口挂HealthComponent组件
*/
UCLASS()
class FIRSTPERSONDEMO_API AEnemyBase : public APawn, public IDamageableInterface {
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AEnemyBase();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
/**
* @brief 敌人受伤函数
* @param DamageAmount 伤害量
*/
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
};

View File

@@ -0,0 +1,37 @@
// Copyright Majowaveon Games. All Rights Reserved.
#include "HealthComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values for this component's properties
UHealthComponent::UHealthComponent() {
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;
// ...
}
// Called when the game starts
void UHealthComponent::BeginPlay() {
Super::BeginPlay();
// ...
}
// Called every frame
void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UHealthComponent::HandleDamage(float DamageAmount) {
}

View File

@@ -0,0 +1,48 @@
// Copyright Majowaveon Games. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "HealthComponent.generated.h"
/**
* @class UHealthComponent
* @brief 生命组件
* @ingroup Battle
*/
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class FIRSTPERSONDEMO_API UHealthComponent : public UActorComponent {
GENERATED_BODY()
public:
// Sets default values for this component's properties
UHealthComponent();
protected:
// 最大生命值
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health")
float MaxHealth = 100.0f;
// 当前生命值
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health")
float CurrentHealth;
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
/**
* @brief 处理伤害
* @param DamageAmount 伤害量
* @todo 实现血量计算,处理死亡逻辑
*/
UFUNCTION(BlueprintCallable, Category="Health")
void HandleDamage(float DamageAmount);
};

View File

@@ -0,0 +1,31 @@
// Copyright Majowaveon Games. All Rights Reserved.
#include "SuriverPlayer.h"
// Sets default values
ASuriverPlayer::ASuriverPlayer() {
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void ASuriverPlayer::BeginPlay() {
Super::BeginPlay();
}
// Called every frame
void ASuriverPlayer::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ASuriverPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
void ASuriverPlayer::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
}

View File

@@ -0,0 +1,37 @@
// Copyright Majowaveon Games. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "DamageableInterface.h"
#include "GameFramework/Character.h"
#include "SuriverPlayer.generated.h"
/**
* @class ASuriverPlayer
* @brief 玩家基类
* @ingroup Battle
* @todo 实现TakeDamage接口挂HealthComponent组件
*/
UCLASS()
class FIRSTPERSONDEMO_API ASuriverPlayer : public ACharacter, public IDamageableInterface {
GENERATED_BODY()
public:
// Sets default values for this character's properties
ASuriverPlayer();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
};

View File

@@ -0,0 +1,16 @@
#pragma once
/**
* @defgroup GameCore 核心玩法系统
* 包含游戏模式、角色和控制器等基础类。
*/
/**
* @defgroup Battle 战斗系统
* 包含所有枪械、投射物和拾取物。
*/
/**
* @defgroup UI 用户界面系统
* 包含所有用户界面相关类。
*/

View File

@@ -0,0 +1,5 @@
// Copyright Majowaveon Games. All Rights Reserved.
#include "Surviver_FPS/SurviverGameMode.h"

View File

@@ -0,0 +1,21 @@
// Copyright Majowaveon Games. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "SurviverGameMode.generated.h"
/**
* @class ASurviverGameMode
* @brief 游戏模式类
* @ingroup GameCore
*
*
*/
UCLASS()
class FIRSTPERSONDEMO_API ASurviverGameMode : public AGameModeBase
{
GENERATED_BODY()
};

View File

@@ -11,5 +11,6 @@ public class FirstPersonDemoEditorTarget : TargetRules
DefaultBuildSettings = BuildSettingsVersion.V6; DefaultBuildSettings = BuildSettingsVersion.V6;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
ExtraModuleNames.Add("FirstPersonDemo"); ExtraModuleNames.Add("FirstPersonDemo");
CppStandard = CppStandardVersion.Cpp20;
} }
} }