diff --git a/Content/maps/test_map.umap b/Content/maps/test_map.umap index 884d35a..7a6dd97 100644 Binary files a/Content/maps/test_map.umap and b/Content/maps/test_map.umap differ diff --git a/Source/WBIF/Private/PlayerCharacter.cpp b/Source/WBIF/Private/PlayerCharacter.cpp index bc89947..656f121 100644 --- a/Source/WBIF/Private/PlayerCharacter.cpp +++ b/Source/WBIF/Private/PlayerCharacter.cpp @@ -2,6 +2,8 @@ #include "PlayerCharacter.h" +#include "TimerManager.h" + // Sets default values @@ -20,6 +22,7 @@ APlayerCharacter::APlayerCharacter() camera->SetupAttachment(SpringArmComponent); isPlayAnimRepair = false; crushedItem = nullptr; + isStaminaDecreace = false; } // Called when the game starts or when spawned @@ -63,6 +66,11 @@ void APlayerCharacter::moveFD(float value) { const FVector Forward = FVector(1, 0, 0); AddMovementInput(Forward, value); + if (isStaminaDecreace != true) + { + isStaminaDecreace = !isStaminaDecreace; + GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false); + } } } @@ -72,27 +80,41 @@ void APlayerCharacter::moveRL(float value) { const FVector Right = FVector(0, 1, 0); AddMovementInput(Right, value); + if(isStaminaDecreace != true) + { + isStaminaDecreace = !isStaminaDecreace; + GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false); + } + } } void APlayerCharacter::moveFrontOn() { - staminaDecreace(); + //isStaminaDecreace = !isStaminaDecreace; + //GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false); + //staminaDecreace(); } void APlayerCharacter::moveBackOn() { - staminaDecreace(); + isStaminaDecreace = !isStaminaDecreace; + GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, true); + //staminaDecreace(); } void APlayerCharacter::moveRightOn() { - staminaDecreace(); + //isStaminaDecreace = !isStaminaDecreace; + //GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false); + //staminaDecreace(); } void APlayerCharacter::moveLeftOn() { - staminaDecreace(); + //isStaminaDecreace = !isStaminaDecreace; + //GetWorldTimerManager().SetTimer(TimerForStamina, this, &APlayerCharacter::staminaDecreace, 0.5f, false); + //staminaDecreace(); } void APlayerCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, @@ -175,10 +197,12 @@ void APlayerCharacter::repairStart() void APlayerCharacter::staminaDecreace() { - if(gameInstance->getCurrentStamina() >= 0) + GetWorldTimerManager().ClearTimer(TimerForStamina); + if(gameInstance->getCurrentStamina() >= 0 && isStaminaDecreace) { - gameInstance->setCurrentStamina(FMath::Clamp(gameInstance->getCurrentStamina() - 0.3, 0.0f, + gameInstance->setCurrentStamina(FMath::Clamp(gameInstance->getCurrentStamina() - 0.1f, 0.0f, gameInstance->getMaxStamina())); + isStaminaDecreace = !isStaminaDecreace; }else { // animation sleep diff --git a/Source/WBIF/Public/PlayerCharacter.h b/Source/WBIF/Public/PlayerCharacter.h index 99a32c6..ada16f7 100644 --- a/Source/WBIF/Public/PlayerCharacter.h +++ b/Source/WBIF/Public/PlayerCharacter.h @@ -75,6 +75,10 @@ protected: float MaxStaminaStamina; UPROPERTY(EditAnywhere, Category = "Data") UWBIFGameInstance* gameInstance; + UPROPERTY() + bool isStaminaDecreace; + UPROPERTY() + FTimerHandle TimerForStamina;