自上而下的游戏 - 检查、绘制有障碍物的敌人视线区域
我需要的示例:
我正在使用 cocos2d 绘制 CCTMXTiledMap,在这些图块上我必须绘制 LOS 三角形。
考虑到障碍物,我将如何测试玩家是否在该三角形内? 我如何像上面的例子一样绘制视线区域?
顺便说一句,我不确定这是否应该发布在这里或游戏开发上,别生气。
Examples of what i'm going to need:
I'm using cocos2d to draw a CCTMXTiledMap, on those tiles i'll have to draw the LOS triangle.
How would i test if the player is within that triangle, taking obstacles into account?
How would i draw the line of sight area like in the examples above?
BTW, i wasn't sure if this should have been posted here or on gamedev, don't be mad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望查看多边形内的点算法,例如此处描述的光线投射算法。
您可以分解三角形来考虑障碍物,或者只是制作一个更复杂的多边形。您应该能够在线找到适合您需求的实现。
您可能还想看看这篇文章以获得一些灵感。您可以维护一个类似树的结构,一个根三角形(或支点),可用于确定一个点是否在一般视线内,子级(三角形)考虑障碍物。这样您就可以快速消除更复杂的检查。
在下图中,深蓝色点很快就被排除在进一步检查之外,因为它们不落在根观察三角形内。
You may wish to look at point-in-polygon algorithms such as the ray casting algorithm described here.
You can break up the triangle to account for obstacles, or just make a more complex polygon. You should be able to find an implementation to suit your needs online.
You may also want to take a look at this article for some inspiration. You can maintain a tree like structure, a root triangle (or fulcrum) that can be used to determine whether a point is in general line of sight, with the children (triangles) taking obstacles into account. That way you can quickly eliminate more complex checks.
In the image below the dark blue dots are quickly eliminated from further checking as they do not fall within the root viewing triangle.