119 - Game Timer
This commit is contained in:
parent
6960a94be5
commit
f1558e3a8a
Binary file not shown.
|
@ -34,4 +34,7 @@ public:
|
||||||
UPROPERTY(meta = (BindWidget))
|
UPROPERTY(meta = (BindWidget))
|
||||||
UTextBlock* CarriedAmmoValue;
|
UTextBlock* CarriedAmmoValue;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
UTextBlock* MatchCountdownText;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,13 @@ void ABlasterPlayerController::BeginPlay()
|
||||||
BlasterHUD = Cast<ABlasterHUD>(GetHUD());
|
BlasterHUD = Cast<ABlasterHUD>(GetHUD());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterPlayerController::Tick(float DeltaSeconds)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaSeconds);
|
||||||
|
|
||||||
|
SetHUDTime();
|
||||||
|
}
|
||||||
|
|
||||||
void ABlasterPlayerController::OnPossess(APawn* InPawn)
|
void ABlasterPlayerController::OnPossess(APawn* InPawn)
|
||||||
{
|
{
|
||||||
Super::OnPossess(InPawn);
|
Super::OnPossess(InPawn);
|
||||||
|
@ -27,6 +34,18 @@ void ABlasterPlayerController::OnPossess(APawn* InPawn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterPlayerController::SetHUDTime()
|
||||||
|
{
|
||||||
|
const uint32 SecondsLeft = FMath::CeilToInt(MatchTime - GetWorld()->GetTimeSeconds());
|
||||||
|
|
||||||
|
if (CountdownInt != SecondsLeft)
|
||||||
|
{
|
||||||
|
SetHUDMatchCountdown(MatchTime - GetWorld()->GetTimeSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
CountdownInt = SecondsLeft;
|
||||||
|
}
|
||||||
|
|
||||||
void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
|
void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
|
||||||
{
|
{
|
||||||
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||||
|
@ -104,3 +123,21 @@ void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo)
|
||||||
BlasterHUD->CharacterOverlay->CarriedAmmoValue->SetText(FText::FromString(CarriedAmmoAmount));
|
BlasterHUD->CharacterOverlay->CarriedAmmoValue->SetText(FText::FromString(CarriedAmmoAmount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime)
|
||||||
|
{
|
||||||
|
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||||
|
bool bHUDValid =
|
||||||
|
BlasterHUD &&
|
||||||
|
BlasterHUD->CharacterOverlay &&
|
||||||
|
BlasterHUD->CharacterOverlay->MatchCountdownText;
|
||||||
|
|
||||||
|
if (bHUDValid)
|
||||||
|
{
|
||||||
|
int32 Minutes = FMath::FloorToInt(CountdownTime / 60);
|
||||||
|
int32 Seconds = CountdownTime - Minutes * 60;
|
||||||
|
|
||||||
|
const FString CountdownText = FString::Printf(TEXT("%02d:%02d"), Minutes, Seconds);
|
||||||
|
BlasterHUD->CharacterOverlay->MatchCountdownText->SetText(FText::FromString(CountdownText));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,20 +16,26 @@ class BLASTER_API ABlasterPlayerController : public APlayerController
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
virtual void OnPossess(APawn* InPawn) override;
|
||||||
|
|
||||||
void SetHUDHealth(float Health, float MaxHealth);
|
void SetHUDHealth(float Health, float MaxHealth);
|
||||||
void SetHUDScore(float Score);
|
void SetHUDScore(float Score);
|
||||||
void SetHUDDefeats(int32 Defeats);
|
void SetHUDDefeats(int32 Defeats);
|
||||||
void SetHUDWeaponAmmo(int32 Ammo);
|
void SetHUDWeaponAmmo(int32 Ammo);
|
||||||
void SetHUDCarriedAmmo(int32 Ammo);
|
void SetHUDCarriedAmmo(int32 Ammo);
|
||||||
virtual void OnPossess(APawn* InPawn) override;
|
void SetHUDMatchCountdown(float CountdownTime);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
void SetHUDTime();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
class ABlasterHUD* BlasterHUD;
|
class ABlasterHUD* BlasterHUD;
|
||||||
|
|
||||||
|
float MatchTime = 120.f;
|
||||||
|
uint32 CountdownInt = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue