Add EXPComponent
This commit is contained in:
parent
a0a503f836
commit
8bf01234a0
|
@ -0,0 +1,52 @@
|
||||||
|
// 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();
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
// 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;
|
||||||
|
};
|
|
@ -17,7 +17,7 @@ APlayerCharacter::APlayerCharacter()
|
||||||
CameraSpringArmComponent->bUsePawnControlRotation = false;
|
CameraSpringArmComponent->bUsePawnControlRotation = false;
|
||||||
CameraSpringArmComponent->TargetArmLength = 1000;
|
CameraSpringArmComponent->TargetArmLength = 1000;
|
||||||
CameraSpringArmComponent->bEnableCameraLag = false;
|
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});
|
CameraSpringArmComponent->SetRelativeRotation({-90.0, 0.0f, 0.0f});
|
||||||
|
|
||||||
// Create Camera
|
// Create Camera
|
||||||
|
@ -29,6 +29,9 @@ APlayerCharacter::APlayerCharacter()
|
||||||
|
|
||||||
// Create Health Component
|
// Create Health Component
|
||||||
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
|
||||||
|
|
||||||
|
// Create EXP Component
|
||||||
|
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::BeginPlay()
|
void APlayerCharacter::BeginPlay()
|
||||||
|
@ -42,7 +45,8 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
||||||
|
|
||||||
if (AVampirePlayerController* TankPlayerController = Cast<AVampirePlayerController>(GetController()))
|
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())
|
if (!InputMappingContext.IsNull())
|
||||||
{
|
{
|
||||||
|
@ -66,7 +70,7 @@ void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
|
||||||
|
|
||||||
if (vec2.Size() != 0.0f)
|
if (vec2.Size() != 0.0f)
|
||||||
{
|
{
|
||||||
AddMovementInput({0.0f,1.0f,0.0f}, vec2.Y);
|
AddMovementInput({0.0f, 1.0f, 0.0f}, vec2.Y);
|
||||||
AddMovementInput({1.0f,0.0f,0.0f}, vec2.X);
|
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "EXPComponent.h"
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
#include "VampireCharacter.h"
|
#include "VampireCharacter.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
|
@ -21,7 +22,6 @@ class VAMPIRES_API APlayerCharacter : public AVampireCharacter
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
USpringArmComponent* CameraSpringArmComponent = nullptr;
|
||||||
|
|
||||||
|
@ -34,11 +34,14 @@ public:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
UInputAction* MovementAction;
|
UInputAction* MovementAction;
|
||||||
|
|
||||||
|
protected:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
UHealthComponent* HealthComponent;
|
UHealthComponent* HealthComponent;
|
||||||
|
|
||||||
public:
|
UPROPERTY()
|
||||||
|
UEXPComponent* EXPComponent;
|
||||||
|
|
||||||
|
public:
|
||||||
APlayerCharacter();
|
APlayerCharacter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -48,9 +51,6 @@ public:
|
||||||
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void MovementCallback(const FInputActionInstance& Instance);
|
void MovementCallback(const FInputActionInstance& Instance);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue