Skip to content

Commit

Permalink
BT96 The Observer Pattern.cmproj
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tristem committed Aug 4, 2016
1 parent e964687 commit d1d5464
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 1 deletion.
Binary file modified BattleTank/Content/Tank/Tank_BP.uasset
Binary file not shown.
Binary file modified BattleTank/Content/_Levels/BattleGround.umap
Binary file not shown.
2 changes: 1 addition & 1 deletion BattleTank/Source/BattleTank/Private/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ float ATank::TakeDamage(float DamageAmount, struct FDamageEvent const & DamageEv
CurrentHealth -= DamageToApply;
if (CurrentHealth <= 0)
{
UE_LOG(LogTemp, Warning, TEXT("Tank died"))
OnDeath.Broadcast();
}
return DamageToApply;
}
20 changes: 20 additions & 0 deletions BattleTank/Source/BattleTank/Private/TankAIController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,33 @@
#include "BattleTank.h"
#include "TankAimingComponent.h"
#include "TankAIController.h"
#include "Tank.h" // So we can impliment OnDeath

// Depends on movement component via pathfinding system

void ATankAIController::BeginPlay()
{
Super::BeginPlay();
}

void ATankAIController::SetPawn(APawn* InPawn)
{
Super::SetPawn(InPawn);
if (InPawn)
{
auto PossessedTank = Cast<ATank>(InPawn);
if (!ensure(PossessedTank)) { return; }

// Subscribe our local method to the tank's death event
PossessedTank->OnDeath.AddUniqueDynamic(this, &ATankAIController::OnPossedTankDeath);
}
}

void ATankAIController::OnPossedTankDeath()
{
UE_LOG(LogTemp, Warning, TEXT("Received!"))
}

// Called every frame
void ATankAIController::Tick(float DeltaTime)
{
Expand Down
4 changes: 4 additions & 0 deletions BattleTank/Source/BattleTank/Public/Tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "GameFramework/Pawn.h"
#include "Tank.generated.h" // Put new includes above

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FTankDelegate);

UCLASS()
class BATTLETANK_API ATank : public APawn
{
Expand All @@ -18,6 +20,8 @@ class BATTLETANK_API ATank : public APawn
UFUNCTION(BlueprintPure, Category = "Health")
float GetHealthPercent() const;

FTankDelegate OnDeath;

private:
// Sets default values for this pawn's properties
ATank();
Expand Down
5 changes: 5 additions & 0 deletions BattleTank/Source/BattleTank/Public/TankAIController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,10 @@ class BATTLETANK_API ATankAIController : public AAIController
private:
virtual void BeginPlay() override;

virtual void SetPawn(APawn* InPawn) override;

virtual void Tick(float DeltaSeconds) override;

UFUNCTION()
void OnPossedTankDeath();
};

0 comments on commit d1d5464

Please sign in to comment.