From 2ad6b53ab3096c73cfec740cdd59988d579b0467 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 21 Aug 2024 01:28:16 +0100 Subject: [PATCH] Add Kill Counter --- Content/Widgets/HUD/BP_HUDWidget.uasset | 4 ++-- Source/vampires/EnemyCharacter.cpp | 6 ++++++ Source/vampires/VampireGameMode.cpp | 10 ++++++++++ Source/vampires/VampireGameMode.h | 11 +++++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Content/Widgets/HUD/BP_HUDWidget.uasset b/Content/Widgets/HUD/BP_HUDWidget.uasset index ed4e279..17101d7 100644 --- a/Content/Widgets/HUD/BP_HUDWidget.uasset +++ b/Content/Widgets/HUD/BP_HUDWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:100a17e8c230198fc4bd2069aeb489726be0f5d74ee8d10d90f2227a612e00c4 -size 137481 +oid sha256:c59c729edd4c86eadb9f563f428825660546673fa2ac8b9b7d2fa14b121d9f53 +size 165091 diff --git a/Source/vampires/EnemyCharacter.cpp b/Source/vampires/EnemyCharacter.cpp index e574d7e..00989ab 100644 --- a/Source/vampires/EnemyCharacter.cpp +++ b/Source/vampires/EnemyCharacter.cpp @@ -3,6 +3,9 @@ #include "EnemyCharacter.h" +#include "VampireGameMode.h" +#include "Kismet/GameplayStatics.h" + AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) { } @@ -39,5 +42,8 @@ void AEnemyCharacter::OnDeath() GetWorld()->SpawnActor(EXPPickupTemplate, GetActorLocation(), FRotator::ZeroRotator, actorSpawnParameters); + + AVampireGameMode* gamemode = Cast(UGameplayStatics::GetGameMode(GetWorld())); + gamemode->IncrementEnemyDeathCount(); //} } diff --git a/Source/vampires/VampireGameMode.cpp b/Source/vampires/VampireGameMode.cpp index 6534470..b877325 100644 --- a/Source/vampires/VampireGameMode.cpp +++ b/Source/vampires/VampireGameMode.cpp @@ -16,6 +16,11 @@ void AVampireGameMode::BeginPlay() GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true); } +int AVampireGameMode::GetEnemyDeathCount() +{ + return EnemyDeathCount; +} + void AVampireGameMode::SpawnEnemy() { FVector TopLeft, TopLeftDir; @@ -68,3 +73,8 @@ void AVampireGameMode::SpawnEnemy() Actor->SetActorLocation(SpawnLocation + Direction); Actor->SpawnDefaultController(); } + +void AVampireGameMode::IncrementEnemyDeathCount() +{ + EnemyDeathCount++; +} diff --git a/Source/vampires/VampireGameMode.h b/Source/vampires/VampireGameMode.h index c2313f1..8209d84 100644 --- a/Source/vampires/VampireGameMode.h +++ b/Source/vampires/VampireGameMode.h @@ -28,9 +28,20 @@ private: FTimerHandle SpawnEnemyTimerDelegate; + int EnemyDeathCount = 0; + protected: virtual void BeginPlay() override; +public: + UFUNCTION(BlueprintCallable, BlueprintPure) + int GetEnemyDeathCount(); + + UFUNCTION() + void IncrementEnemyDeathCount(); + +protected: + UFUNCTION() void SpawnEnemy(); };