Game loop finished
This commit is contained in:
@@ -51,4 +51,13 @@ TArray<ABuildingBlock*> ABuildingBlock::GetSameVariantNeighbours() {
|
||||
}
|
||||
|
||||
return Results;
|
||||
}
|
||||
|
||||
void ABuildingBlock::DestroyBlock_Implementation() {
|
||||
IsBeingDestroyed = true;
|
||||
OnBlockDestroyed.ExecuteIfBound();
|
||||
}
|
||||
|
||||
void ABuildingBlock::DestroyWithDelay_Implementation() {
|
||||
IsBeingDestroyed = true;
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
#include "DrawDebugHelpers.h"
|
||||
#include "BuildingBlock.generated.h"
|
||||
|
||||
DECLARE_DELEGATE(FBlockDestroyed);
|
||||
|
||||
UCLASS()
|
||||
class FIREWORKDUELS_API ABuildingBlock : public AActor
|
||||
{
|
||||
@@ -35,16 +37,21 @@ public:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
int32 Variant = 0;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
bool IsBeingDestroyed = false;
|
||||
|
||||
FBlockDestroyed OnBlockDestroyed;
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void TakeHit();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
|
||||
void DestroyBlock();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void FadeIn();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
|
||||
UFUNCTION(BlueprintNativeEvent, BlueprintCallable)
|
||||
void DestroyWithDelay();
|
||||
|
||||
// Get neighbouring Blocks with same color variant
|
||||
|
||||
@@ -25,13 +25,10 @@ UENUM(BlueprintType)
|
||||
enum Firework
|
||||
{
|
||||
Impact UMETA(DisplayName = "Impact"),
|
||||
Timed UMETA(DisplayName = "Timed"),
|
||||
Sticky UMETA(DisplayName = "Sticky"),
|
||||
Cluster UMETA(DisplayName = "Cluster"),
|
||||
ImpactRocket UMETA(DisplayName = "ImpactRocket"),
|
||||
TimedRocket UMETA(DisplayName = "TimedRocket"),
|
||||
ClusterRocket UMETA(DisplayName = "ClusterRocket"),
|
||||
StickyRocket UMETA(DisplayName = "StickyRocket"),
|
||||
GuidedRocket UMETA(DisplayName = "GuidedRocket"),
|
||||
|
||||
Lighter UMETA(DisplayName = "Lighter"),
|
||||
|
||||
@@ -16,14 +16,15 @@ ALevelTemplate::ALevelTemplate()
|
||||
void ALevelTemplate::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ALevelTemplate::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
GameTime += DeltaTime;
|
||||
if (CountTime) {
|
||||
GameTime += DeltaTime;
|
||||
}
|
||||
}
|
||||
|
||||
void ALevelTemplate::StartGame() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,18 @@ protected:
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TMap<int32, TSubclassOf<ABuildingBlock>> BlockTemplates;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite)
|
||||
int32 SpawnedBlocks = 0;
|
||||
|
||||
UFUNCTION(BlueprintCallable, CallInEditor)
|
||||
void GenerateBoard(const TSubclassOf<ALevelTemplate> Template);
|
||||
|
||||
UFUNCTION()
|
||||
void RemoveBlock();
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void OnLevelCompleted(const float &Playtime,const int32 &AcquiredStars);
|
||||
|
||||
public:
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user