Create and Add SwarmAgents to SwarmWeapon
This commit is contained in:
parent
5adafd6519
commit
293d0ae8b2
BIN
Content/Weapons/Swarm/BP_SwarmActor.uasset
(Stored with Git LFS)
BIN
Content/Weapons/Swarm/BP_SwarmActor.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Weapons/Swarm/BP_SwarmAgent.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Weapons/Swarm/BP_SwarmAgent.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Weapons/Swarm/BP_SwarmWeapon.uasset
(Stored with Git LFS)
BIN
Content/Weapons/Swarm/BP_SwarmWeapon.uasset
(Stored with Git LFS)
Binary file not shown.
55
Source/vampires/Weapons/SwarmAgent.cpp
Normal file
55
Source/vampires/Weapons/SwarmAgent.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
|
||||
#include "SwarmAgent.h"
|
||||
|
||||
#include "Components/SphereComponent.h"
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
#include "vampires/HealthComponent.h"
|
||||
#include "vampires/Weapon.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
ASwarmAgent::ASwarmAgent()
|
||||
{
|
||||
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
|
||||
SetRootComponent(SphereComponent);
|
||||
SphereComponent->SetSphereRadius(50.0f);
|
||||
SphereComponent->SetCollisionProfileName(TEXT("Weapon"));
|
||||
|
||||
StaticMeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Static Mesh Component"));
|
||||
StaticMeshComponent->AttachToComponent(SphereComponent, FAttachmentTransformRules::KeepRelativeTransform);
|
||||
StaticMeshComponent->SetEnableGravity(false);
|
||||
StaticMeshComponent->SetGenerateOverlapEvents(false);
|
||||
StaticMeshComponent->SetCollisionProfileName(TEXT("NoCollision"));
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ASwarmAgent::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &ASwarmAgent::OnSwarmAgentBeginOverlap);
|
||||
}
|
||||
|
||||
void ASwarmAgent::OnSwarmAgentBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult)
|
||||
{
|
||||
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
|
||||
{
|
||||
UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent();
|
||||
|
||||
if (!EnemyHealthComponent->GetIsDead())
|
||||
{
|
||||
AController* ownerController = nullptr;
|
||||
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
|
||||
{
|
||||
ownerController = character->GetController();
|
||||
}
|
||||
|
||||
AWeapon* ownerWeapon = Cast<AWeapon>(GetOwner());
|
||||
EnemyHealthComponent->TakeDamage(Enemy, ownerWeapon->Damage, nullptr, ownerController, this);
|
||||
}
|
||||
}
|
||||
}
|
35
Source/vampires/Weapons/SwarmAgent.h
Normal file
35
Source/vampires/Weapons/SwarmAgent.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "SwarmAgent.generated.h"
|
||||
|
||||
class USphereComponent;
|
||||
|
||||
UCLASS()
|
||||
class VAMPIRES_API ASwarmAgent : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
USphereComponent* SphereComponent = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UStaticMeshComponent* StaticMeshComponent = nullptr;
|
||||
|
||||
// Sets default values for this actor's properties
|
||||
ASwarmAgent();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
UFUNCTION()
|
||||
void OnSwarmAgentBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
|
||||
const FHitResult& SweepResult);
|
||||
};
|
@ -3,10 +3,7 @@
|
||||
|
||||
#include "SwarmWeapon.h"
|
||||
|
||||
#include "VectorTypes.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
|
||||
#include "SwarmAgent.h"
|
||||
|
||||
// Sets default values
|
||||
ASwarmWeapon::ASwarmWeapon()
|
||||
@ -30,8 +27,8 @@ void ASwarmWeapon::BeginPlay()
|
||||
Super::BeginPlay();
|
||||
|
||||
// Spawn the swarm actors in
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SpawnSwarmAgent();
|
||||
SpawnSwarmAgent();
|
||||
|
||||
// Start the timeline
|
||||
if (SwarmCurve != nullptr)
|
||||
@ -41,7 +38,6 @@ void ASwarmWeapon::BeginPlay()
|
||||
|
||||
TimelineComponent->SetPlayRate(TimelinePlayRate);
|
||||
TimelineComponent->PlayFromStart();
|
||||
|
||||
}
|
||||
|
||||
void ASwarmWeapon::TimelineCallback(float val)
|
||||
@ -56,38 +52,42 @@ void ASwarmWeapon::TimelineCallback(float val)
|
||||
FVector Direction = FVector(0.0, 1, 0.0);
|
||||
FVector RotatedDirection = Direction.RotateAngleAxis(val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f));
|
||||
FVector NewLocation = CenterLocation + (RotatedDirection * Distance);
|
||||
NewLocation.Z = 140.0f;
|
||||
SwarmActors[i]->SetActorLocation(NewLocation);
|
||||
}
|
||||
}
|
||||
|
||||
bool ASwarmWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
if (!Super::UpgradeWeapon_Implementation())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
case 1:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SpawnSwarmAgent();
|
||||
break;
|
||||
case 2:
|
||||
Distance *= 1.25f;
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
break;
|
||||
case 3:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 4:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SpawnSwarmAgent();
|
||||
break;
|
||||
case 5:
|
||||
Distance *= 1.25f;
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
break;
|
||||
case 6:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 7:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SpawnSwarmAgent();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -97,3 +97,9 @@ bool ASwarmWeapon::UpgradeWeapon_Implementation()
|
||||
return true;
|
||||
}
|
||||
|
||||
void ASwarmWeapon::SpawnSwarmAgent()
|
||||
{
|
||||
ASwarmAgent* newAgent = GetWorld()->SpawnActor<ASwarmAgent>(SwarmActor, GetActorLocation() / 2, FRotator(0, 0, 0));
|
||||
newAgent->SetOwner(this);
|
||||
SwarmActors.Add(newAgent);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "vampires/Weapon.h"
|
||||
#include "SwarmWeapon.generated.h"
|
||||
|
||||
class ASwarmAgent;
|
||||
|
||||
UCLASS()
|
||||
class VAMPIRES_API ASwarmWeapon : public AWeapon
|
||||
{
|
||||
@ -15,26 +17,24 @@ class VAMPIRES_API ASwarmWeapon : public AWeapon
|
||||
public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline")
|
||||
TObjectPtr<UTimelineComponent> TimelineComponent = nullptr;
|
||||
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TObjectPtr<UCurveFloat> SwarmCurve;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
float TimelinePlayRate = 1;
|
||||
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<class AActor> SwarmActor;
|
||||
TSubclassOf<ASwarmAgent> SwarmActor;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
float Distance = 250.0f;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
FOnTimelineFloat onTimelineCallback;
|
||||
|
||||
TArray<AActor*> SwarmActors;
|
||||
|
||||
TArray<ASwarmAgent*> SwarmActors;
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ASwarmWeapon();
|
||||
@ -46,6 +46,9 @@ protected:
|
||||
public:
|
||||
UFUNCTION()
|
||||
void TimelineCallback(float val);
|
||||
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
|
||||
private:
|
||||
void SpawnSwarmAgent();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user