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 "SwarmWeapon.h" | ||||||
| 
 | 
 | ||||||
| #include "VectorTypes.h" | #include "SwarmAgent.h" | ||||||
| #include "Kismet/KismetSystemLibrary.h" |  | ||||||
| #include "vampires/EnemyCharacter.h" |  | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| // Sets default values
 | // Sets default values
 | ||||||
| ASwarmWeapon::ASwarmWeapon() | ASwarmWeapon::ASwarmWeapon() | ||||||
| @ -30,8 +27,8 @@ void ASwarmWeapon::BeginPlay() | |||||||
| 	Super::BeginPlay(); | 	Super::BeginPlay(); | ||||||
| 
 | 
 | ||||||
| 	// Spawn the swarm actors in
 | 	// Spawn the swarm actors in
 | ||||||
| 	SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor)); | 	SpawnSwarmAgent(); | ||||||
| 	SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor)); | 	SpawnSwarmAgent(); | ||||||
| 
 | 
 | ||||||
| 	// Start the timeline
 | 	// Start the timeline
 | ||||||
| 	if (SwarmCurve != nullptr) | 	if (SwarmCurve != nullptr) | ||||||
| @ -41,7 +38,6 @@ void ASwarmWeapon::BeginPlay() | |||||||
| 
 | 
 | ||||||
| 	TimelineComponent->SetPlayRate(TimelinePlayRate); | 	TimelineComponent->SetPlayRate(TimelinePlayRate); | ||||||
| 	TimelineComponent->PlayFromStart(); | 	TimelineComponent->PlayFromStart(); | ||||||
| 	 |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void ASwarmWeapon::TimelineCallback(float val) | void ASwarmWeapon::TimelineCallback(float val) | ||||||
| @ -56,38 +52,42 @@ void ASwarmWeapon::TimelineCallback(float val) | |||||||
| 		FVector Direction = FVector(0.0, 1, 0.0); | 		FVector Direction = FVector(0.0, 1, 0.0); | ||||||
| 		FVector RotatedDirection = Direction.RotateAngleAxis(val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f)); | 		FVector RotatedDirection = Direction.RotateAngleAxis(val * 360.0f + offset, FVector(0.0f, 0.0f, 1.0f)); | ||||||
| 		FVector NewLocation = CenterLocation + (RotatedDirection * Distance); | 		FVector NewLocation = CenterLocation + (RotatedDirection * Distance); | ||||||
|  | 		NewLocation.Z = 140.0f; | ||||||
| 		SwarmActors[i]->SetActorLocation(NewLocation); | 		SwarmActors[i]->SetActorLocation(NewLocation); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool ASwarmWeapon::UpgradeWeapon_Implementation() | bool ASwarmWeapon::UpgradeWeapon_Implementation() | ||||||
| { | { | ||||||
| 	if (!Super::UpgradeWeapon_Implementation()) return false; | 	if (!Super::UpgradeWeapon_Implementation()) | ||||||
|  | 	{ | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	switch (CurrentLevel) | 	switch (CurrentLevel) | ||||||
| 	{ | 	{ | ||||||
| 	case 1: | 	case 1: | ||||||
| 		SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor)); | 		SpawnSwarmAgent(); | ||||||
| 		break; | 		break; | ||||||
| 	case 2: | 	case 2: | ||||||
| 		Distance *= 1.25f; | 		Distance *= 1.25f; | ||||||
| 		TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);  | 		TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f); | ||||||
| 		break; | 		break; | ||||||
| 	case 3: | 	case 3: | ||||||
| 		Damage += 10; | 		Damage += 10; | ||||||
| 		break; | 		break; | ||||||
| 	case 4: | 	case 4: | ||||||
| 		SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor)); | 		SpawnSwarmAgent(); | ||||||
| 		break; | 		break; | ||||||
| 	case 5: | 	case 5: | ||||||
| 		Distance *= 1.25f; | 		Distance *= 1.25f; | ||||||
| 		TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f);  | 		TimelineComponent->SetPlayRate(TimelineComponent->GetPlayRate() * 1.3f); | ||||||
| 		break; | 		break; | ||||||
| 	case 6: | 	case 6: | ||||||
| 		Damage += 10; | 		Damage += 10; | ||||||
| 		break; | 		break; | ||||||
| 	case 7: | 	case 7: | ||||||
| 		SwarmActors.Add(GetWorld()->SpawnActor<AActor>(SwarmActor)); | 		SpawnSwarmAgent(); | ||||||
| 		break; | 		break; | ||||||
| 	default: | 	default: | ||||||
| 		return false; | 		return false; | ||||||
| @ -97,3 +97,9 @@ bool ASwarmWeapon::UpgradeWeapon_Implementation() | |||||||
| 	return true; | 	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 "vampires/Weapon.h" | ||||||
| #include "SwarmWeapon.generated.h" | #include "SwarmWeapon.generated.h" | ||||||
| 
 | 
 | ||||||
|  | class ASwarmAgent; | ||||||
|  | 
 | ||||||
| UCLASS() | UCLASS() | ||||||
| class VAMPIRES_API ASwarmWeapon : public AWeapon | class VAMPIRES_API ASwarmWeapon : public AWeapon | ||||||
| { | { | ||||||
| @ -15,26 +17,24 @@ class VAMPIRES_API ASwarmWeapon : public AWeapon | |||||||
| public: | public: | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline") | 	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Timeline") | ||||||
| 	TObjectPtr<UTimelineComponent> TimelineComponent = nullptr; | 	TObjectPtr<UTimelineComponent> TimelineComponent = nullptr; | ||||||
| 	 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
| 	TObjectPtr<UCurveFloat> SwarmCurve; | 	TObjectPtr<UCurveFloat> SwarmCurve; | ||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||||
| 	float TimelinePlayRate = 1; | 	float TimelinePlayRate = 1; | ||||||
| 	 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
| 	TSubclassOf<class AActor> SwarmActor; | 	TSubclassOf<ASwarmAgent> SwarmActor; | ||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | 	UPROPERTY(EditAnywhere, BlueprintReadWrite) | ||||||
| 	float Distance = 250.0f; | 	float Distance = 250.0f; | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	 |  | ||||||
| private: | private: | ||||||
| 	FOnTimelineFloat onTimelineCallback; | 	FOnTimelineFloat onTimelineCallback; | ||||||
| 
 | 
 | ||||||
| 	TArray<AActor*> SwarmActors; | 	TArray<ASwarmAgent*> SwarmActors; | ||||||
| 	 | 
 | ||||||
| public: | public: | ||||||
| 	// Sets default values for this actor's properties
 | 	// Sets default values for this actor's properties
 | ||||||
| 	ASwarmWeapon(); | 	ASwarmWeapon(); | ||||||
| @ -46,6 +46,9 @@ protected: | |||||||
| public: | public: | ||||||
| 	UFUNCTION() | 	UFUNCTION() | ||||||
| 	void TimelineCallback(float val); | 	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