Game loop finished

This commit is contained in:
2023-07-31 22:57:35 +02:00
parent 6b23098dd3
commit 774101a96c
26 changed files with 63 additions and 18 deletions

View File

@@ -12,6 +12,7 @@ ASpawnManager::ASpawnManager()
}
void ASpawnManager::GenerateBoard(const TSubclassOf<ALevelTemplate> Template) {
SpawnedBlocks = 0;
FVector ActorLocation = this->GetActorLocation();
CurrentLevel = GetWorld()->SpawnActor<ALevelTemplate>(Template, this->GetActorTransform());
UPaperTileMapComponent* Tilemap = CurrentLevel->Template;
@@ -20,19 +21,40 @@ void ASpawnManager::GenerateBoard(const TSubclassOf<ALevelTemplate> Template) {
for (int32 i = 0; i < BlocksY; i++) {
for (int32 o = 0; o < BlocksX; o++) {
// Make transform
FTransform SpawnTransform;
SpawnTransform.SetLocation(FVector((ActorLocation.X - (Distance * BlocksX / 2) + (o * Distance)), (ActorLocation.Y - (Distance * (BlocksY / 2)) + (i * Distance)), ActorLocation.Z));
// Spawn block
int32 TileId = Tilemap->GetTile(i, o, 0).GetTileIndex();
TSubclassOf<ABuildingBlock> TileClass = *BlockTemplates.Find(TileId);
ABuildingBlock* ThisBlock = GetWorld()->SpawnActor<ABuildingBlock>(TileClass, SpawnTransform);
ThisBlock->Index = (10 * i) + o;
if (ThisBlock->HasVariants) {
ThisBlock->Variant = FMath::RandRange(1, MaxVariants);
// If TileId == 4 means, that there should be no tile at this location
if (TileId != 4) {
// Make transform
FTransform SpawnTransform;
SpawnTransform.SetLocation(FVector((ActorLocation.X - (Distance * BlocksX / 2) + (o * Distance)), (ActorLocation.Y - (Distance * (BlocksY / 2)) + (i * Distance)), ActorLocation.Z));
// Spawn block
TSubclassOf<ABuildingBlock> TileClass = *BlockTemplates.Find(TileId);
ABuildingBlock* ThisBlock = GetWorld()->SpawnActor<ABuildingBlock>(TileClass, SpawnTransform);
ThisBlock->Index = (10 * i) + o;
if (ThisBlock->HasVariants) {
ThisBlock->Variant = FMath::RandRange(1, MaxVariants);
}
if (TileId != 5) {
SpawnedBlocks++;
ThisBlock->OnBlockDestroyed.BindUFunction(this, TEXT("RemoveBlock"));
}
ThisBlock->FadeIn();
}
ThisBlock->FadeIn();
}
}
}
void ASpawnManager::RemoveBlock() {
SpawnedBlocks--;
UE_LOG(LogTemp, Warning, TEXT("Removed Block --- %i left"), SpawnedBlocks);
if (SpawnedBlocks <= 0)
{
UE_LOG(LogTemp, Warning, TEXT("All blocks destroyed, calling OnLevelCompleted"));
float Playtime = CurrentLevel->StopGame();
int32 AcquiredStars = CurrentLevel->GetAwardStars();
OnLevelCompleted(Playtime, AcquiredStars);
}
}