diff --git a/Source/vampires/GoldComponent.cpp b/Source/vampires/GoldComponent.cpp new file mode 100644 index 0000000..0759c61 --- /dev/null +++ b/Source/vampires/GoldComponent.cpp @@ -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(); +} diff --git a/Source/vampires/GoldComponent.h b/Source/vampires/GoldComponent.h new file mode 100644 index 0000000..6c78d69 --- /dev/null +++ b/Source/vampires/GoldComponent.h @@ -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; +}; diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index a3df768..4ddf101 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -31,6 +31,9 @@ APlayerCharacter::APlayerCharacter() // Create EXP Component EXPComponent = CreateDefaultSubobject(TEXT("EXP Component")); + // Create Gold Component + GoldComponent = CreateDefaultSubobject(TEXT("Gold Component")); + // Create Garlic Sphere Component GarlicSphereComponent = CreateDefaultSubobject(TEXT("Garlic Sphere Component")); GarlicSphereComponent->SetupAttachment(RootComponent); diff --git a/Source/vampires/PlayerCharacter.h b/Source/vampires/PlayerCharacter.h index bbb29ac..9ded7d5 100644 --- a/Source/vampires/PlayerCharacter.h +++ b/Source/vampires/PlayerCharacter.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "EnemyCharacter.h" #include "EXPComponent.h" +#include "GoldComponent.h" #include "VampireCharacter.h" #include "Camera/CameraComponent.h" #include "Components/SphereComponent.h" @@ -51,6 +52,9 @@ protected: UPROPERTY() TArray OverlappedEnemies; + UPROPERTY() + UGoldComponent* GoldComponent; + private: FTimerHandle GarlicTimerHandle;