Some basic boilerplate for win/lose states
This commit is contained in:
parent
549d4e590a
commit
1d964b289c
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/0/W3/BH9RA5CXGG4V6NBO45LIOY.uasset (Stored with Git LFS)
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/0/W3/BH9RA5CXGG4V6NBO45LIOY.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/2/YS/0MUVLSZG6FOQLXF4C5BDRV.uasset (Stored with Git LFS)
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/2/YS/0MUVLSZG6FOQLXF4C5BDRV.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/3/YJ/OD1NN2YHEXD84Z0IQ2F2Z8.uasset (Stored with Git LFS)
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/3/YJ/OD1NN2YHEXD84Z0IQ2F2Z8.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/7/UM/P713255HQHP0RVRQ5S9OSS.uasset (Stored with Git LFS)
Normal file
BIN
Content/__ExternalActors__/SideScroller/Maps/ExampleMap/7/UM/P713255HQHP0RVRQ5S9OSS.uasset (Stored with Git LFS)
Normal file
Binary file not shown.
|
@ -9,7 +9,9 @@
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "Default",
|
"LoadingPhase": "Default",
|
||||||
"AdditionalDependencies": [
|
"AdditionalDependencies": [
|
||||||
"SST"
|
"SST",
|
||||||
|
"AIModule",
|
||||||
|
"Engine"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "FighterAIController.h"
|
||||||
|
|
||||||
|
#include "FunnyPrinceCharacter.h"
|
||||||
|
#include "BehaviorTree/BlackboardComponent.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
void AFighterAIController::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
if (AIBehavior)
|
||||||
|
{
|
||||||
|
RunBehaviorTree(AIBehavior);
|
||||||
|
|
||||||
|
GetBlackboardComponent()->SetValueAsVector(TEXT("StartLocation"), GetPawn()->GetActorLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AFighterAIController::Tick(float DeltaSeconds)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AFighterAIController::IsDead() const
|
||||||
|
{
|
||||||
|
AFunnyPrinceCharacter* ControlledCharacter = Cast<AFunnyPrinceCharacter>(GetPawn());
|
||||||
|
if (ControlledCharacter)
|
||||||
|
{
|
||||||
|
return ControlledCharacter->IsDead();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "AIController.h"
|
||||||
|
#include "FighterAIController.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class FUNNYPRINCE_API AFighterAIController : public AAIController
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void Tick(float DeltaSeconds) override;
|
||||||
|
|
||||||
|
bool IsDead() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
class UBehaviorTree* AIBehavior;
|
||||||
|
};
|
|
@ -8,6 +8,6 @@ public class FunnyPrince : ModuleRules
|
||||||
{
|
{
|
||||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });
|
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "UMG" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "Engine/DamageEvents.h"
|
#include "Engine/DamageEvents.h"
|
||||||
#include "EnemyCharacter.h"
|
#include "EnemyCharacter.h"
|
||||||
|
#include "FunnyPrinceGameMode.h"
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
|
|
||||||
DEFINE_LOG_CATEGORY(LogTemplateFunnyPrinceCharacter);
|
DEFINE_LOG_CATEGORY(LogTemplateFunnyPrinceCharacter);
|
||||||
|
|
||||||
|
@ -46,6 +48,8 @@ void AFunnyPrinceCharacter::BeginPlay()
|
||||||
{
|
{
|
||||||
// Call the base class
|
// Call the base class
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
Health = MaxHealth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,14 +88,15 @@ float AFunnyPrinceCharacter::TakeDamage(float DamageAmount, FDamageEvent const&
|
||||||
{
|
{
|
||||||
Health = 0;
|
Health = 0;
|
||||||
|
|
||||||
/*ASimpleShooterGameModeBase* GameMode = GetWorld()->GetAuthGameMode<ASimpleShooterGameModeBase>();
|
AFunnyPrinceGameMode* GameMode = GetWorld()->GetAuthGameMode<AFunnyPrinceGameMode>();
|
||||||
if (GameMode)
|
if (GameMode)
|
||||||
{
|
{
|
||||||
GameMode->PawnKilled(this);
|
GameMode->PawnKilled(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
DetachFromControllerPendingDestroy();
|
DetachFromControllerPendingDestroy();
|
||||||
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);*/
|
GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
|
SetLifeSpan(0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
UE_LOG(LogTemp, Warning, TEXT("Actor hit for %f damage. Current HP: %f"), DamageToApply, Health);
|
UE_LOG(LogTemp, Warning, TEXT("Actor hit for %f damage. Current HP: %f"), DamageToApply, Health);
|
||||||
|
|
|
@ -29,6 +29,9 @@ public:
|
||||||
// To add mapping context
|
// To add mapping context
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
UFUNCTION(BlueprintPure)
|
||||||
|
bool IsDead() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// To add mapping context
|
// To add mapping context
|
||||||
|
@ -36,9 +39,6 @@ protected:
|
||||||
|
|
||||||
virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser) override;
|
virtual float TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, AActor* DamageCauser) override;
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure)
|
|
||||||
bool IsDead() const;
|
|
||||||
|
|
||||||
UFUNCTION(BlueprintPure)
|
UFUNCTION(BlueprintPure)
|
||||||
float GetHealthPercent() const;
|
float GetHealthPercent() const;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "FunnyPrinceController.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
|
||||||
|
void AFunnyPrinceController::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
HUD = CreateWidget(this, HUDClass);
|
||||||
|
if (HUD != nullptr)
|
||||||
|
{
|
||||||
|
HUD->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AFunnyPrinceController::GameHasEnded(AActor* EndGameFocus, bool bIsWinner)
|
||||||
|
{
|
||||||
|
Super::GameHasEnded(EndGameFocus, bIsWinner);
|
||||||
|
HUD->RemoveFromParent();
|
||||||
|
|
||||||
|
if (bIsWinner)
|
||||||
|
{
|
||||||
|
UUserWidget* WinScreen = CreateWidget(this, WinScreenClass);
|
||||||
|
if (WinScreen != nullptr)
|
||||||
|
{
|
||||||
|
WinScreen->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UUserWidget* LoseScreen = CreateWidget(this, LoseScreenClass);
|
||||||
|
if (LoseScreen != nullptr)
|
||||||
|
{
|
||||||
|
LoseScreen->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GetWorldTimerManager().SetTimer(RestartTimer, this, &APlayerController::RestartLevel, RestartDelay);
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/PlayerController.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
|
||||||
|
#include "FunnyPrinceController.generated.h"
|
||||||
|
|
||||||
|
class UUserWidget;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class FUNNYPRINCE_API AFunnyPrinceController : public APlayerController
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
virtual void GameHasEnded(class AActor* EndGameFocus = nullptr, bool bIsWinner = false) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
TSubclassOf<UUserWidget> HUDClass;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
TSubclassOf<UUserWidget> WinScreenClass;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
TSubclassOf<UUserWidget> LoseScreenClass;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
float RestartDelay = 5;
|
||||||
|
|
||||||
|
FTimerHandle RestartTimer;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
UUserWidget* HUD;
|
||||||
|
};
|
|
@ -2,8 +2,45 @@
|
||||||
|
|
||||||
#include "FunnyPrinceGameMode.h"
|
#include "FunnyPrinceGameMode.h"
|
||||||
#include "UObject/ConstructorHelpers.h"
|
#include "UObject/ConstructorHelpers.h"
|
||||||
|
#include "EngineUtils.h"
|
||||||
|
#include "FighterAIController.h"
|
||||||
|
|
||||||
AFunnyPrinceGameMode::AFunnyPrinceGameMode()
|
AFunnyPrinceGameMode::AFunnyPrinceGameMode()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AFunnyPrinceGameMode::PawnKilled(APawn* PawnKilled)
|
||||||
|
{
|
||||||
|
if (!PawnKilled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
APlayerController* PlayerController = Cast<APlayerController>(PawnKilled->GetController());
|
||||||
|
if (PlayerController)
|
||||||
|
{
|
||||||
|
PlayerController->GameHasEnded(nullptr, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for win condition
|
||||||
|
for (AFighterAIController* Controller : TActorRange<AFighterAIController>(GetWorld()))
|
||||||
|
{
|
||||||
|
if (!Controller->IsDead())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All AI is dead, game is won
|
||||||
|
EndGame(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AFunnyPrinceGameMode::EndGame(bool bIsPlayerWinner)
|
||||||
|
{
|
||||||
|
for (AController* Controller : TActorRange<AController>(GetWorld()))
|
||||||
|
{
|
||||||
|
bool bWon = (bIsPlayerWinner == Controller->IsPlayerController());
|
||||||
|
Controller->GameHasEnded(Controller->GetPawn(), bWon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,9 @@ class AFunnyPrinceGameMode : public AGameModeBase
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AFunnyPrinceGameMode();
|
AFunnyPrinceGameMode();
|
||||||
|
|
||||||
|
virtual void PawnKilled(APawn* PawnKilled);
|
||||||
|
void EndGame(bool bIsPlayerWinner);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue