Created
November 20, 2017 18:34
-
-
Save LeviVisser/16135fe7efa48fcae4003f7617706dec to your computer and use it in GitHub Desktop.
Tank.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Tank.h" | |
#include "Engine.h" | |
// Sets default values | |
ATank::ATank() | |
{ | |
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it. | |
PrimaryActorTick.bCanEverTick = false; | |
} | |
void ATank::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
CurrentHealth = StartingHealth; | |
} | |
float ATank::GetHealthPercent() const | |
{ | |
return (float)CurrentHealth / (float)StartingHealth; | |
} | |
float ATank::TakeDamage(float DamageAmount, struct FDamageEvent const & DamageEvent, class AController* EvemtInstigatpr, AActor* DamageCauser) | |
{ | |
int32 DamagePoints = FPlatformMath::RoundToInt(DamageAmount); | |
int32 DamageToApply = FMath::Clamp(DamagePoints, 0, CurrentHealth); | |
CurrentHealth -= DamageToApply; | |
if (CurrentHealth <= 0) | |
{ | |
OnDeath.Broadcast(); | |
} | |
return DamageToApply; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment