feat: add basic FPS base classes
This commit is contained in:
@@ -4,3 +4,5 @@ ProjectName=First Person Template
|
||||
|
||||
[/Script/EngineSettings.GeneralProjectSettings]
|
||||
ProjectID=CD31059C4BA9CB538B509492FA2A5B38
|
||||
CopyrightNotice=Copyright Majowaveon Games. All Rights Reserved.
|
||||
|
||||
|
||||
@@ -11,5 +11,6 @@ public class FirstPersonDemoTarget : TargetRules
|
||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||
ExtraModuleNames.Add("FirstPersonDemo");
|
||||
CppStandard = CppStandardVersion.Cpp20;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
};
|
||||
29
Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp
Normal file
29
Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.cpp
Normal 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;
|
||||
}
|
||||
42
Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h
Normal file
42
Source/FirstPersonDemo/Surviver_FPS/Battle/EnemyBase.h
Normal 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;
|
||||
};
|
||||
@@ -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) {
|
||||
|
||||
}
|
||||
48
Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h
Normal file
48
Source/FirstPersonDemo/Surviver_FPS/Battle/HealthComponent.h
Normal 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);
|
||||
|
||||
};
|
||||
31
Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp
Normal file
31
Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.cpp
Normal 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) {
|
||||
|
||||
}
|
||||
37
Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h
Normal file
37
Source/FirstPersonDemo/Surviver_FPS/Battle/SuriverPlayer.h
Normal 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;
|
||||
};
|
||||
16
Source/FirstPersonDemo/Surviver_FPS/Documentation.h
Normal file
16
Source/FirstPersonDemo/Surviver_FPS/Documentation.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @defgroup GameCore 核心玩法系统
|
||||
* 包含游戏模式、角色和控制器等基础类。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup Battle 战斗系统
|
||||
* 包含所有枪械、投射物和拾取物。
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup UI 用户界面系统
|
||||
* 包含所有用户界面相关类。
|
||||
*/
|
||||
5
Source/FirstPersonDemo/Surviver_FPS/SurviverGameMode.cpp
Normal file
5
Source/FirstPersonDemo/Surviver_FPS/SurviverGameMode.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright Majowaveon Games. All Rights Reserved.
|
||||
|
||||
|
||||
#include "Surviver_FPS/SurviverGameMode.h"
|
||||
|
||||
21
Source/FirstPersonDemo/Surviver_FPS/SurviverGameMode.h
Normal file
21
Source/FirstPersonDemo/Surviver_FPS/SurviverGameMode.h
Normal 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()
|
||||
|
||||
};
|
||||
@@ -11,5 +11,6 @@ public class FirstPersonDemoEditorTarget : TargetRules
|
||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||
ExtraModuleNames.Add("FirstPersonDemo");
|
||||
CppStandard = CppStandardVersion.Cpp20;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user