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;
}