Player Dies oof

This commit is contained in:
Rafal 2024-12-08 23:54:09 +00:00
parent 0113c6c958
commit 620d480dc0
8 changed files with 52 additions and 8 deletions

BIN
Content/Enemies/Small/BP_SmallEnemy.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Enemies/Small/BTT_Attack.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Enemies/Small/BT_SmallEnemy.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/PrototypeLevel.umap (Stored with Git LFS)

Binary file not shown.

BIN
Content/Monolith/UI/WBP_Died.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -46,6 +46,7 @@ void AMonolithCharacter::BeginPlay()
// Call the base class // Call the base class
Super::BeginPlay(); Super::BeginPlay();
MaxHealth = Health;
Mesh1P = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass())); Mesh1P = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
CharMove = Cast<UCharacterMovementComponent>(GetComponentByClass(UCharacterMovementComponent::StaticClass())); CharMove = Cast<UCharacterMovementComponent>(GetComponentByClass(UCharacterMovementComponent::StaticClass()));
if (CharMove) WalkSpeed = CharMove->MaxWalkSpeed; if (CharMove) WalkSpeed = CharMove->MaxWalkSpeed;
@ -122,6 +123,19 @@ static void UpdateMoveState(FMoveState& MoveState, int Forwards, int Sideways)
} }
} }
void AMonolithCharacter::IncrementHealth(float amount)
{
Health += amount;
if (Health > MaxHealth)
{
Health = MaxHealth;
}
else if (Health <= 0)
{
Died();
}
}
void AMonolithCharacter::Move(const FInputActionValue& Value) void AMonolithCharacter::Move(const FInputActionValue& Value)
{ {
// input is a Vector2D // input is a Vector2D

View File

@ -59,6 +59,11 @@ class AMonolithCharacter : public ACharacter
UPROPERTY(EditAnywhere, Category = "MoveState", meta=(AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, Category = "MoveState", meta=(AllowPrivateAccess = "true"))
float DashImpulse = 600.f; float DashImpulse = 600.f;
UPROPERTY(EditDefaultsOnly, Category = "Health", meta=(AllowPrivateAccess = "true"))
float Health = 100.f;
float MaxHealth;
USkeletalMeshComponent* Mesh1P; USkeletalMeshComponent* Mesh1P;
UCharacterMovementComponent* CharMove; UCharacterMovementComponent* CharMove;
@ -70,6 +75,25 @@ protected:
void BeginPlay(); void BeginPlay();
void Tick(float DeltaSeconds) override; void Tick(float DeltaSeconds) override;
UFUNCTION(BlueprintCallable)
float GetHealth()
{
return Health;
}
UFUNCTION(BlueprintCallable)
void ResetHealth()
{
Health = MaxHealth;
}
// Increase/Decrease health by this amount, will handle death
UFUNCTION(BlueprintCallable)
void IncrementHealth(float amount);
UFUNCTION(BlueprintImplementableEvent)
void Died();
/** Called for movement input */ /** Called for movement input */
void Move(const FInputActionValue& Value); void Move(const FInputActionValue& Value);
void StopMove(); void StopMove();