diff --git a/Content/Blueprints/Tiles/BP_TileStraight.uasset b/Content/Blueprints/Tiles/BP_TileStraight.uasset index 6c3ba4f..a9da3c1 100644 --- a/Content/Blueprints/Tiles/BP_TileStraight.uasset +++ b/Content/Blueprints/Tiles/BP_TileStraight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:947a238f28a5c5d94fece83194baf572e1ba3e0f9c3c94cb264947887b5e42c8 -size 35071 +oid sha256:98a9077418a30a25184b951cd22f4627fc4f37b8bf0f71ce8908015b33c302dd +size 35401 diff --git a/Content/Blueprints/Tiles/BP_TileTurnLeft.uasset b/Content/Blueprints/Tiles/BP_TileTurnLeft.uasset index 08116ce..d920a26 100644 --- a/Content/Blueprints/Tiles/BP_TileTurnLeft.uasset +++ b/Content/Blueprints/Tiles/BP_TileTurnLeft.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:368e355640209d925f14b1aa209150fae69e0fdc8cc6ea88769dceed6c6766ef -size 36928 +oid sha256:ceb7baf8d39f681cb829006fc9dac54aaf2dc0ce00457bff7a336af811c690f6 +size 37357 diff --git a/Content/Blueprints/Tiles/BP_TileTurnRight.uasset b/Content/Blueprints/Tiles/BP_TileTurnRight.uasset index 41cb58d..b5d4a28 100644 --- a/Content/Blueprints/Tiles/BP_TileTurnRight.uasset +++ b/Content/Blueprints/Tiles/BP_TileTurnRight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:302d46c4efd912d483f97d9e2e469566dd5eca88883381779e45b2924ec3e0f0 -size 37105 +oid sha256:9b103009453641f601ab59fcf1237bc369000b37128a2d006f252b900265deac +size 37544 diff --git a/Source/EndlessZombie/Brain.cpp b/Source/EndlessZombie/Brain.cpp index 63df515..e681cbe 100644 --- a/Source/EndlessZombie/Brain.cpp +++ b/Source/EndlessZombie/Brain.cpp @@ -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); - AEndlessZombieGameMode* CurrentGameMode = Cast(UGameplayStatics::GetGameMode(GetWorld())); - if (CurrentGameMode) - CurrentGameMode->UpdateScore(iPunctuation); + AZombieCharacter* ZombieCharacter = Cast(OtherActor); + if (ZombieCharacter) + { + AEndlessZombieGameMode* CurrentGameMode = Cast(UGameplayStatics::GetGameMode(GetWorld())); + if (CurrentGameMode) + CurrentGameMode->UpdateScore(iPunctuation); + } } diff --git a/Source/EndlessZombie/PickupItem.cpp b/Source/EndlessZombie/PickupItem.cpp index 7d21ff4..06985fe 100644 --- a/Source/EndlessZombie/PickupItem.cpp +++ b/Source/EndlessZombie/PickupItem.cpp @@ -2,12 +2,13 @@ #include "PickupItem.h" +#include "ZombieCharacter.h" #include "Components/BoxComponent.h" // Sets default values APickupItem::APickupItem() { - // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; StaticMesh = CreateDefaultSubobject(TEXT("StaticMesh")); @@ -23,12 +24,14 @@ void APickupItem::BeginPlay() Super::BeginPlay(); CollisionTrigger->OnComponentBeginOverlap.AddDynamic(this, &APickupItem::OnBeginOverlap); - + } void APickupItem::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) { - this->Destroy(); + AZombieCharacter* ZombieCharacter = Cast(OtherActor); + if (ZombieCharacter) + this->Destroy(); } // Called every frame diff --git a/Source/EndlessZombie/Tile.cpp b/Source/EndlessZombie/Tile.cpp index 91b75a7..9bbf5fb 100644 --- a/Source/EndlessZombie/Tile.cpp +++ b/Source/EndlessZombie/Tile.cpp @@ -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" @@ -31,7 +32,12 @@ ATile::ATile() ObstacleZone->AttachToComponent(SceneComponent, FAttachmentTransformRules::KeepRelativeTransform); ObstacleZone->SetRelativeLocation(FVector(511.0f, 0.f, 26.0f)); ObstacleZone->SetRelativeScale3D(FVector(12.50f, 14.5f, 1.0f)); - + + // Add the brain zone + BrainZone = CreateDefaultSubobject(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(vRandomPoint, FRotator::ZeroRotator); + //aBrain->AttachToActor(this, FAttachmentTransformRules::KeepRelativeTransform); +} + void ATile::DestroyTile() { TArray childActors; diff --git a/Source/EndlessZombie/Tile.h b/Source/EndlessZombie/Tile.h index 536d40c..3fd8d14 100644 --- a/Source/EndlessZombie/Tile.h +++ b/Source/EndlessZombie/Tile.h @@ -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> ObstacleArray; + void SpawnBrainAtRandomLocation(UBoxComponent* spawnArea); + private: void DestroyTile(); };