Switch to Timeline for game Timer
This commit is contained in:
parent
2c3a66cbd4
commit
64a21df059
BIN
Content/Gamemode/BP_DefaultGamemode.uasset
(Stored with Git LFS)
BIN
Content/Gamemode/BP_DefaultGamemode.uasset
(Stored with Git LFS)
Binary file not shown.
7
Source/vampires/Interfaces/Playerable.cpp
Normal file
7
Source/vampires/Interfaces/Playerable.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
|
||||
#include "Playerable.h"
|
||||
|
||||
|
||||
// Add default functionality here for any IPlayerable functions that are not pure virtual.
|
28
Source/vampires/Interfaces/Playerable.h
Normal file
28
Source/vampires/Interfaces/Playerable.h
Normal file
@ -0,0 +1,28 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "UObject/Interface.h"
|
||||
#include "Playerable.generated.h"
|
||||
|
||||
// This class does not need to be modified.
|
||||
UINTERFACE(Blueprintable)
|
||||
class UPlayerable : public UInterface
|
||||
{
|
||||
GENERATED_BODY()
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class VAMPIRES_API IPlayerable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
|
||||
public:
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
|
||||
void UpdateTimerHUDElement(float deltaTime);
|
||||
};
|
@ -76,9 +76,9 @@ void AVampireGameMode::SpawnEnemy()
|
||||
|
||||
if (AActor* enemy = GetEnemyObjectPoolManager_Implementation()->GetObject())
|
||||
{
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(enemy, UEnemyable::StaticClass()) && EnemyDataAssets.Num() > 0)
|
||||
if (UKismetSystemLibrary::DoesImplementInterface(enemy, UEnemyable::StaticClass()) && SpawnableEnemyDataAssets.Num() > 0)
|
||||
{
|
||||
IEnemyable::Execute_LoadDataFromDataAsset(enemy, EnemyDataAssets[FMath::RandRange(0, EnemyDataAssets.Num() - 1)]);
|
||||
IEnemyable::Execute_LoadDataFromDataAsset(enemy, SpawnableEnemyDataAssets[FMath::RandRange(0, SpawnableEnemyDataAssets.Num() - 1)]);
|
||||
|
||||
SpawnLocation.Z = PlayerCharacter->GetActorLocation().Z;
|
||||
FTransform Transform;
|
||||
@ -139,6 +139,21 @@ AObjectPoolManager* AVampireGameMode::GetPickupObjectPoolManager_Implementation(
|
||||
return PickupObjectPoolManager;
|
||||
}
|
||||
|
||||
void AVampireGameMode::AddRandomEnemyTypeToPool()
|
||||
{
|
||||
if (EnemyDataAssets.Num() > 0)
|
||||
{
|
||||
int32 rand = FMath::RandRange(0, EnemyDataAssets.Num() - 1);
|
||||
SpawnableEnemyDataAssets.Add(EnemyDataAssets[rand]);
|
||||
EnemyDataAssets.RemoveAt(rand);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampireGameMode::EndGame()
|
||||
{
|
||||
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, true);
|
||||
}
|
||||
|
||||
void AVampireGameMode::IncrementEnemyDeathCount()
|
||||
{
|
||||
EnemyDeathCount++;
|
||||
|
@ -53,6 +53,8 @@ private:
|
||||
|
||||
TObjectPtr<AObjectPoolManager> PickupObjectPoolManager = nullptr;
|
||||
|
||||
TArray<TObjectPtr<UEnemyDataAsset>> SpawnableEnemyDataAssets;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
@ -72,6 +74,12 @@ public:
|
||||
|
||||
virtual AObjectPoolManager* GetPickupObjectPoolManager_Implementation() override;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void AddRandomEnemyTypeToPool();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void EndGame();
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void SpawnEnemy();
|
||||
|
@ -53,8 +53,6 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
||||
}
|
||||
|
||||
GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f);
|
||||
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->AddToViewport();
|
||||
@ -163,11 +161,11 @@ void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateTimerHUD()
|
||||
void AVampirePlayerController::UpdateTimerHUD(float deltaTime)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateTimerBlock(GetPawn());
|
||||
currentPlayerHUD->UpdateTimerBlock(deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,3 +184,11 @@ void AVampirePlayerController::UpdateGoldCountHUD(int goldCount)
|
||||
currentPlayerHUD->UpdateGoldBlock(goldCount);
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float deltaTime)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateTimerBlock(deltaTime);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "Interfaces/Playerable.h"
|
||||
#include "VampirePlayerController.generated.h"
|
||||
|
||||
class ULevelUpWidget;
|
||||
@ -15,7 +16,7 @@ class UHUDWidget;
|
||||
*
|
||||
*/
|
||||
UCLASS(Abstract)
|
||||
class VAMPIRES_API AVampirePlayerController : public APlayerController
|
||||
class VAMPIRES_API AVampirePlayerController : public APlayerController, public IPlayerable
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
@ -69,12 +70,14 @@ protected:
|
||||
UFUNCTION()
|
||||
void UpdatePlayerLevelHUD(int level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerHUD();
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void UpdateTimerHUD(float deltaTime);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillCountHUD(int killCount);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateGoldCountHUD(int goldCount);
|
||||
|
||||
virtual void UpdateTimerHUDElement_Implementation(float deltaTime) override;
|
||||
};
|
||||
|
@ -19,18 +19,18 @@ void UHUDWidget::UpdateLevelBlock(int level)
|
||||
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(level)));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateTimerBlock(APawn* pawn)
|
||||
void UHUDWidget::UpdateTimerBlock(float deltaTime)
|
||||
{
|
||||
int timeSinceCreation = FMath::FloorToInt(pawn->GetGameTimeSinceCreation());
|
||||
int timeSinceStart = FMath::FloorToInt(deltaTime);
|
||||
|
||||
FString mins = FString::FromInt(timeSinceCreation / 60);
|
||||
if (timeSinceCreation / 60 < 10)
|
||||
FString mins = FString::FromInt(timeSinceStart / 60);
|
||||
if (timeSinceStart / 60 < 10)
|
||||
{
|
||||
mins = "0" + mins;
|
||||
}
|
||||
|
||||
FString secs = FString::FromInt(timeSinceCreation % 60);
|
||||
if (timeSinceCreation % 60 < 10)
|
||||
FString secs = FString::FromInt(timeSinceStart % 60);
|
||||
if (timeSinceStart % 60 < 10)
|
||||
{
|
||||
secs = "0" + secs;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
void UpdateLevelBlock(int level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerBlock(APawn* pawn);
|
||||
void UpdateTimerBlock(float deltaTime);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillBlock(int killCount);
|
||||
|
Loading…
x
Reference in New Issue
Block a user