Add Gold Component
This commit is contained in:
parent
619c82bd01
commit
b576bb4a19
|
@ -0,0 +1,44 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "GoldComponent.h"
|
||||||
|
|
||||||
|
// Sets default values for this component's properties
|
||||||
|
UGoldComponent::UGoldComponent()
|
||||||
|
{
|
||||||
|
// 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 UGoldComponent::IncrementGold(int value)
|
||||||
|
{
|
||||||
|
CurrentGold += value;
|
||||||
|
OnGoldGained.ExecuteIfBound();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGoldComponent::SetCurrentGold(int value)
|
||||||
|
{
|
||||||
|
CurrentGold = value;
|
||||||
|
OnGoldGained.ExecuteIfBound();
|
||||||
|
}
|
||||||
|
|
||||||
|
int UGoldComponent::GetCurrentGold()
|
||||||
|
{
|
||||||
|
return CurrentGold;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGoldComponent::Reset()
|
||||||
|
{
|
||||||
|
CurrentGold = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the game starts
|
||||||
|
void UGoldComponent::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
Reset();
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Components/ActorComponent.h"
|
||||||
|
#include "GoldComponent.generated.h"
|
||||||
|
|
||||||
|
DECLARE_DELEGATE(FOnGoldGainedDelegate)
|
||||||
|
|
||||||
|
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
|
||||||
|
class VAMPIRES_API UGoldComponent : public UActorComponent
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
FOnGoldGainedDelegate OnGoldGained;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int CurrentGold = 0;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets default values for this component's properties
|
||||||
|
UGoldComponent();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void IncrementGold(int value);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void SetCurrentGold(int value);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
int GetCurrentGold();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void Reset();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
};
|
|
@ -31,6 +31,9 @@ APlayerCharacter::APlayerCharacter()
|
||||||
// Create EXP Component
|
// Create EXP Component
|
||||||
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
|
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
|
||||||
|
|
||||||
|
// Create Gold Component
|
||||||
|
GoldComponent = CreateDefaultSubobject<UGoldComponent>(TEXT("Gold Component"));
|
||||||
|
|
||||||
// Create Garlic Sphere Component
|
// Create Garlic Sphere Component
|
||||||
GarlicSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Garlic Sphere Component"));
|
GarlicSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Garlic Sphere Component"));
|
||||||
GarlicSphereComponent->SetupAttachment(RootComponent);
|
GarlicSphereComponent->SetupAttachment(RootComponent);
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "EnemyCharacter.h"
|
#include "EnemyCharacter.h"
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
|
#include "GoldComponent.h"
|
||||||
#include "VampireCharacter.h"
|
#include "VampireCharacter.h"
|
||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Components/SphereComponent.h"
|
#include "Components/SphereComponent.h"
|
||||||
|
@ -51,6 +52,9 @@ protected:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TArray<AEnemyCharacter*> OverlappedEnemies;
|
TArray<AEnemyCharacter*> OverlappedEnemies;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UGoldComponent* GoldComponent;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FTimerHandle GarlicTimerHandle;
|
FTimerHandle GarlicTimerHandle;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue