Compare commits

...

4 Commits

Author SHA1 Message Date
baz cafb8206e5 IncrementEXP when player overlaps 2024-06-24 21:42:44 +01:00
baz 7f6e41cb50 IncrementGold when Player overlaps 2024-06-24 21:42:33 +01:00
baz 2d078ec48c Add GetGoldComponent function 2024-06-24 21:42:03 +01:00
baz 0092c3831f Add Get EXPComponent function 2024-06-24 21:41:49 +01:00
6 changed files with 41 additions and 9 deletions

View File

@ -3,6 +3,8 @@
#include "EXPPickup.h" #include "EXPPickup.h"
#include "PlayerCharacter.h"
void AEXPPickup::BeginPlay() void AEXPPickup::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
@ -16,7 +18,9 @@ void AEXPPickup::Tick(float DeltaSeconds)
void AEXPPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void AEXPPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{ {
// TODO: Add EXP to player EXP component if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
} }

View File

@ -13,7 +13,10 @@ UCLASS()
class VAMPIRES_API AEXPPickup : public APickup class VAMPIRES_API AEXPPickup : public APickup
{ {
GENERATED_BODY() GENERATED_BODY()
public:
int EXP = 1;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
@ -21,6 +24,6 @@ public:
virtual void Tick(float DeltaSeconds) override; virtual void Tick(float DeltaSeconds) override;
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override; const FHitResult& SweepResult) override;
}; };

View File

@ -3,6 +3,10 @@
#include "GoldPickup.h" #include "GoldPickup.h"
#include "PlayerCharacter.h"
class APlayerCharacter;
void AGoldPickup::BeginPlay() void AGoldPickup::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
@ -16,7 +20,9 @@ void AGoldPickup::Tick(float DeltaSeconds)
void AGoldPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void AGoldPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{ {
// TODO: Add Gold to player Gold component if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
} }

View File

@ -14,6 +14,11 @@ class VAMPIRES_API AGoldPickup : public APickup
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int Gold = 1;
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;

View File

@ -74,6 +74,16 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
} }
} }
UEXPComponent* APlayerCharacter::GetEXPComponent()
{
return EXPComponent;
}
UGoldComponent* APlayerCharacter::GetGoldComponent()
{
return GoldComponent;
}
void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance) void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
{ {
FVector2D vec2 = Instance.GetValue().Get<FVector2D>(); FVector2D vec2 = Instance.GetValue().Get<FVector2D>();

View File

@ -67,6 +67,10 @@ protected:
public: public:
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
UEXPComponent* GetEXPComponent();
UGoldComponent* GetGoldComponent();
private: private:
UFUNCTION() UFUNCTION()
void MovementCallback(const FInputActionInstance& Instance); void MovementCallback(const FInputActionInstance& Instance);