Add base implementation of SwarmWeapon
Still need to implement the Swarm actors
This commit is contained in:
parent
dd92863b60
commit
5adafd6519
BIN
Content/Weapons/Swarm/BP_SwarmActor.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Weapons/Swarm/BP_SwarmActor.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Weapons/Swarm/BP_SwarmWeapon.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Weapons/Swarm/BP_SwarmWeapon.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Weapons/Swarm/C_Swarm.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Weapons/Swarm/C_Swarm.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
99
Source/vampires/Weapons/SwarmWeapon.cpp
Normal file
99
Source/vampires/Weapons/SwarmWeapon.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
|
||||
#include "SwarmWeapon.h"
|
||||
|
||||
#include "VectorTypes.h"
|
||||
#include "Kismet/KismetSystemLibrary.h"
|
||||
#include "vampires/EnemyCharacter.h"
|
||||
|
||||
|
||||
// Sets default values
|
||||
ASwarmWeapon::ASwarmWeapon()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = false;
|
||||
|
||||
TimelineComponent = CreateDefaultSubobject<UTimelineComponent>("TimelineComponent");
|
||||
TimelineComponent->SetDirectionPropertyName(FName("TimelineDirection"));
|
||||
TimelineComponent->SetLooping(true);
|
||||
TimelineComponent->SetTimelineLength(1.0f);
|
||||
TimelineComponent->SetTimelineLengthMode(TL_TimelineLength);
|
||||
TimelineComponent->SetPlaybackPosition(0.0f, false);
|
||||
|
||||
onTimelineCallback.BindUFunction(this, FName(TEXT("TimelineCallback")));
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ASwarmWeapon::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// Spawn the swarm actors in
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
|
||||
// Start the timeline
|
||||
if (SwarmCurve != nullptr)
|
||||
{
|
||||
TimelineComponent->AddInterpFloat(SwarmCurve, onTimelineCallback);
|
||||
}
|
||||
|
||||
TimelineComponent->SetPlayRate(TimelinePlayRate);
|
||||
TimelineComponent->PlayFromStart();
|
||||
|
||||
}
|
||||
|
||||
void ASwarmWeapon::TimelineCallback(float val)
|
||||
{
|
||||
float num = SwarmActors.Num();
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
float actorIndex = (i + 1);
|
||||
float offset = (actorIndex / num) * 360.0f;
|
||||
FVector CenterLocation = GetActorLocation();
|
||||
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);
|
||||
SwarmActors[i]->SetActorLocation(NewLocation);
|
||||
}
|
||||
}
|
||||
|
||||
bool ASwarmWeapon::UpgradeWeapon_Implementation()
|
||||
{
|
||||
if (!Super::UpgradeWeapon_Implementation()) return false;
|
||||
|
||||
switch (CurrentLevel)
|
||||
{
|
||||
case 1:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
break;
|
||||
case 2:
|
||||
Distance *= 1.25f;
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
break;
|
||||
case 3:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 4:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
break;
|
||||
case 5:
|
||||
Distance *= 1.25f;
|
||||
TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);
|
||||
break;
|
||||
case 6:
|
||||
Damage += 10;
|
||||
break;
|
||||
case 7:
|
||||
SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor));
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
ResetWeaponTimer();
|
||||
return true;
|
||||
}
|
||||
|
51
Source/vampires/Weapons/SwarmWeapon.h
Normal file
51
Source/vampires/Weapons/SwarmWeapon.h
Normal file
@ -0,0 +1,51 @@
|
||||
// Louis Hobbs | 2024-2025
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/TimelineComponent.h"
|
||||
#include "vampires/Weapon.h"
|
||||
#include "SwarmWeapon.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class VAMPIRES_API ASwarmWeapon : public AWeapon
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
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;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
float Distance = 250.0f;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
FOnTimelineFloat onTimelineCallback;
|
||||
|
||||
TArray<AActor*> SwarmActors;
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ASwarmWeapon();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void TimelineCallback(float val);
|
||||
|
||||
virtual bool UpgradeWeapon_Implementation() override;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user