首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >创建一个二维的圆形迷宫

创建一个二维的圆形迷宫
EN

Game Development用户
提问于 2018-05-05 23:39:15
回答 1查看 3.5K关注 0票数 3

如何创建一个2d程序生成的圆形迷宫,如下所示:

EN

回答 1

Game Development用户

发布于 2018-05-06 01:13:19

任何只依赖于一组节点(几乎全部)的迷宫生成算法都能工作。不是创建网格,每个网格点都是一个节点,它们连接到它们的邻居,您需要以圆形的形式生成它们。

所以,首先,中心是一个节点。假设下一层有6个节点,中间连接到所有节点。为了确保迷宫保持一致,每一层(除了第二层)应该有两倍多的节点,因为在最后一层中的每个节点都需要一个相邻的节点,并且需要在它们之间添加一个额外的节点,这样迷宫就会随着你离中心越远而变得更加详细。

这方面的伪代码:

代码语言:javascript
复制
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
票数 5
EN
页面原文内容由Game Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://gamedev.stackexchange.com/questions/158299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档