Section 16: Khaimera - Lecture 322

Health Pickup
This commit is contained in:
charnet3d 2024-03-12 03:38:53 +00:00
parent bb3f9f8e7d
commit 652d630ccb
71 changed files with 175 additions and 113 deletions

BIN
Content/Health/M_Pickup_Health.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Health/SM_Pickup_Health.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Assets/Sounds/Pickups/HealthPickupCue.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Assets/Sounds/Pickups/sw_Pickup_Ammo.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Assets/Sounds/Pickups/sw_Pickup_Health.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Enemies/EnemyBP.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/EnemyGruxBP.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Grux/Animations/GruxAttack.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Enemies/Grux/Animations/GruxDeath.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Enemies/Grux/Animations/GruxHit.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/GruxAnimBP.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/Death_B.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/Death_B_end.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/HS_Idle.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/Jog_Fwd.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/KhaimeraHit.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/Melee_A.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/Animations/Melee_B.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/EnemyKhaimeraBengalBP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Enemies/Khaimera/KhaimeraAnimBP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
Content/_Game/Health/HealthBP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -24,5 +24,5 @@ class SHOOTER_API IBulletHitInterface
public: public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable) UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
void BulletHit(FHitResult HitResult); void BulletHit(FHitResult HitResult, AActor* Shooter, AController* ShooterController);
}; };

View File

@ -209,6 +209,8 @@ void AEnemy::AgroSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor*
if (!Character) return; if (!Character) return;
// Set the value of the Target blackboard key // Set the value of the Target blackboard key
if (!EnemyController) return;
if (!EnemyController->GetBlackboardComponent()) return;
EnemyController->GetBlackboardComponent()->SetValueAsObject(TEXT("Target"), Character); EnemyController->GetBlackboardComponent()->SetValueAsObject(TEXT("Target"), Character);
} }
@ -385,7 +387,7 @@ void AEnemy::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
} }
void AEnemy::BulletHit_Implementation(FHitResult HitResult) void AEnemy::BulletHit_Implementation(FHitResult HitResult, AActor* Shooter, AController* ShooterController)
{ {
if (ImpactSound) if (ImpactSound)
{ {
@ -396,19 +398,6 @@ void AEnemy::BulletHit_Implementation(FHitResult HitResult)
{ {
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, HitResult.Location, FRotator(0.f), true); UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ImpactParticles, HitResult.Location, FRotator(0.f), true);
} }
if (bDying) return;
ShowHealthBar();
// Determine whether bullet hit stuns
const float Stunned = FMath::FRandRange(0.f, 1.f);
if (Stunned <= StunChance)
{
// Stun the Enemy
PlayHitMontage(FName("HitReactFront"));
SetStunned(true);
}
} }
float AEnemy::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, float AEnemy::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator,
@ -431,6 +420,20 @@ float AEnemy::TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AC
{ {
Health -= DamageAmount; Health -= DamageAmount;
} }
if (bDying) return DamageInflicted;
ShowHealthBar();
// Determine whether bullet hit stuns
const float Stunned = FMath::FRandRange(0.f, 1.f);
if (Stunned <= StunChance)
{
// Stun the Enemy
PlayHitMontage(FName("HitReactFront"));
SetStunned(true);
}
return DamageInflicted; return DamageInflicted;
} }

View File

@ -249,7 +249,7 @@ public:
// Called to bind functionality to input // Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
virtual void BulletHit_Implementation(FHitResult HitResult) override; virtual void BulletHit_Implementation(FHitResult HitResult, AActor* Shooter, AController* ShooterController) override;
virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override; virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;

View File

@ -2,16 +2,25 @@
#include "Explosive.h" #include "Explosive.h"
#include "Components/SphereComponent.h"
#include "GameFramework/Character.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
#include "Sound/SoundCue.h" #include "Sound/SoundCue.h"
#include "Particles/ParticleSystemComponent.h" #include "Particles/ParticleSystemComponent.h"
// Sets default values // Sets default values
AExplosive::AExplosive() AExplosive::AExplosive() :
Damage(40.f)
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
ExplosiveMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ExplosiveMesh"));
SetRootComponent(ExplosiveMesh);
OverlapSphere = CreateDefaultSubobject<USphereComponent>(TEXT("OverlapSphere"));
OverlapSphere->SetupAttachment(GetRootComponent());
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -28,7 +37,7 @@ void AExplosive::Tick(float DeltaTime)
} }
void AExplosive::BulletHit_Implementation(FHitResult HitResult) void AExplosive::BulletHit_Implementation(FHitResult HitResult, AActor* Shooter, AController* ShooterController)
{ {
if (ExplosionSound) if (ExplosionSound)
{ {
@ -40,7 +49,14 @@ void AExplosive::BulletHit_Implementation(FHitResult HitResult)
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticles, HitResult.Location, FRotator(0.f), true); UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionParticles, HitResult.Location, FRotator(0.f), true);
} }
// TODO: Apply explosive damage // Apply explosive damage
TArray<AActor*> OverlappingActors;
GetOverlappingActors(OverlappingActors, ACharacter::StaticClass());
for (auto Actor : OverlappingActors)
{
UGameplayStatics::ApplyDamage(Actor, Damage, ShooterController, Shooter, UDamageType::StaticClass());
}
Destroy(); Destroy();
} }

View File

@ -9,6 +9,8 @@
class UParticleSystem; class UParticleSystem;
class USoundCue; class USoundCue;
class USphereComponent;
class UStaticMeshComponent;
UCLASS() UCLASS()
class SHOOTER_API AExplosive : public AActor, public IBulletHitInterface class SHOOTER_API AExplosive : public AActor, public IBulletHitInterface
@ -33,9 +35,20 @@ private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
USoundCue* ExplosionSound; USoundCue* ExplosionSound;
/** Mesh for the explosive */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Combat, meta = (AllowPrivateAccess = true))
UStaticMeshComponent* ExplosiveMesh;
/** Used to determine what actors overlap during explosion */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
USphereComponent* OverlapSphere;
/** Damage amount for explosive */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
float Damage;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
virtual void BulletHit_Implementation(FHitResult HitResult) override; virtual void BulletHit_Implementation(FHitResult HitResult, AActor* Shooter, AController* ShooterController) override;
}; };

View File

@ -766,7 +766,7 @@ void AShooterCharacter::SendBullet()
{ {
if (IBulletHitInterface* BulletHitInterface = Cast<IBulletHitInterface>(BeamHitResult.GetActor())) if (IBulletHitInterface* BulletHitInterface = Cast<IBulletHitInterface>(BeamHitResult.GetActor()))
{ {
BulletHitInterface->BulletHit_Implementation(BeamHitResult); BulletHitInterface->BulletHit_Implementation(BeamHitResult, this, GetController());
} }
else else
{ {