|
发表于 2004-8-21 10:52:00
|
显示全部楼层
Re:???????????
?winapi????.?~~
IntersectRect
What is IntersectRect?
This function takes to RECT types and determines whether they overlap each other. Lets take a look at this function.
Public Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
lpDestRect ? This RECT will receive the area that the 2 RECTs crossed over. You would be able to use this RECT for pixel perfect detection. More on that in a later lesson (maybe)
lpSrc1Rect ? The first source RECT
lpSrc2Rect ? The second source RECT
[Code Start]
Dim tmpRECT as RECT
Dim PlayerX as Integer, PlayerY As Integer
Dim CompX As Integer, CompY as Integer
Dim PlayerRect as RECT, CompRect As RECT
//We are assuming the dimenions of the player are 50x50 and the comp 50x50
//createrect is a helper function I wrote for creating rects.
PlayerRect = CreateRect(PlayerX, PlayerY, PlayerX +50, PlayerY + 50)
CompRect = CreateRect(CompX,CompY,CompX + 50, CompY + 50)
If IntersectRect(tmpRECT,PlayerRect,CompRect) = True Then //there was an overlap between the 2 rects
//code here
End If
[Code Stop]
|
|