如何创建一个2d程序生成的圆形迷宫,如下所示:
发布于 2018-05-06 01:13:19
任何只依赖于一组节点(几乎全部)的迷宫生成算法都能工作。不是创建网格,每个网格点都是一个节点,它们连接到它们的邻居,您需要以圆形的形式生成它们。
所以,首先,中心是一个节点。假设下一层有6个节点,中间连接到所有节点。为了确保迷宫保持一致,每一层(除了第二层)应该有两倍多的节点,因为在最后一层中的每个节点都需要一个相邻的节点,并且需要在它们之间添加一个额外的节点,这样迷宫就会随着你离中心越远而变得更加详细。
这方面的伪代码:
nodes is an empty set of nodes
put central node in nodes
put the second layer's nodes in nodes
connect the first and second layer
let currentLayerCount be 12
for every layer
for i from 0 to currentLayerCount
create a node with a position
x: cos(2*pi / currentLayerCount) * layerId
y: sin(2*pi / currentLayerCount) * layerId
put node in nodes
if i is divisible by 2
connect the node to the neigbouring nodes in the same and last layer
else
only connect the node to the neighbouring nodes in the same layer
end if
end for
multiply currentLayerCount by 2
end for
https://gamedev.stackexchange.com/questions/158299
复制相似问题