Compare commits
No commits in common. "8bf01234a0854907da9830295d54824259fa859b" and "c6059578ace80f17c8c8597380e23fd9d4c0c17e" have entirely different histories.
8bf01234a0
...
c6059578ac
|
@ -1,52 +0,0 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "EXPComponent.h"
|
||||
|
||||
// Sets default values for this component's properties
|
||||
UEXPComponent::UEXPComponent()
|
||||
{
|
||||
// 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 = false;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
void UEXPComponent::IncrementEXP(int value)
|
||||
{
|
||||
// TODO: I should be updating the level here
|
||||
CurrentEXP += value;
|
||||
OnEXPGained.ExecuteIfBound();
|
||||
}
|
||||
|
||||
void UEXPComponent::SetCurrentEXP(int value)
|
||||
{
|
||||
// TODO: I should be updating the level here
|
||||
CurrentEXP = value;
|
||||
OnEXPGained.ExecuteIfBound();
|
||||
}
|
||||
|
||||
int UEXPComponent::GetCurrentEXP()
|
||||
{
|
||||
return CurrentEXP;
|
||||
}
|
||||
|
||||
int UEXPComponent::GetCurrentLevel()
|
||||
{
|
||||
return CurrentLevel;
|
||||
}
|
||||
|
||||
void UEXPComponent::Reset()
|
||||
{
|
||||
CurrentEXP = 0;
|
||||
CurrentLevel = 0;
|
||||
}
|
||||
|
||||
// Called when the game starts
|
||||
void UEXPComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
Reset();
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "EXPComponent.generated.h"
|
||||
|
||||
DECLARE_DELEGATE(FOnEXPGainedDelegate)
|
||||
DECLARE_DELEGATE(FOnEXPLevelUpDelegate)
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class VAMPIRES_API UEXPComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FOnEXPGainedDelegate OnEXPGained;
|
||||
FOnEXPLevelUpDelegate OnEXPLevelUp;
|
||||
|
||||
protected:
|
||||
int CurrentEXP = 0;
|
||||
|
||||
int CurrentLevel = 0;
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UEXPComponent();
|
||||
|
||||
UFUNCTION()
|
||||
void IncrementEXP(int value);
|
||||
|
||||
UFUNCTION()
|
||||
void SetCurrentEXP(int value);
|
||||
|
||||
UFUNCTION()
|
||||
int GetCurrentEXP();
|
||||
|
||||
UFUNCTION()
|
||||
int GetCurrentLevel();
|
||||
|
||||
UFUNCTION()
|
||||
void Reset();
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
};
|
|
@ -1,108 +0,0 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "HealthComponent.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 = false;
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
|
||||
AController* instigatedBy, AActor* damageCauser)
|
||||
{
|
||||
if (damagedActor == nullptr || IsDead || !CanDamage)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentHealth -= damage;
|
||||
|
||||
OnDamaged.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
|
||||
|
||||
if (CurrentHealth <= 0.0f)
|
||||
{
|
||||
IsDead = true;
|
||||
OnDeath.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
|
||||
}
|
||||
}
|
||||
|
||||
void UHealthComponent::IncrementHealth(float value)
|
||||
{
|
||||
CurrentHealth += value;
|
||||
|
||||
if (CurrentHealth > MaxHealth)
|
||||
{
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
float UHealthComponent::GetMaxHealth()
|
||||
{
|
||||
return MaxHealth;
|
||||
}
|
||||
|
||||
void UHealthComponent::SetMaxHealth(float value)
|
||||
{
|
||||
MaxHealth = value;
|
||||
}
|
||||
|
||||
float UHealthComponent::GetCurrentHealth()
|
||||
{
|
||||
return CurrentHealth;
|
||||
}
|
||||
|
||||
void UHealthComponent::SetCurrentHealth(float value)
|
||||
{
|
||||
CurrentHealth = value;
|
||||
|
||||
if (CurrentHealth > MaxHealth)
|
||||
{
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
}
|
||||
|
||||
void UHealthComponent::ResetHealth()
|
||||
{
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
|
||||
void UHealthComponent::RecoverHealth(float value)
|
||||
{
|
||||
// TODO: We might want to add some extra checking here
|
||||
IncrementHealth(value);
|
||||
}
|
||||
|
||||
bool UHealthComponent::GetIsDead()
|
||||
{
|
||||
return IsDead;
|
||||
}
|
||||
|
||||
void UHealthComponent::SetIsDead(bool isDead)
|
||||
{
|
||||
IsDead = isDead;
|
||||
}
|
||||
|
||||
bool UHealthComponent::GetCanDamage()
|
||||
{
|
||||
return CanDamage;
|
||||
}
|
||||
|
||||
void UHealthComponent::SetCanDamage(bool canDamage)
|
||||
{
|
||||
CanDamage = canDamage;
|
||||
}
|
||||
|
||||
|
||||
// Called when the game starts
|
||||
void UHealthComponent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
ResetHealth();
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "HealthComponent.generated.h"
|
||||
|
||||
USTRUCT()
|
||||
struct FDamageInfo
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
AActor* DamagedActor;
|
||||
|
||||
UPROPERTY()
|
||||
float Damage;
|
||||
|
||||
UPROPERTY()
|
||||
const UDamageType* DamageType;
|
||||
|
||||
UPROPERTY()
|
||||
AController* InstigatedBy;
|
||||
|
||||
UPROPERTY()
|
||||
AActor* DamageCauser;
|
||||
};
|
||||
|
||||
DECLARE_DELEGATE_OneParam(FOnDamageDelegate, FDamageInfo)
|
||||
DECLARE_DELEGATE_OneParam(FOnDeathDelegate, FDamageInfo)
|
||||
|
||||
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||
class VAMPIRES_API UHealthComponent : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
FOnDamageDelegate OnDamaged;
|
||||
FOnDeathDelegate OnDeath;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditDefaultsOnly)
|
||||
float MaxHealth = 100.f;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
float CurrentHealth;
|
||||
|
||||
bool IsDead = false;
|
||||
|
||||
bool CanDamage = true;
|
||||
|
||||
public:
|
||||
// Sets default values for this component's properties
|
||||
UHealthComponent();
|
||||
|
||||
UFUNCTION()
|
||||
virtual void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
|
||||
AController* instigatedBy,
|
||||
AActor* damageCauser);
|
||||
|
||||
UFUNCTION()
|
||||
void IncrementHealth(float value);
|
||||
|
||||
UFUNCTION()
|
||||
float GetMaxHealth();
|
||||
|
||||
UFUNCTION()
|
||||
void SetMaxHealth(float value);
|
||||
|
||||
UFUNCTION()
|
||||
float GetCurrentHealth();
|
||||
|
||||
UFUNCTION()
|
||||
void SetCurrentHealth(float value);
|
||||
|
||||
UFUNCTION()
|
||||
void ResetHealth();
|
||||
|
||||
UFUNCTION()
|
||||
void RecoverHealth(float healing);
|
||||
|
||||
UFUNCTION()
|
||||
bool GetIsDead();
|
||||
|
||||
UFUNCTION()
|
||||
void SetIsDead(bool isDead);
|
||||
|
||||
UFUNCTION()
|
||||
bool GetCanDamage();
|
||||
|
||||
UFUNCTION()
|
||||
void SetCanDamage(bool canDamage);
|
||||
|
||||
protected:
|
||||
// Called when the game starts
|
||||
virtual void BeginPlay() override;
|
||||
};
|
|
@ -17,7 +17,7 @@ APlayerCharacter::APlayerCharacter()
|
|||
CameraSpringArmComponent->bUsePawnControlRotation = false;
|
||||
CameraSpringArmComponent->TargetArmLength = 1000;
|
||||
CameraSpringArmComponent->bEnableCameraLag = false;
|
||||
CameraSpringArmComponent->SocketOffset = {0.0f, 0.0f, 0.0f};
|
||||
CameraSpringArmComponent->SocketOffset = { 0.0f, 0.0f, 0.0f };
|
||||
CameraSpringArmComponent->SetRelativeRotation({-90.0, 0.0f, 0.0f});
|
||||
|
||||
// Create Camera
|
||||
|
@ -26,12 +26,6 @@ APlayerCharacter::APlayerCharacter()
|
|||
CameraComponent->bUsePawnControlRotation = false;
|
||||
CameraComponent->SetProjectionMode(ECameraProjectionMode::Type::Orthographic);
|
||||
CameraComponent->SetOrthoWidth(4000.0f);
|
||||
|
||||
// Create Health Component
|
||||
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||
|
||||
// Create EXP Component
|
||||
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
|
||||
}
|
||||
|
||||
void APlayerCharacter::BeginPlay()
|
||||
|
@ -45,8 +39,7 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
|||
|
||||
if (AVampirePlayerController* TankPlayerController = Cast<AVampirePlayerController>(GetController()))
|
||||
{
|
||||
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<
|
||||
UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
|
||||
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(TankPlayerController->GetLocalPlayer()))
|
||||
{
|
||||
if (!InputMappingContext.IsNull())
|
||||
{
|
||||
|
@ -70,7 +63,7 @@ void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
|
|||
|
||||
if (vec2.Size() != 0.0f)
|
||||
{
|
||||
AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y);
|
||||
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X);
|
||||
AddMovementInput({0.0f,1.0f,0.0f}, vec2.Y);
|
||||
AddMovementInput({1.0f,0.0f,0.0f}, vec2.X);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "EXPComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "VampireCharacter.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
|
@ -22,6 +20,7 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
|
|||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
||||
|
||||
|
@ -34,14 +33,8 @@ public:
|
|||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
UInputAction* MovementAction;
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
UHealthComponent* HealthComponent;
|
||||
|
||||
UPROPERTY()
|
||||
UEXPComponent* EXPComponent;
|
||||
|
||||
public:
|
||||
|
||||
APlayerCharacter();
|
||||
|
||||
protected:
|
||||
|
@ -51,6 +44,9 @@ public:
|
|||
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
private:
|
||||
|
||||
UFUNCTION()
|
||||
void MovementCallback(const FInputActionInstance& Instance);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue