存储 2d 平台游戏/卷轴游戏的生成信息

发布于 2024-09-14 06:57:31 字数 482 浏览 0 评论 0原文

我正在寻找一些关于如何最好地存储侧面卷轴的生成信息的想法。我正在编写的游戏与《超级马里奥兄弟》非常相似。我试图实现的是,当你通过一个关卡时,敌人应该在特定位置生成。我想将这些信息存储在关卡中,并且不想随机生成敌人。我正在寻找一种高级策略来在玩家到达特定位置(例如马里奥)时存储和检索生成的对象。我在谷歌搜索中找不到任何像样的教程或建议。

关卡是基于图块的,因此地图是图块[][]。现在每个图块都是 16x16 像素。

到目前为止,我看到的唯一好的建议是将生成信息存储在二维数组中,其中第一个维度是 x,第二个维度是 y,以图块空间给出。我在该实现中遇到的问题是,如果我的玩家位于 (160, 0),我想生成一个特定的敌人。然而,如果下次重置等级时玩家处于 (160, 5),我想生成相同的敌人。因此,为了使该实现正常工作,我必须扫描给定的 y 位置。

我正在寻找一种更高效的存储机械。我需要一些可以快速检索正确生成点的东西,而不是浪费太多存储生成位置的内存。

游戏中有什么常见的策略吗?

I'm looking for some idea's how best to store spawn information for a side scroller. The game I'm writing is very similar to Super Mario Bros. What I'm trying to implement is as you move through a level, enemies should spawn at particular locations. I want to store this information in the level and I don't want to just randomly spawn enemies. I'm looking for a high level strategy to store and retrieve the spawned objects when the player reaches a particular location (like mario). I couldn't find any decent tutorials or suggestions from Googleing around.

The Level is tile based so the map is Tile[][]. Each tile right now is 16x16 pixels.

The only good suggestion I've seen so far is to store the the spawning information in a 2d array where the first dimension is x and the second is y, given in tile space. The issue I have with that implementation is that if my player is at say (160, 0) I want to spawn a particular enemy. If however next time the level is reset the player is at (160, 5) I want to spawn the same enemy. So for that implementation to work I have to do a scan for a given y position.

I'm looking for a more efficient storage mechanize. I need something where I can retrieve the correct spawns quickly and not waist too much memory storing spawning locations.

Are there any common strategies in games for this?

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

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

发布评论

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

评论(1

饮湿 2024-09-21 06:57:31

只要生成点不是太多,一个简单的列表就可以了。每个列表条目都有 XY 坐标和生成信息。只需迭代列表即可确定玩家是否靠近重生点。这比稀疏填充的二维数组的内存效率要高得多,非常容易实现,而且可能足够快。

如果事实证明速度不够快,您需要某种空间索引,kd-trees实现起来相当简单,并且为邻近搜索提供良好的性能。
另一种解决方案是使用位置敏感哈希,如本文中所述(PDF)

As long as there are not too many spawn-points, a simple list will do. Each list entry has the XY coordinates and spawn info. Just iterate through the list to determine whether player is near a spawn point. This is much more memory efficient than a sparsly filled 2D array, very easy to implement, and probably fast enough.

If it turns out to be not fast enough you need some kind of spatial index, kd-trees are rather simple to implement and offer good performance for proximity search.
Another solution is to use a locality sensitive hash, as explained in this paper (PDF).

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