如何将运行时程序生成的世界划分为块
我一直在考虑制作一款具有伪无限运行时程序生成世界的自顶向下 2D 游戏。我读过几篇关于程序生成的文章,也许我误读或误解了它们,但我还没有遇到一篇解释如何将世界划分为块(就像《我的世界》显然所做的那样)。
显然,我只需要生成玩家当前可以看到的世界部分。例如,如果我的游戏是基于图块的,我可以将世界分为 n*n 个块。如果玩家位于这样一个块的边界,我也会生成相邻的块。
我不明白的是我到底如何采用程序世界生成算法并且一次只在一个块上使用它。例如,如果我有一种算法可以生成一个大型结构(例如城堡、森林、河流),该结构会分布在许多块中,我如何调整它以仅生成一个块,然后生成相邻的块?
表歉意。先感谢您!
I've been thinking of making a top-down 2D game with a pseudo-infinite runtime procedural generated world. I've read several articles about procedural generation and, maybe I've misread or misunderstood them, but I have yet to come across one explaining how to divide the world into chunks (like Minecraft apparently does).
Obviously, I need to generate only the part of the world that the player can currently see. If my game is tile-based, for example, I could divide the world into n*n chunks. If the player were at the border of such a chunk, I would also generate the adjacent chunk(s).
What I can't figure out is how exactly do I take a procedural world generation algorithm and only use it on one chunk at a time. For example, if I have an algorithm that generates a big structure (e.g. castle, forest, river) that would spread across many chunks, how can I adjust it to generate only one chunk, and afterwards the adjacent chunks?
I apologize if I completely missed something obvious. Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
研究中点位移算法。请注意,一侧的点均基于角点的起始值。您可以在不知道网格其余部分的情况下计算它们。
我用这种方法来生成地形。我需要每个“块”地形的边缘与相邻块对齐。使用中点位移算法的变体,我可以仅根据两个角的值来计算沿块边缘的每个点的高度。如果我需要添加随机性,我会使用两个角的数据播种随机数生成器。这样,任何两个相邻的块都可以独立生成,并且边缘肯定匹配。
您可以将高度图方法用于其他用途。这些数据可以确定植被类型、人口密度等,而不是高度。您可以拥有森林匹配的植被地图,而不是丘陵和山谷匹配的大块高度图。
对于任何类型的复杂世界来说,当然都需要一些创造性的编程。
Study the Midpoint displacement algorithm. Note that the points all along one side are based on the starting values of the corners. You can calculate them without knowing the rest of the grid.
I used this approach to generate terrain. I needed the edges of each 'chunk' of terrain to line up with the adjacent chunks. Using a variation of the Midpoint displacement algorithm I made it so that the height of each point along the edge of a chunk was calculated based only on values at the two corners. If I needed to add randomness, I seeded a random number generator with data from the two corners. This way, any two adjacent chunks could be generated independently and the edges were sure to match.
You can use approaches for height-maps for other things. Instead of height, the data could determine vegetation type, population density, etc. Instead of a chunks of height map where the hills and valleys match up you can have a vegetation map where the forests match up.
It certainly takes some creative programming for any kind of complex world.