Compare commits
2 Commits
929c4fa0f3
...
e55d62ff05
Author | SHA1 | Date |
---|---|---|
baz | e55d62ff05 | |
baz | e694e647b0 |
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include "EXPPickup.h"
|
#include "EXPPickup.h"
|
||||||
|
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
#include "PlayerCharacter.h"
|
|
||||||
|
|
||||||
void AEXPPickup::BeginPlay()
|
void AEXPPickup::BeginPlay()
|
||||||
{
|
{
|
||||||
|
@ -17,11 +15,12 @@ void AEXPPickup::Tick(float DeltaSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
void AEXPPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
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 (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
if (UEXPComponent* expComponent = OtherActor->GetComponentByClass<UEXPComponent>())
|
||||||
{
|
{
|
||||||
PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
|
expComponent->IncrementEXP(EXP);
|
||||||
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "GoldPickup.h"
|
#include "GoldPickup.h"
|
||||||
|
|
||||||
#include "GoldComponent.h"
|
#include "GoldComponent.h"
|
||||||
#include "PlayerCharacter.h"
|
|
||||||
|
|
||||||
class APlayerCharacter;
|
class APlayerCharacter;
|
||||||
|
|
||||||
|
@ -19,11 +18,12 @@ void AGoldPickup::Tick(float DeltaSeconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGoldPickup::OnInnerBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
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 (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
|
if (UGoldComponent* goldComponent = OtherActor->GetComponentByClass<UGoldComponent>())
|
||||||
{
|
{
|
||||||
PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
|
goldComponent->IncrementGold(Gold);
|
||||||
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
Super::OnInnerBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "VampirePlayerController.h"
|
#include "VampirePlayerController.h"
|
||||||
|
|
||||||
#include "EXPComponent.h"
|
#include "EXPComponent.h"
|
||||||
#include "HealthComponent.h"
|
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
@ -25,9 +24,8 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||||
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
|
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
|
||||||
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
|
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
|
if (AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
|
||||||
if (gamemode)
|
|
||||||
{
|
{
|
||||||
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
|
||||||
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "HealthbarWidget.h"
|
#include "HealthbarWidget.h"
|
||||||
|
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "vampires/PlayerCharacter.h"
|
|
||||||
#include "Components/ProgressBar.h"
|
#include "Components/ProgressBar.h"
|
||||||
#include "vampires/HealthComponent.h"
|
#include "vampires/HealthComponent.h"
|
||||||
#include "vampires/VampireCharacter.h"
|
#include "vampires/VampireCharacter.h"
|
||||||
|
@ -12,15 +11,25 @@
|
||||||
void UHealthbarWidget::NativeConstruct()
|
void UHealthbarWidget::NativeConstruct()
|
||||||
{
|
{
|
||||||
Super::NativeConstruct();
|
Super::NativeConstruct();
|
||||||
APlayerCharacter* player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
|
||||||
UHealthComponent* healthComponent = player->GetHealthComponent();
|
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||||
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
|
{
|
||||||
UpdateHealthBar({});
|
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
|
||||||
|
{
|
||||||
|
healthComponent->OnDamaged.AddDynamic(this, &UHealthbarWidget::UpdateHealthBar);
|
||||||
|
UpdateHealthBar({});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UHealthbarWidget::UpdateHealthBar(FDamageInfo damageInfo)
|
void UHealthbarWidget::UpdateHealthBar(FDamageInfo damageInfo)
|
||||||
{
|
{
|
||||||
APlayerCharacter* player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
if (ACharacter* character = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))
|
||||||
float percent = player->GetHealthComponent()->GetCurrentHealth() / player->GetHealthComponent()->GetMaxHealth();
|
{
|
||||||
HealthBar->SetPercent(percent);
|
if (UHealthComponent* healthComponent = character->FindComponentByClass<UHealthComponent>())
|
||||||
|
{
|
||||||
|
float percent = healthComponent->GetCurrentHealth() / healthComponent->GetMaxHealth();
|
||||||
|
HealthBar->SetPercent(percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "vampires/HealthComponent.h"
|
|
||||||
#include "HealthbarWidget.generated.h"
|
#include "HealthbarWidget.generated.h"
|
||||||
|
|
||||||
class UProgressBar;
|
class UProgressBar;
|
||||||
|
|
Loading…
Reference in New Issue