两个图片碰撞检测

nileileini 2009-11-07 05:58:33

______ _______
| | | |
| A | | B |
------ -------

我做一个贪吃蛇游戏,导入两个BITMAP类型的图片,现在的问题是检测A和B接触的条件.

 1.用RECT吗?怎么样把图片弄进RECT里,A的up坐标==B的top坐标 A的right坐标==B的left坐标

 新手,不大会用这些函数,不知道怎样把图片弄成坐标
...全文
276 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhigang34 2009-11-07
  • 打赏
  • 举报
回复
位图是矩形的,要通过矩形来进行碰撞检测,最好做点处理..比如下面两张图片,A,B;
图片的矩形区域用-和|圈出来了,而实际的区域用*圈出,些时两张图片是相撞的,但图片中的真实内容并没有碰撞,所以游戏的效果可能就很假了.可以根据需要,取图片的m/n来作为碰撞检测的矩形.


|-----------
| * |
----------- * * |
| **** || * * |
| * * || * * |
| * A * || * B * |
| ****** || * * |
| ********|


jwybobo2007 2009-11-07
  • 打赏
  • 举报
回复
无非是判断坐标是否相交,想想中学学的直角坐标系,是怎么判断相交的
schlafenhamster 2009-11-07
  • 打赏
  • 举报
回复
IntersectRect
The IntersectRect function calculates the intersection of two source rectangles and places the coordinates of the intersection rectangle into the destination rectangle. If the source rectangles do not intersect, an empty rectangle (in which all coordinates are set to zero) is placed into the destination rectangle.
BOOL IntersectRect(
LPRECT lprcDst, // pointer to structure for intersection
CONST RECT *lprcSrc1, // pointer to structure with first rectangle
CONST RECT *lprcSrc2 // pointer to structure with second rectangle
);
//
IsRectEmpty
The IsRectEmpty function determines whether the specified rectangle is empty. A empty rectangle is one that has no area; that is, the coordinate of the right side is less than or equal to the coordinate of the left side, or the coordinate of the bottom side is less than or equal to the coordinate of the top side.

BOOL IsRectEmpty(
CONST RECT *lprc // pointer to structure with rectangle
);

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧