Compare commits

...

2 Commits

Author SHA1 Message Date
baz 619c82bd01 Add basic Garlic weapon 2024-06-19 02:29:19 +01:00
baz 6e24728a8b uhhh 2024-06-19 02:29:05 +01:00
4 changed files with 86 additions and 5 deletions

BIN
Content/Enemy/BT_Enemy.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -7,6 +7,7 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputMappingContext.h"
#include "Kismet/GameplayStatics.h"
APlayerCharacter::APlayerCharacter()
{
@ -29,11 +30,20 @@ APlayerCharacter::APlayerCharacter()
// Create EXP Component
EXPComponent = CreateDefaultSubobject<UEXPComponent>(TEXT("EXP Component"));
// Create Garlic Sphere Component
GarlicSphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Garlic Sphere Component"));
GarlicSphereComponent->SetupAttachment(RootComponent);
GarlicSphereComponent->SetSphereRadius(150.0f);
}
void APlayerCharacter::BeginPlay()
{
Super::BeginPlay();
GarlicSphereComponent->OnComponentBeginOverlap.AddDynamic(this, &APlayerCharacter::OnGarlicBeginOverlap);
GarlicSphereComponent->OnComponentEndOverlap.AddDynamic(this, &APlayerCharacter::OnGarlicEndOverlap);
GetWorldTimerManager().SetTimer(GarlicTimerHandle, this, &APlayerCharacter::GarlicUpdate, GarlicUpdateTime, true);
}
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
@ -71,3 +81,46 @@ void APlayerCharacter::MovementCallback(const FInputActionInstance& Instance)
AddMovementInput({1.0f, 0.0f, 0.0f}, vec2.X);
}
}
void APlayerCharacter::OnGarlicBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Add(Enemy);
}
}
void APlayerCharacter::OnGarlicEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Remove(Enemy);
}
}
void APlayerCharacter::GarlicUpdate()
{
for (int i = 0; i < OverlappedEnemies.Num(); i++)
{
bool deadCheck = false;
UHealthComponent* EnemyHealthComponent = OverlappedEnemies[i]->GetHealthComponent();
if (!EnemyHealthComponent->GetIsDead())
{
if (EnemyHealthComponent->GetCurrentHealth() < GarlicDamage)
{
deadCheck = true;
}
EnemyHealthComponent->TakeDamage(OverlappedEnemies[i], GarlicDamage, nullptr, GetController(), this);
}
if (deadCheck)
{
i -= 1;
}
}
}

View File

@ -3,9 +3,11 @@
#pragma once
#include "CoreMinimal.h"
#include "EnemyCharacter.h"
#include "EXPComponent.h"
#include "VampireCharacter.h"
#include "Camera/CameraComponent.h"
#include "Components/SphereComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "PlayerCharacter.generated.h"
@ -33,11 +35,25 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* MovementAction;
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float GarlicDamage = 51.0f;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float GarlicUpdateTime = 1.0f;
protected:
UPROPERTY()
UEXPComponent* EXPComponent;
UPROPERTY(VisibleAnywhere)
USphereComponent* GarlicSphereComponent;
UPROPERTY()
TArray<AEnemyCharacter*> OverlappedEnemies;
private:
FTimerHandle GarlicTimerHandle;
public:
APlayerCharacter();
@ -50,4 +66,16 @@ public:
private:
UFUNCTION()
void MovementCallback(const FInputActionInstance& Instance);
UFUNCTION()
void OnGarlicBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult);
UFUNCTION()
void OnGarlicEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
UFUNCTION()
void GarlicUpdate();
};