Compare commits

..

No commits in common. "e55d62ff05e27371e407a60f1cee52ab3e31187b" and "929c4fa0f3829ef9f76d1d512573c299927e7956" have entirely different histories.

5 changed files with 22 additions and 27 deletions

View File

@ -2,7 +2,9 @@
#include "EXPPickup.h"
#include "EXPComponent.h"
#include "PlayerCharacter.h"
void AEXPPickup::BeginPlay()
{
@ -15,12 +17,11 @@ void AEXPPickup::Tick(float DeltaSeconds)
}
void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (UEXPComponent* expComponent = OtherActor->GetComponentByClass<UEXPComponent>())
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
expComponent->IncrementEXP(EXP);
PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -4,6 +4,7 @@
#include "GoldPickup.h"
#include "GoldComponent.h"
#include "PlayerCharacter.h"
class APlayerCharacter;
@ -18,12 +19,11 @@ void AGoldPickup::Tick(float DeltaSeconds)
}
void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (UGoldComponent* goldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
goldComponent->IncrementGold(Gold);
PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -4,6 +4,7 @@
#include "VampirePlayerController.h"
#include "EXPComponent.h"
#include "HealthComponent.h"
#include "VampireGameMode.h"
#include "Blueprint/UserWidget.h"
#include "Kismet/GameplayStatics.h"
@ -24,8 +25,9 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
}
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (gamemode)
{
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());

View File

@ -4,6 +4,7 @@
#include "HealthbarWidget.h"
#include "Kismet/GameplayStatics.h"
#include "vampires/PlayerCharacter.h"
#include "Components/ProgressBar.h"
#include "vampires/HealthComponent.h"
#include "vampires/VampireCharacter.h"
@ -11,25 +12,15 @@
void UHealthbarWidget::NativeConstruct()
{
Super::NativeConstruct();
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
{
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
{
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
UpdateHealthBar({});
}
}
APlayerCharacter* player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
UHealthComponent* healthComponent = player->GetHealthComponent();
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
UpdateHealthBar({});
}
void UHealthbarWidget::UpdateHealthBar(FDamageInfo damageInfo)
{
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
{
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
{
float percent = healthComponent->GetCurrentHealth() / healthComponent->GetMaxHealth();
HealthBar->SetPercent(percent);
}
}
APlayerCharacter* player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
float percent = player->GetHealthComponent()->GetCurrentHealth() / player->GetHealthComponent()->GetMaxHealth();
HealthBar->SetPercent(percent);
}

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "vampires/HealthComponent.h"
#include "HealthbarWidget.generated.h"
class UProgressBar;