From cca4fc3e83636522881e350db23d9fa2020ee7ab Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Tue, 10 May 2022 12:15:22 +0200 Subject: [PATCH] 121 - Match State --- Source/Blaster/GameMode/BlasterGameMode.cpp | 26 +++++++++++++++++++ Source/Blaster/GameMode/BlasterGameMode.h | 21 ++++++++++++--- .../BlasterPlayerController.h | 2 +- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 4c8b5d8..e8616f4 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -9,6 +9,32 @@ #include "GameFramework/PlayerStart.h" #include "Kismet/GameplayStatics.h" +ABlasterGameMode::ABlasterGameMode() +{ + bDelayedStart = true; +} + +void ABlasterGameMode::BeginPlay() +{ + Super::BeginPlay(); + + LevelStartingTime = GetWorld()->GetTimeSeconds(); +} + +void ABlasterGameMode::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + if (MatchState == MatchState::WaitingToStart) + { + CountDownTime = WarmupTime - GetWorld()->GetTimeSeconds() + LevelStartingTime; + if (CountDownTime < 0.f) + { + StartMatch(); + } + } +} + void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController, ABlasterPlayerController* AttackerController) { diff --git a/Source/Blaster/GameMode/BlasterGameMode.h b/Source/Blaster/GameMode/BlasterGameMode.h index 7e9560b..d8efe3c 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.h +++ b/Source/Blaster/GameMode/BlasterGameMode.h @@ -13,9 +13,22 @@ UCLASS() class BLASTER_API ABlasterGameMode : public AGameMode { GENERATED_BODY() - - public: - - virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController, class ABlasterPlayerController* AttackerController); + +public: + ABlasterGameMode(); + virtual void Tick(float DeltaSeconds) override; + virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController, + class ABlasterPlayerController* AttackerController); virtual void RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController); + + UPROPERTY(EditDefaultsOnly) + float WarmupTime = 10.f; + + float LevelStartingTime = 0.f; + +protected: + virtual void BeginPlay() override; + +private: + float CountDownTime = 0.f; }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 61ddfb8..308c3dd 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -50,7 +50,7 @@ protected: float ClientServerDelta = 0; UPROPERTY(EditAnywhere, Category = Time) - float TimeSyncFrequency = 10.f; + float TimeSyncFrequency = 5.f; float TimeSyncRunningTime = 0.f; private: