plan to implement pathfinding; minor fixes & refactorings
This commit is contained in:
@ -24,17 +24,6 @@ void AAdventureMap::BeginPlay()
|
||||
}
|
||||
}
|
||||
|
||||
// Every Hex Tile's index within the Grid Array can be derived from its Q and R coordinates
|
||||
int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
|
||||
{
|
||||
/*
|
||||
* The Q axis is (i.e. columns are) oriented diagonally.
|
||||
* The Hex Grid has a rough square shape, hence the Q coordinates must be offset by -1 every other row.
|
||||
*/
|
||||
int32 column = qAxial + FMath::FloorToInt(rAxial / 2);
|
||||
return (rAxial * GridSize) + column;
|
||||
}
|
||||
|
||||
// Called once on Begin Play
|
||||
void AAdventureMap::MakeGrid()
|
||||
{
|
||||
@ -83,8 +72,23 @@ void AAdventureMap::MakeGrid()
|
||||
bHexGridReady = true;
|
||||
}
|
||||
|
||||
// Every Hex Tile's index within the Grid Array can be derived from its Q and R coordinates
|
||||
int32 AAdventureMap::GridIndex(int32 qAxial, int32 rAxial)
|
||||
{
|
||||
/*
|
||||
* The Q axis is (i.e. columns are) oriented diagonally.
|
||||
* The Hex Grid has a rough square shape, hence the Q coordinates must be offset by -1 every other row.
|
||||
*/
|
||||
int32 column = qAxial + FMath::FloorToInt(rAxial / 2);
|
||||
return (rAxial * GridSize) + column;
|
||||
}
|
||||
|
||||
AHexTile* AAdventureMap::RandomHex()
|
||||
{
|
||||
int32 RandHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
|
||||
while (RandHex > Grid.Num())
|
||||
{
|
||||
RandHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
|
||||
}
|
||||
return Grid[RandHex];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user