unreal/HexTile.cpp

35 lines
1.0 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "HexTile.h"
#include "AdventurePlayerController.h"
#include "AdventureMap.h"
#include "Kismet/KismetMathLibrary.h"
// Sets default values
AHexTile::AHexTile()
{
TileSize = 100.f;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Scene"));
this->FillCornersArray();
}
void AHexTile::BeginPlay() { Super::BeginPlay(); }
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);
}
void AHexTile::FillCornersArray() { for (int32 i = 0 ; i < 6; i++) { Corners.Emplace(Corner(i + 1)); } }
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;
}