Brain spawn

Added the functionality to spawn randomly one brain per tile
This commit is contained in:
JKuijperM 2023-06-05 18:41:05 +02:00
parent 800b10d65f
commit 52c3dff6d0
7 changed files with 52 additions and 18 deletions

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:947a238f28a5c5d94fece83194baf572e1ba3e0f9c3c94cb264947887b5e42c8
size 35071
oid sha256:98a9077418a30a25184b951cd22f4627fc4f37b8bf0f71ce8908015b33c302dd
size 35401

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:368e355640209d925f14b1aa209150fae69e0fdc8cc6ea88769dceed6c6766ef
size 36928
oid sha256:ceb7baf8d39f681cb829006fc9dac54aaf2dc0ce00457bff7a336af811c690f6
size 37357

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:302d46c4efd912d483f97d9e2e469566dd5eca88883381779e45b2924ec3e0f0
size 37105
oid sha256:9b103009453641f601ab59fcf1237bc369000b37128a2d006f252b900265deac
size 37544

View File

@ -2,6 +2,7 @@
#include "Brain.h"
#include "ZombieCharacter.h"
#include "EndlessZombieGameMode.h"
#include "Kismet/GameplayStatics.h"
#include "Components/BoxComponent.h"
@ -22,7 +23,11 @@ void ABrain::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* Ot
{
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
AZombieCharacter* ZombieCharacter = Cast<AZombieCharacter>(OtherActor);
if (ZombieCharacter)
{
AEndlessZombieGameMode* CurrentGameMode = Cast<AEndlessZombieGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (CurrentGameMode)
CurrentGameMode->UpdateScore(iPunctuation);
}
}

View File

@ -2,6 +2,7 @@
#include "PickupItem.h"
#include "ZombieCharacter.h"
#include "Components/BoxComponent.h"
// Sets default values
@ -28,6 +29,8 @@ void APickupItem::BeginPlay()
void APickupItem::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
AZombieCharacter* ZombieCharacter = Cast<AZombieCharacter>(OtherActor);
if (ZombieCharacter)
this->Destroy();
}

View File

@ -2,8 +2,9 @@
#include "Tile.h"
#include "ZombieCharacter.h"
#include "Brain.h"
#include "PathGenerator.h"
#include "ZombieCharacter.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "Kismet/KismetMathLibrary.h"
@ -32,6 +33,11 @@ ATile::ATile()
ObstacleZone->SetRelativeLocation(FVector(511.0f, 0.f, 26.0f));
ObstacleZone->SetRelativeScale3D(FVector(12.50f, 14.5f, 1.0f));
// Add the brain zone
BrainZone = CreateDefaultSubobject<UBoxComponent>(TEXT("BrainZone"));
BrainZone->AttachToComponent(SceneComponent, FAttachmentTransformRules::KeepRelativeTransform);
BrainZone->SetRelativeLocation(FVector(511.0f, 0.f, 133.0f));
BrainZone->SetRelativeScale3D(FVector(12.50f, 11.16f, 1.0f));
}
// Called when the game starts or when spawned
@ -41,8 +47,8 @@ void ATile::BeginPlay()
EndTrigger->OnComponentBeginOverlap.AddDynamic(this, &ATile::OnBeginOverlap);
SpawnRandomLocation(ObstacleZone);
SpawnObstacleAtRandomLocation(ObstacleZone);
SpawnBrainAtRandomLocation(BrainZone);
}
// Called every frame
@ -83,7 +89,7 @@ void ATile::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* Oth
}
}
void ATile::SpawnRandomLocation(UBoxComponent* spawnArea)
void ATile::SpawnObstacleAtRandomLocation(UBoxComponent* spawnArea)
{
// TODO: Check if I have to spawn something
if (ObstacleArray.Num() > 0)
@ -107,6 +113,20 @@ void ATile::SpawnRandomLocation(UBoxComponent* spawnArea)
}
}
void ATile::SpawnBrainAtRandomLocation(UBoxComponent* spawnArea)
{
FVector vOrigin = spawnArea->Bounds.Origin;
FVector vBoxExtent = spawnArea->Bounds.BoxExtent;
//FVector vRandomPoint = RandomPointInBoundingBox(vOrigin, vBoxExtent);
const FVector BoxMin = vOrigin - vBoxExtent;
const FVector BoxMax = vOrigin + vBoxExtent;
FVector vRandomPoint = FMath::RandPointInBox(FBox(BoxMin, BoxMax));
ABrain* aBrain = GetWorld()->SpawnActor<ABrain>(vRandomPoint, FRotator::ZeroRotator);
//aBrain->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform);
}
void ATile::DestroyTile()
{
TArray<AActor*> childActors;

View File

@ -34,17 +34,23 @@ public:
UBoxComponent* EndTrigger;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UBoxComponent* ObstacleZone;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UBoxComponent* BrainZone;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Pickup Item")
int iMaxBrains = 3;
UFUNCTION(BlueprintCallable, Category = "AttachedPoint")
FTransform GetAttachTransform();
UFUNCTION()
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
void SpawnRandomLocation(UBoxComponent* boxTrigger);
void SpawnObstacleAtRandomLocation(UBoxComponent* spawnArea);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Obstacles")
TArray<TSubclassOf<class AObstacle>> ObstacleArray;
void SpawnBrainAtRandomLocation(UBoxComponent* spawnArea);
private:
void DestroyTile();
};