2022-01-11 11:07:17 +01:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "HexTile.h"
|
|
|
|
#include "AdventurePlayerController.h"
|
2022-01-13 16:34:06 +01:00
|
|
|
#include "AdventureMap.h"
|
2022-01-11 11:07:17 +01:00
|
|
|
#include "Kismet/KismetMathLibrary.h"
|
|
|
|
|
|
|
|
// Sets default values
|
|
|
|
AHexTile::AHexTile()
|
|
|
|
{
|
|
|
|
TileSize = 100.f;
|
|
|
|
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
|
|
|
|
this->FillCornersArray();
|
|
|
|
}
|
|
|
|
|
2022-01-29 20:54:35 +01:00
|
|
|
void AHexTile::BeginPlay() { Super::BeginPlay(); }
|
2022-01-11 11:07:17 +01:00
|
|
|
|
|
|
|
FVector AHexTile::Corner(int32 i)
|
|
|
|
{
|
|
|
|
FVector TileCenter = this->GetActorTransform().GetLocation();
|
|
|
|
int32 Angle_Deg = 60 * i - 30;
|
|
|
|
float Angle_Rad = UKismetMathLibrary::GetPI()/180 * Angle_Deg;
|
|
|
|
float X = TileCenter.X + TileSize * cos(Angle_Rad);
|
|
|
|
float Y = TileCenter.Y + TileSize * sin(Angle_Rad);
|
|
|
|
return FVector(X, Y, 0.f);
|
|
|
|
}
|
2022-01-29 20:54:35 +01:00
|
|
|
void AHexTile::FillCornersArray() { for (int32 i = 0 ; i < 6; i++) { Corners.Emplace(Corner(i + 1)); } }
|
2022-01-13 16:54:37 +01:00
|
|
|
|
|
|
|
int32 AHexTile::Distance(AHexTile* ToHex)
|
|
|
|
{
|
|
|
|
int32 CubeS1 = -this->Q - this->R;
|
|
|
|
int32 CubeS2 = -ToHex->Q - ToHex->R;
|
|
|
|
return (abs(this->Q - ToHex->Q) + abs(this->R - ToHex->R) + abs(CubeS1 - CubeS2)) / 2;
|
|
|
|
}
|