Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "FPS2.h"
  4. #include "BaseCharacter_C.h"
  5.  
  6.  
  7. // Sets default values
  8. ABaseCharacter_C::ABaseCharacter_C()
  9. {
  10.     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
  11.     PrimaryActorTick.bCanEverTick = true;
  12.  
  13. }
  14.  
  15. // Called when the game starts or when spawned
  16. void ABaseCharacter_C::BeginPlay()
  17. {
  18.     Super::BeginPlay();
  19.  
  20. }
  21.  
  22. // Called every frame
  23. void ABaseCharacter_C::Tick(float DeltaTime)
  24. {
  25.     Super::Tick(DeltaTime);
  26.  
  27. }
  28.  
  29. // Called to bind functionality to input
  30. void ABaseCharacter_C::SetupPlayerInputComponent(class UInputComponent* InputComponent)
  31. {
  32.     Super::SetupPlayerInputComponent(InputComponent);
  33.  
  34. }
  35.  
  36. ///////////////////////////////////////////////////
  37.  
  38. //Step 1: Implement the CalculateHealth function.
  39. void ABaseCharacter_C::CalculateHealth(float Delta)
  40. {
  41.     Health += Delta;
  42.     Health = FMath::Clamp(Health, 0.0f, HealthMax);
  43.    
  44.     HealthPerc = Health / HealthMax;
  45.  
  46.     CalculateDead();
  47. }
  48.  
  49. //Step 2: Implement the CalculateDead function.
  50. void ABaseCharacter_C::CalculateDead()
  51. {
  52.     if (Health <= 0)
  53.     {
  54.         IsDead = true;
  55.         OnDeath_Implementation();
  56.     }
  57.     else
  58.     {
  59.         IsDead = false;
  60.     }
  61. }
  62.  
  63. void ABaseCharacter_C::Kill()
  64. {
  65.     CalculateHealth(-Health);
  66. }
  67.  
  68. void ABaseCharacter_C::OnDeath_Implementation(){}
  69.  
  70. #if WITH_EDITOR
  71. //Step 3: Implement the remainder of our helper code, used by the editor when we change values.
  72. void ABaseCharacter_C::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
  73. {
  74.     IsDead = false;
  75.     Health = 100;
  76.  
  77.     Super::PostEditChangeProperty(PropertyChangedEvent);
  78.  
  79.     CalculateDead();
  80. }
  81. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement