diff --git a/Content/Blueprints/BP_PlayerController.uasset b/Content/Blueprints/BP_PlayerController.uasset index 5090b7e..d7248c0 100644 --- a/Content/Blueprints/BP_PlayerController.uasset +++ b/Content/Blueprints/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:80c4f2ba5cb51befdb7b122e8c8681ef1c1f27240d3a80615e8134c0f1d8a5c4 -size 324532 +oid sha256:e9bdff03e1bc72f9028b7eb96799242a1cc20a87c31cbc99129872872ae47ab5 +size 323560 diff --git a/Content/Blueprints/BP_PlayerPawn.uasset b/Content/Blueprints/BP_PlayerPawn.uasset index 90787b5..7b8319d 100644 --- a/Content/Blueprints/BP_PlayerPawn.uasset +++ b/Content/Blueprints/BP_PlayerPawn.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b5aff189863636bdf510e9fb0326a5433cb9fc2f0a9ce8bcd43362fd4b72b5fb -size 81067 +oid sha256:798e519803b5a70767ad60c18787e810d1a56ed79d13125e887d4762a0eea6d8 +size 79967 diff --git a/Content/Blueprints/BP_SpawnPoint.uasset b/Content/Blueprints/BP_SpawnPoint.uasset new file mode 100644 index 0000000..f4a794a --- /dev/null +++ b/Content/Blueprints/BP_SpawnPoint.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4560108a65504f62158b4805b4bf547498dacc1192deae32e9d1fca606c4a12 +size 26288 diff --git a/Content/Blueprints/Units/Common/BP_Unit.uasset b/Content/Blueprints/Units/Common/BP_Unit.uasset index aad46d5..667feb5 100644 --- a/Content/Blueprints/Units/Common/BP_Unit.uasset +++ b/Content/Blueprints/Units/Common/BP_Unit.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bdd41cc7cd87ba2ca423623500bb4f9240f6f0d580ef959460d50e21d86e754c -size 68183 +oid sha256:5175d37ab090d94bebdfd70dee80b882d94d89f70b87756ec30786c8b20c2190 +size 66982 diff --git a/Content/Levels/BattleMap.umap b/Content/Levels/BattleMap.umap index 7c1db6e..2f44427 100644 --- a/Content/Levels/BattleMap.umap +++ b/Content/Levels/BattleMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2e967a548da565ab1b5415d47b89a317595c731db748d3af061ce3c850acb07a -size 71930 +oid sha256:1fc147d8727046d65d9aab2dc8f3a0320f327a0a9e13847b367395872417b7dc +size 219897 diff --git a/Content/Levels/MainMenu.umap b/Content/Levels/MainMenu.umap index 69d4e37..4ee1387 100644 --- a/Content/Levels/MainMenu.umap +++ b/Content/Levels/MainMenu.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1360f38c4e6d217122ea2f5222d6892a79940a1f212c8efc8616132be3490bab -size 41472 +oid sha256:a1a6165a9c5f5cad029a31b944e8b14829cb23145c632d56ba72668988a907ae +size 41821 diff --git a/Content/Models/Levels/Level1/level1.uasset b/Content/Models/Levels/Level1/level1.uasset index 04ae278..333a97f 100644 --- a/Content/Models/Levels/Level1/level1.uasset +++ b/Content/Models/Levels/Level1/level1.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b9625d9144787271ff0a0e7c986f6f199b51c6b0b2407d3b7f51f817cfc51aee -size 612415 +oid sha256:1aab7ec71496959feb34625244177e8e15a5efbfe988ca1746b5c0065e53d1dd +size 610252 diff --git a/Source/SpaceBattler/Private/PartySubsystem.cpp b/Source/SpaceBattler/Private/PartySubsystem.cpp index 951fada..ae65b01 100644 --- a/Source/SpaceBattler/Private/PartySubsystem.cpp +++ b/Source/SpaceBattler/Private/PartySubsystem.cpp @@ -3,6 +3,8 @@ #include "PartySubsystem.h" +#include "Kismet/GameplayStatics.h" + void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo) { for (FPartyMember &Unit : Members) @@ -32,7 +34,13 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH this->HorizontalOffset = InHorizontalOffset; this->NumRows = InNumRows; this->HorizontalSpacing = InHorizontalSpacing; + CurrentColumn = 0; + SpawnQueue.Empty(); + TArray SpawnPoints; + UGameplayStatics::GetAllActorsWithTag(GetWorld(), "PlayerSpawn", SpawnPoints); + SpawnPoint = SpawnPoints[0]; + for (FPartyMember &Unit : GetMembers()) { for(auto i = 0; i < GetMemberAllocated(Unit); i++) @@ -41,7 +49,7 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH } } - const auto NumUnits= SpawnQueue.Num(); + const int32 NumUnits = SpawnQueue.Num(); SpawnUnits(); GetWorld()->GetTimerManager().SetTimer( @@ -68,8 +76,22 @@ void UPartySubsystem::SpawnUnits() FActorSpawnParameters SpawnActorParameters = {}; SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn; - FVector Location = FVector( VerticalSpacing * i - VerticalSpacing, -HorizontalOffset * CurrentColumn, 1000); - GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, nullptr, SpawnActorParameters); + FVector Location = SpawnPoint->GetActorLocation() + FVector(i * -VerticalSpacing, -HorizontalOffset * CurrentColumn, 300); + FRotator Rotation = FRotator(0, 90.0f, 0); + + AActor* NewActor = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, &Rotation, SpawnActorParameters); + + FHitResult Hit; + FVector TraceStart = NewActor->GetActorLocation(); + FVector TraceEnd = -NewActor->GetActorUpVector() * 10000.0f; + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(NewActor); + + NewActor->GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_WorldStatic, QueryParams); + if(Hit.bBlockingHit) + { + NewActor->SetActorLocation(Hit.Location, true, nullptr, ETeleportType::ResetPhysics); + } } LastSpawnIndex += NumRows; diff --git a/Source/SpaceBattler/Private/WaveSubsystem.cpp b/Source/SpaceBattler/Private/WaveSubsystem.cpp index 66eb5b5..98747b3 100644 --- a/Source/SpaceBattler/Private/WaveSubsystem.cpp +++ b/Source/SpaceBattler/Private/WaveSubsystem.cpp @@ -3,6 +3,8 @@ #include "WaveSubsystem.h" +#include "Kismet/GameplayStatics.h" + void UWaveSubsystem::Init(const TArray InWaves, const int32 CurrWave = 0) { CurrentWave = CurrWave; @@ -16,6 +18,11 @@ int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHor VerticalSpacing = InVerticalSpacing; SpawnQueue = Waves[CurrentWave]->GetUnits(); const auto NumUnits = SpawnQueue.Num(); + CurrentColumn = 0; + + TArray SpawnPoints; + UGameplayStatics::GetAllActorsWithTag(GetWorld(), "EnemySpawn", SpawnPoints); + SpawnPoint = SpawnPoints[0]; SpawnUnits(); GetWorld()->GetTimerManager().SetTimer( @@ -36,15 +43,33 @@ void UWaveSubsystem::SpawnUnits() if(i + LastSpawnIndex >= SpawnQueue.Num()) { GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle); + LastSpawnIndex += i; return; } + + FActorSpawnParameters SpawnActorParameters = {}; + SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn; + + FVector Location = SpawnPoint->GetActorLocation() + FVector(i * -VerticalSpacing, -HorizontalOffset * CurrentColumn, 300); + FRotator Rotation = FRotator(0,-90.0f, 0); + AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location, &Rotation, SpawnActorParameters); - FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, HorizontalOffset, 0); - AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location); if(NewEnemy != nullptr) { NewEnemy->Tags.Add(TEXT("enemy")); } + + FHitResult Hit; + FVector TraceStart = NewEnemy->GetActorLocation(); + FVector TraceEnd = -NewEnemy->GetActorUpVector() * 10000.0f; + FCollisionQueryParams QueryParams; + QueryParams.AddIgnoredActor(NewEnemy); + + NewEnemy->GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_WorldStatic, QueryParams); + if(Hit.bBlockingHit) + { + NewEnemy->SetActorLocation(Hit.Location, true, nullptr, ETeleportType::ResetPhysics); + } } LastSpawnIndex += NumRows; diff --git a/Source/SpaceBattler/Public/PartySubsystem.h b/Source/SpaceBattler/Public/PartySubsystem.h index 65fad56..94913fc 100644 --- a/Source/SpaceBattler/Public/PartySubsystem.h +++ b/Source/SpaceBattler/Public/PartySubsystem.h @@ -78,6 +78,9 @@ protected: UPROPERTY(BlueprintReadWrite, EditAnywhere) int32 Credits; + + UPROPERTY() + AActor* SpawnPoint; FTimerHandle SpawnTimerHandle; int32 LastSpawnIndex; diff --git a/Source/SpaceBattler/Public/WaveSubsystem.h b/Source/SpaceBattler/Public/WaveSubsystem.h index 9f74aea..eb3758d 100644 --- a/Source/SpaceBattler/Public/WaveSubsystem.h +++ b/Source/SpaceBattler/Public/WaveSubsystem.h @@ -20,7 +20,7 @@ public: UFUNCTION(BlueprintCallable) int32 SpawnWave(float InVerticalSpacing, float InHorizontalOffset, int InNumRows); - + protected: void SpawnUnits(); @@ -35,10 +35,14 @@ protected: UPROPERTY(BlueprintReadWrite) UPrimaryDataAsset* SelectedStage; + + UPROPERTY() + AActor* SpawnPoint; FTimerHandle SpawnTimerHandle; int32 NumRows; int32 LastSpawnIndex; float VerticalSpacing; float HorizontalOffset; + int32 CurrentColumn; };