diff --git a/Content/Assets/NormieAsset/Test_anim.uasset b/Content/Assets/NormieAsset/Test_anim.uasset index fff74e1..93894d5 100644 --- a/Content/Assets/NormieAsset/Test_anim.uasset +++ b/Content/Assets/NormieAsset/Test_anim.uasset Binary files differ diff --git a/Content/Levels/Sergio_Level.umap b/Content/Levels/Sergio_Level.umap index ae00ad7..408f47e 100644 --- a/Content/Levels/Sergio_Level.umap +++ b/Content/Levels/Sergio_Level.umap Binary files differ diff --git a/SkyFrontier.uproject b/SkyFrontier.uproject index 6003fa6..1e6d8c8 100644 --- a/SkyFrontier.uproject +++ b/SkyFrontier.uproject @@ -7,18 +7,16 @@ { "Name": "SkyFrontier", "Type": "Runtime", - "LoadingPhase": "Default" + "LoadingPhase": "Default", + "AdditionalDependencies": [ + "Engine" + ] } ], "Plugins": [ { "Name": "RawInput", "Enabled": true - }, - { - "Name": "UniversalCameraPlugin", - "Enabled": true, - "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/a9172fdfc87c464eae3a49860ee2610f" } ] } \ No newline at end of file diff --git a/Source/SkyFrontier/Private/HealthSystem.cpp b/Source/SkyFrontier/Private/HealthSystem.cpp new file mode 100644 index 0000000..aacb077 --- /dev/null +++ b/Source/SkyFrontier/Private/HealthSystem.cpp @@ -0,0 +1,64 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "HealthSystem.h" + +UHealthSystem::UHealthSystem() +{ + // This is a component that doesn't need a tick so lets disable it + PrimaryComponentTick.bCanEverTick = false; + PrimaryComponentTick.bStartWithTickEnabled = false; +} + +void UHealthSystem::BeginPlay() +{ + Super::BeginPlay(); + + // This is here for now, but if you ever do anything serialization related you might not want this. + Health = MaxHealth; +} + +float UHealthSystem::GetHealth() const +{ + return Health; +} + +float UHealthSystem::GetMaxHealth() const +{ + return MaxHealth; +} + +float UHealthSystem::GetHealthAsPercentage() const +{ + return Health / MaxHealth; +} + +void UHealthSystem::ModifyHealth(const float Amount) +{ + if(Amount == 0) + return; + + Health += Amount; + + Amount > 0 ? OnDamageHealedEvent.Broadcast(Amount) : OnDamageTakenEvent.Broadcast(Amount); +} + +void UHealthSystem::TakeDamage(const float Amount) +{ + if(Amount > 0) + { + Health -= Amount; + + OnDamageTakenEvent.Broadcast(Amount); + } +} + +void UHealthSystem::RecoverHealth(const float Amount) +{ + if(Amount > 0) + { + Health += Amount; + + OnDamageHealedEvent.Broadcast(Amount); + } +} \ No newline at end of file diff --git a/Source/SkyFrontier/Public/HealthSystem.h b/Source/SkyFrontier/Public/HealthSystem.h new file mode 100644 index 0000000..2e0e911 --- /dev/null +++ b/Source/SkyFrontier/Public/HealthSystem.h @@ -0,0 +1,52 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "HealthSystem.generated.h" + +DECLARE_EVENT_OneParam(UCPP_HealthComponent, DamageTakenEvent, float ) +DECLARE_EVENT_OneParam(UCPP_HealthComponent, HealDamageEvent, float ) + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class SKYFRONTIER_API UHealthSystem : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UHealthSystem(); + + UFUNCTION(BlueprintPure) + float GetHealth() const; + UFUNCTION(BlueprintPure) + float GetMaxHealth() const; + UFUNCTION(BlueprintPure) + float GetHealthAsPercentage() const; + + UFUNCTION(BlueprintCallable) + void ModifyHealth(float Amount); + + UFUNCTION(BlueprintCallable) + void TakeDamage(float Amount); + UFUNCTION(BlueprintCallable) + void RecoverHealth(float Amount); + +protected: // Functions + + virtual void BeginPlay() override; + +public: // Events + + DamageTakenEvent OnDamageTakenEvent; + HealDamageEvent OnDamageHealedEvent; + +private: // This can be protected if we want to subclass the Health Component + + UPROPERTY(VisibleAnywhere) + float Health; + UPROPERTY(EditAnywhere) + float MaxHealth; + +};