2D瓦片地图生成

发布于 2024-10-12 08:49:42 字数 450 浏览 8 评论 0原文

对于 2D 图块引擎,我正在研究地图生成算法。我尝试了高度图生成:

  • 山丘生成
  • 柏林噪声
  • 钻石方形

适合具有高度分量的平铺地图,但我有像草,海,沙漠这样的精灵,它们应该放置如下:

  • 从海洋
  • 岛屿开始的所有东西都放置在中间地图(这是我尝试的算法大多失败的地方)
  • 生成沙漠(它们应该像周围的随机点)
  • 生成山脉和山链(它们应该像蛇)

我应该尝试什么方法?

我解决了沙漠、丘陵和山脉(例如山脉从一个点开始,然后沿着一个有转弯机会的方向),但我在生成岛屿时失败了(应该可定制为盘古大陆或许多程度的大小) )。

我正在寻找类似文明算法的东西:

alt text

For a 2D tile engine I'm working on map generation algorithms. I tried heightmap generation :

  • hill generation
  • Perlin noise
  • Diamond-square

Suitable for tile maps that have a height component but I have sprites like grass, sea, desert and they should be placed like :

  • everything starts from ocean
  • islands are placed in the middle of the map (this is where algorithms that I tried failed mostly)
  • deserts are generated (they should be like random spots around)
  • mountain and hill chains are spawned (they should be like snakes)

What approach should I try?

I solved deserts, hills and mountains (for example mountain starts from a point then follows a direction with a chance of turning) but I'm failing with the generation of islands (which should be customizable to be just a pangea or many degrees of size).

I'm looking for something like the Civilization algorithm:

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千寻… 2024-10-19 08:49:42

[hill Generation、perlin、diamond square] ...这种算法似乎适合处理也具有高度分量的图块地图,但这不是我的情况。

但这是你的情况。山高于平原,平原高于水。

                        ___/
                    ___/ ___ Mountain cutoff
                ___/
         ______/
    ____/ ___ Water cutoff
__/

您可以量化数据,以便如果它位于一组级别之间,则将其视为一种图块类型,而当其位于不同范围内时,则将其视为不同类型的图块。您将丢弃一些细节,但您仍然会得到与您生成的噪声类型相匹配的轮廓。

它可能需要大量的调整,并且需要您自己生成其他陆地特征(除了不可逾越的山脉),但您必须对任何内容生成解决方案进行大量调整。

[hill generation, perlin, diamond square] ... this kind of algorithms seems suitable when dealing with tile maps that also have a height component but this is not my case.

But it is your case. Mountains are higher than plains, and plains are higher than water.

                        ___/
                    ___/ ___ Mountain cutoff
                ___/
         ______/
    ____/ ___ Water cutoff
__/

You can quantize your data so that if it is between one set of levels, it is counted as one type of tile, whereas when it is in a different range, it is a different type of tile. You'll be throwing out some detail, but you'll still get outlines that match the type of noise that you're generating.

It'll probably take a good amount of tweaking, and will require you to generate other land features (besides impassible mountains) yourself, but you'll have to tweak a lot with any content generation solution.

萌能量女王 2024-10-19 08:49:42

我使用了一种被其他人称为使用“蚂蚁”来创建随机地形的方法。所用方法的描述:

首先,我使用专用图块类的二维矩形数组 (x,y) 生成图块地图。图块类保存与图块相关的信息,例如绘图点和地形类型。

然后我创建了一个特殊的“ant”类,它可以被认为是一个不可见的实体,在瓦片地图周围“行走”。每当蚂蚁移动到新的图块时,底层的地形类型就会发生变化。蚂蚁可以向 8 个方向移动,并且每移动一格就会改变方向。每一步之后的方向是随机的。

我生成固定或随机数量的蚂蚁,它们的寿命是固定或随机的。生命周期是指它在被移除之前可以遍历/步进的瓷砖数量。

为了能够控制最常见的地形类型,我创建了一个“地形类型”数组。该数组包含地形类型列表(基本上只是一个 int)。为了在所有类型的地形之间获得平等的平衡,您只需将每种地形类型之一添加到地形类型数组中。如果您希望某种地形类型更常见,您可以使用该特定地形类型向数组添加更多条目。

然后,当蚂蚁需要确定要更改的地形时,您可以使用随机整数作为数组索引在地形类型数组中进行查找。

这需要对参数(蚂蚁数量、蚂蚁寿命、地形类型数组)进行一些调整,但到目前为止我已经实现了一些非常好的地形。

它可以通过使用更复杂类型的蚂蚁类来进一步增强,例如以专门的模式遍历等。为了在海洋中创建可信的岛屿,您可能需要修改蚂蚁的行为,以便它们在以下方面有一些限制:移动方式(这样你就不会随机得到长长的“尖刺”土地、非常分散的小岛屿等)。

下面是一个森林图块地图的示例,它是由我使用 ant 方法制作的一个小应用程序生成的。希望这可以帮助您走上自己的道路!

您可以在 Github

程序生成的森林部分的 2D 平铺地图

I used an approach which others have referred to as using "ants" for creating the random terrain. A description of the approach used:

First, I generated a tilemap by using a twodimensional rectangular array (x,y) of a specialized tile class. The tile class holds tile related information such as drawpoint, and terrain type.

Then I created a special "ant" class, which can be thought of as an invisible entity that takes "steps" around the tilemap. Every time the ant moves to a new tile, the underlying terrain type is changed. The ant can move in 8 directions and it changes direction, every time it has moved one tile. The direction it takes after each step is random.

I spawn either a fixed or random amount of ants with a fixed or random amount of lifetime. Lifetime is the amount of tiles it can traverse / step to before being removed.

To be able to control what kind of terrain is most common, I create an "terrain type" array. This array contains a list of the terrain types (basically just an int). To get equal balance between all types of terrain, you add only one of each terrain type to the terrain type array. If you wanted a certain terrain type to be more common, you would add further entries to the array, with that particular terrain type.

Then when the ant needs to determine what terrain to change, you do a lookup in the terrain type array using a random integer as the array index.

It takes a bit of tweaking the parameters (ant amount, ant lifetime, terrain type array), but I'm achieving some really good terrains so far.

It could be further enhanced by using more sophisticated types of ant classes, that for example traversed in specialized patterns etc. For making believeable islands in a ocean, you'd probably want to modify the ant behavior so they have some constraints in terms of which way to move (so you don't randomly get long "spikes" of land , very dispersed small islands etc).

The below is an example tilemap of a forest, that's generated procedurally by a little app I made using the ant approach. Hope this can set you on your way!

You can get the source of the app (VB.NET) at Github

Procedurally generated 2D tile map of a forest section

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文