【发布时间】:2018-03-21 07:16:17
【问题描述】:
我正在关注一些关于地图随机十六进制生成的教程。我目前正在尝试通过获取围绕该特定十六进制的其他十六进制来根据地图上的单个十六进制随机生成大陆。
这是我将所有相邻的十六进制放入数组的代码:
public HexCell[] GetHexWithinRange (HexCell centerHex, int range)
{
List<HexCell> hexWithinRange = new List<HexCell>();
int x = centerHex.coordinates.X;
int y = centerHex.coordinates.Y;
int z = centerHex.coordinates.Z;
int sequence = 0;
for (int dy = -range; dy < range + 1; dy++)
{
for (int dz = -range; dz < range + 1; dz++)
{
for (int dx = -range; dx < range + 1; dx++)
{
HexCell neighborHex = GetCellFromCoord(x + (float)dx,
y + (float)dy, z + (float)dz);
if (neighborHex == null)
{ continue; }
else
{
neighborHex.sequenceCheck = sequence++;
hexWithinRange.Add(neighborHex);
}
}
}
}
return hexWithinRange.ToArray();
}
Perfectly hexagonal shaped continent
虽然代码返回了一个形状完美的大陆,但它是将其他六角从外环对角线放入中心六角:
Sequence when the code is putting the neighboring hex into array
我真正希望它做的是从大陆内部获取相邻的十六进制并从那里移动到外部,直到它达到预期的半径,例如:
Sequence how I want the code to put the neighboring hex into array
我尝试提出一个公式,将相邻的十六进制逐个环放入数组中。但我想保持我的半径从中心十六进制成为一个变量。我怎么做?
【问题讨论】: