Variants / Chaining / Icons / ...

This commit is contained in:
2023-07-22 17:01:54 +02:00
parent 77bb47aeb9
commit 224154e100
110 changed files with 97 additions and 27 deletions

View File

@@ -8,28 +8,47 @@ ABuildingBlock::ABuildingBlock()
{
// 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;
InitialHealth = Health;
StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
}
void ABuildingBlock::DepleteHealth(float Amount) {
Health = Health - Amount;
if (Health <= 0.0f) {
UE_LOG(LogTemp, Warning, TEXT("Health below 0 - DestroyingBlock"));
void ABuildingBlock::TakeHit() {
HitsRemaining -= 1;
if (HitsRemaining <= 0) {
DestroyBlock();
}
else {
uint8 DestructionLevel = 0;
if (Health <= InitialHealth * 0.66f) {
if (Health <= InitialHealth * 0.33f) {
DestructionLevel = 2;
}
else {
DestructionLevel = 1;
}
}
TArray<ABuildingBlock*> ABuildingBlock::GetSameVariantNeighbours() {
TArray<ABuildingBlock*> Results;
FVector Location = this->GetActorLocation();
for (int32 i = 0; i < 4; i++) {
FHitResult HitResult;
FVector EndLocation;
switch (i) {
case 0:
EndLocation = Location + FVector(60.f, 0.f, 0.f);
break;
case 1:
EndLocation = Location + FVector(-60.f, 0.f, 0.f);
break;
case 2:
EndLocation = Location + FVector(0.f, 60.f, 0.f);
break;
case 3:
EndLocation = Location + FVector(0.f, -60.f, 0.f);
break;
}
UpdateDestructionLevel(DestructionLevel);
if (GetWorld()->LineTraceSingleByChannel(HitResult, Location, EndLocation, ECC_Visibility)) {
ABuildingBlock* HitActor = Cast<ABuildingBlock>(HitResult.GetActor());
if (IsValid(HitActor) && HitActor->Variant == this->Variant) {
Results.Add(HitActor);
}
}
}
return Results;
}

View File

@@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Components/StaticMeshComponent.h"
#include "DrawDebugHelpers.h"
#include "BuildingBlock.generated.h"
UCLASS()
@@ -18,22 +19,33 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UStaticMeshComponent* StaticMesh;
// How many hits can this block take before getting destroyed
UPROPERTY(BlueprintReadWrite, EditAnywhere)
float Health = 100.0f;
int32 HitsRemaining = 1;
UPROPERTY(BlueprintReadOnly)
int32 Index = 0;
UPROPERTY(BlueprintReadOnly)
float InitialHealth;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
bool HasVariants = false;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int32 Variant = 0;
UFUNCTION(BlueprintCallable)
void DepleteHealth(float Amount);
void TakeHit();
UFUNCTION(BlueprintImplementableEvent)
void UpdateDestructionLevel(uint8 Level);
UFUNCTION(BlueprintImplementableEvent)
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
void DestroyBlock();
UFUNCTION(BlueprintImplementableEvent)
void FadeIn();
UFUNCTION(BlueprintImplementableEvent, BlueprintCallable)
void DestroyWithDelay();
// Get neighbouring Blocks with same color variant
UFUNCTION(BlueprintCallable)
TArray<ABuildingBlock*> GetSameVariantNeighbours();
};

View File

@@ -8,6 +8,7 @@ ALevelTemplate::ALevelTemplate()
{
// 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;
Template = CreateDefaultSubobject<UPaperTileMapComponent>(TEXT("TemplateTilemap"));
}
@@ -22,6 +23,22 @@ void ALevelTemplate::BeginPlay()
void ALevelTemplate::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
GameTime += DeltaTime;
}
void ALevelTemplate::StartGame() {
CountTime = true;
GameTime = 0.f;
}
float ALevelTemplate::StopGame() {
CountTime = false;
return GameTime;
}
int32 ALevelTemplate::GetAwardStars() {
if (GameTime < ThreeStarTarget) return 3;
if (GameTime < TwoStarTarget) return 2;
if (GameTime < OneStarTarget) return 1;
return 0;
}

View File

@@ -28,6 +28,12 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int32 ThreeStarTarget = 60;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
float GameTime = 0.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool CountTime = false;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
@@ -36,4 +42,13 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable)
void StartGame();
// Stop counting and return elapsed game time
UFUNCTION(BlueprintCallable)
float StopGame();
UFUNCTION(BlueprintCallable)
int32 GetAwardStars();
};

View File

@@ -11,7 +11,7 @@ ASpawnManager::ASpawnManager()
}
void ASpawnManager::GenerateBoard(TSubclassOf<ALevelTemplate> &Template) {
void ASpawnManager::GenerateBoard(const TSubclassOf<ALevelTemplate> Template) {
FVector ActorLocation = this->GetActorLocation();
CurrentLevel = GetWorld()->SpawnActor<ALevelTemplate>(Template, this->GetActorTransform());
UPaperTileMapComponent* Tilemap = CurrentLevel->Template;
@@ -29,6 +29,10 @@ void ASpawnManager::GenerateBoard(TSubclassOf<ALevelTemplate> &Template) {
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);
}
ThisBlock->FadeIn();
}
}
}

View File

@@ -29,6 +29,9 @@ protected:
UPROPERTY(BlueprintReadWrite, EditAnywhere)
int32 BlocksY = 10;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int32 MaxVariants = 5;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ALevelTemplate* CurrentLevel;
@@ -36,7 +39,7 @@ protected:
TMap<int32, TSubclassOf<ABuildingBlock>> BlockTemplates;
UFUNCTION(BlueprintCallable, CallInEditor)
void GenerateBoard(TSubclassOf<ALevelTemplate> &Template);
void GenerateBoard(const TSubclassOf<ALevelTemplate> Template);
public: