Update Character for Johns Hunger Mechanic
This commit is contained in:
parent
4952fff6c1
commit
9e2fe3c0f5
@ -53,6 +53,19 @@ ASeagullGameCharacter::ASeagullGameCharacter()
|
||||
void ASeagullGameCharacter::Tick(float DeltaSeconds)
|
||||
{
|
||||
Super::Tick(DeltaSeconds);
|
||||
|
||||
if (JohnsCurrentHunger > 0)
|
||||
{
|
||||
JohnsCurrentHunger -= DeltaSeconds * JohnsHungerDeclineAmount;
|
||||
}
|
||||
else if (!bHasGameEnded)
|
||||
{
|
||||
JohnsCurrentHunger = 0;
|
||||
OnGameEnd.Broadcast("You Lose!");
|
||||
bHasGameEnded = true;
|
||||
}
|
||||
|
||||
|
||||
if (!IsValid(PickupBox)) return;
|
||||
|
||||
TArray<AActor*> OverlappingActors;
|
||||
@ -96,10 +109,13 @@ void ASeagullGameCharacter::BeginPlay()
|
||||
void ASeagullGameCharacter::DamagePlayer(float DamageAmount)
|
||||
{
|
||||
CurrentHealth -= DamageAmount;
|
||||
OnPlayerDamage.Broadcast();
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
CurrentHealth = 0;
|
||||
OnPlayerDeath.Broadcast();
|
||||
OnGameEnd.Broadcast("You Lose!");
|
||||
bHasGameEnded = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,6 +130,7 @@ void ASeagullGameCharacter::HealPlayer(float HealAmount)
|
||||
|
||||
void ASeagullGameCharacter::StartGame()
|
||||
{
|
||||
JohnsCurrentHunger = JohnsDefaultHunger;
|
||||
if (GetWorld()->GetTimerManager().IsTimerActive(GameTimerHandle))
|
||||
{
|
||||
GetWorld()->GetTimerManager().ClearTimer(GameTimerHandle);
|
||||
@ -123,7 +140,7 @@ void ASeagullGameCharacter::StartGame()
|
||||
|
||||
void ASeagullGameCharacter::EndGame()
|
||||
{
|
||||
OnGameEnd.Broadcast();
|
||||
OnGameEnd.Broadcast("You Win!");
|
||||
}
|
||||
|
||||
void ASeagullGameCharacter::PickupItem()
|
||||
@ -171,6 +188,15 @@ void ASeagullGameCharacter::OnPickupBoxEndOverlap(UPrimitiveComponent* Overlappe
|
||||
}
|
||||
}
|
||||
|
||||
void ASeagullGameCharacter::IncreaseJohnsHunger(float HungerAmount)
|
||||
{
|
||||
JohnsCurrentHunger += HungerAmount;
|
||||
if (JohnsCurrentHunger > JohnsMaxHunger)
|
||||
{
|
||||
JohnsCurrentHunger = JohnsMaxHunger;
|
||||
}
|
||||
}
|
||||
|
||||
void ASeagullGameCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
// Set up action bindings
|
||||
|
@ -17,8 +17,12 @@ class ASeagullGameCharacter : public ACharacter
|
||||
public:
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerDeath);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnGameEnd);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnPlayerDamage);
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnGameEnd, FString, Message);
|
||||
|
||||
UPROPERTY(BlueprintAssignable, Category = "Events")
|
||||
FOnPlayerDeath OnPlayerDamage;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Events")
|
||||
FOnPlayerDeath OnPlayerDeath;
|
||||
UPROPERTY(BlueprintAssignable, Category = "Events")
|
||||
@ -58,7 +62,7 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||
float MaxHealth = 100;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||
float CurrentHealth;
|
||||
float CurrentHealth = 100;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health")
|
||||
float DefaultHealth = 100;
|
||||
|
||||
@ -75,6 +79,8 @@ public:
|
||||
FTimerHandle GameTimerHandle;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "General")
|
||||
float GameTime = 120;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "General")
|
||||
float Score = 0;
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category = "Item")
|
||||
void PickupItem();
|
||||
@ -93,6 +99,17 @@ public:
|
||||
UPROPERTY(BlueprintReadOnly, Category = "Item")
|
||||
UBoxComponent* PickupBox;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "John")
|
||||
float JohnsCurrentHunger = 0;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "John")
|
||||
float JohnsDefaultHunger = 100;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "John")
|
||||
float JohnsMaxHunger = 200;
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "John")
|
||||
float JohnsHungerDeclineAmount = 10.f;
|
||||
UFUNCTION(BlueprintCallable, Category = "John")
|
||||
void IncreaseJohnsHunger(float HungerAmount);
|
||||
|
||||
protected:
|
||||
// APawn interface
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
@ -110,4 +127,6 @@ private:
|
||||
/** Camera boom positioning the camera above the character */
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class USpringArmComponent* CameraBoom;
|
||||
|
||||
bool bHasGameEnded = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user