107 - Blaster Player State
This commit is contained in:
parent
e478e0d433
commit
4261cd8f0d
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -7,6 +7,7 @@
|
|||
#include "Blaster/Components/CombatComponent.h"
|
||||
#include "Blaster/GameMode/BlasterGameMode.h"
|
||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||
#include "Blaster/PlayerState/BlasterPlayerState.h"
|
||||
#include "Blaster/Weapon/Weapon.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
|
@ -238,6 +239,20 @@ void ABlasterCharacter::Tick(float DeltaTime)
|
|||
}
|
||||
|
||||
HideCameraIfCharacterClose();
|
||||
PollInit();
|
||||
}
|
||||
|
||||
void ABlasterCharacter::PollInit()
|
||||
{
|
||||
if (PlayerState == nullptr)
|
||||
{
|
||||
PlayerState = GetPlayerState<ABlasterPlayerState>();
|
||||
if (PlayerState)
|
||||
{
|
||||
// Initialize Score now we have the PlayerState
|
||||
PlayerState->IncreaseScore(0.f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
|
|
|
@ -53,8 +53,12 @@ protected:
|
|||
UFUNCTION()
|
||||
void ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, class AController* InstigatorController, AActor* DamageCauser);
|
||||
void UpdateHUDHealth();
|
||||
// Poll for any relevant classes and initialize them
|
||||
void PollInit();
|
||||
|
||||
private:
|
||||
class ABlasterPlayerState* PlayerState;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, Category="Camera")
|
||||
class USpringArmComponent* CameraBoom;
|
||||
|
||||
|
|
|
@ -4,12 +4,22 @@
|
|||
#include "BlasterGameMode.h"
|
||||
|
||||
#include "Blaster/Character/BlasterCharacter.h"
|
||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||
#include "Blaster/PlayerState/BlasterPlayerState.h"
|
||||
#include "GameFramework/PlayerStart.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController,
|
||||
ABlasterPlayerController* AttackerController)
|
||||
{
|
||||
ABlasterPlayerState* AttackerPlayerState = AttackerController ? Cast<ABlasterPlayerState>(AttackerController->PlayerState) : nullptr;
|
||||
ABlasterPlayerState* VictimPlayerState = VictimController ? Cast<ABlasterPlayerState>(VictimController->PlayerState) : nullptr;
|
||||
|
||||
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState)
|
||||
{
|
||||
AttackerPlayerState->IncreaseScore(1.f);
|
||||
}
|
||||
|
||||
if (EliminatedCharacter)
|
||||
{
|
||||
EliminatedCharacter->Eliminated();
|
||||
|
|
|
@ -22,4 +22,7 @@ public:
|
|||
UPROPERTY(meta = (BindWidget))
|
||||
class UTextBlock* HealthText;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
UTextBlock* ScoreValue;
|
||||
|
||||
};
|
||||
|
|
|
@ -44,3 +44,18 @@ void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
|
|||
BlasterHUD->CharacterOverlay->HealthText->SetText(FText::FromString(HealthText));
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::SetHUDScore(float Score)
|
||||
{
|
||||
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||
bool bHUDValid =
|
||||
BlasterHUD &&
|
||||
BlasterHUD->CharacterOverlay &&
|
||||
BlasterHUD->CharacterOverlay->ScoreValue;
|
||||
|
||||
if (bHUDValid)
|
||||
{
|
||||
const FString ScoreValue = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score));
|
||||
BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreValue));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ class BLASTER_API ABlasterPlayerController : public APlayerController
|
|||
public:
|
||||
|
||||
void SetHUDHealth(float Health, float MaxHealth);
|
||||
void SetHUDScore(float Score);
|
||||
virtual void OnPossess(APawn* InPawn) override;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "BlasterPlayerState.h"
|
||||
|
||||
#include "Blaster/Character/BlasterCharacter.h"
|
||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||
|
||||
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
|
||||
{
|
||||
SetScore(GetScore() + ScoreAmount);
|
||||
|
||||
Character = GetCharacter();
|
||||
if (Character)
|
||||
{
|
||||
Controller = GetController();
|
||||
if (Controller)
|
||||
{
|
||||
Controller->SetHUDScore(GetScore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerState::OnRep_Score()
|
||||
{
|
||||
Super::OnRep_Score();
|
||||
|
||||
Character = GetCharacter();
|
||||
if (Character)
|
||||
{
|
||||
Controller = GetController();
|
||||
if (Controller)
|
||||
{
|
||||
Controller->SetHUDScore(GetScore());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ABlasterCharacter* ABlasterPlayerState::GetCharacter() const
|
||||
{
|
||||
return Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
||||
}
|
||||
|
||||
ABlasterPlayerController* ABlasterPlayerState::GetController() const
|
||||
{
|
||||
if (Character)
|
||||
{
|
||||
return Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerState.h"
|
||||
#include "BlasterPlayerState.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class BLASTER_API ABlasterPlayerState : public APlayerState
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void OnRep_Score() override;
|
||||
void IncreaseScore(float ScoreAmount);
|
||||
|
||||
private:
|
||||
class ABlasterCharacter* Character;
|
||||
class ABlasterPlayerController* Controller;
|
||||
ABlasterCharacter* GetCharacter() const;
|
||||
ABlasterPlayerController* GetController() const;
|
||||
};
|
Loading…
Reference in New Issue