2D 游戏的障碍路径检测

发布于 2024-09-24 02:17:30 字数 489 浏览 3 评论 0原文

我主要致力于平台游戏的开发,并且仍处于起步阶段,所以我对最佳实践/算法感到好奇。我的背景中只有一座城堡,底部大约 200 像素高,有一些草,稍微上下弯曲。在中间(这是背景 png 的一部分)我有一个圆角矩形岩石。所以没有什么是它自己独立的对象,只有角色和背景。

目前,我将角色的路径设置为初始化颜色数组并加载路径坐标字典。我这样做的方法是遍历 x 轴上的每个像素并向下(就像 (0,1), (0,2)...然后 (1,0), (1,1).. .)。当我发现第一个接近绿色的 RGB 值时,我将前面的 y 值存储到路径坐标字典中。因此,pathDictionary[0]=>563 的值将是草,而 562 将是草或路径上方的黑色。

对于中间的岩石,我只是有一个条件,即查看我的 x 坐标是否超出某个点,以及 y 坐标减去角色原点是否大于指示角色在背景。这显然不是我到处使用的方法,但我想知道是否有更有效的方法?也许查看 png,获取岩石的坐标并创建一个矩形?

根据你们的建议,跳到这块背景岩石上的最佳方式是什么?

I'm pretty much working on a platformer and still starting out so I was curious about best practices/algorithms. I have in my background just a castle and about 200px high at the bottom some grass which slightly curves up and down. In the middle (which is part of the background png) I have a rounded rectangle rock. So nothing is its own seperate object, just the character and the background.

Currently, I set up the path my character goes as initializing an array of colors and loading up a path coordinate dictionary. The way I do it is I go through each pixel on the x-axis and go down (so like (0,1), (0,2)... then (1,0), (1,1)...). The first instance I find of a RGB value of near green, I store the preceeding y value into the path coordinate dictionary. So a value of pathDictionary[0]=>563 would be the grass while 562 would be the black above the grass or the path.

For the rock in the middle, I simply have a condition where I see if my x-coordinate is beyond a certain point and if the y-coordinate minus the origin of my character is greater than a value indicating that the character met the rock in the background. This is obviously not an approach I'd use everywhere but I'm wondering if there is a more efficient way? Perhaps looking at the png, getting the coordinates of the rock and creating a rectangle?

Based on what you guys recommend, what would be the best way for jumping onto this background rock?

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

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

发布评论

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

评论(1

梦与时光遇 2024-10-01 02:17:30

最近向我介绍了音速物理指南,它是从《刺猬索尼克》系列中逆向设计的信息游戏。它可能有很多对您的任务有用的信息。

I was recently introduced to the Sonic Physics Guide which is information reverse engineered out of the Sonic the Hedgehog series of games. It may have a lot of useful information for your quest.

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