CodeItBetter Programming Another VB Programming Blog

How to Return a boolean whether two Rectangles collide

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'Graphics - How to Return a boolean whether two Rectangles collide
Option Explicit
 
Private Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, _
    lpSrc2Rect As RECT) As Long
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, _
    ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type
 
Private Sub Form_Load()
    Dim a As RECT, b As RECT, c As RECT
    SetRect a, 0, 0, 100, 100
    SetRect b, 50, 50, 150, 150
    If IntersectRect(c, a, b) Then
        'a and b collided
    End If
End Sub
Filed under: Graphics Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.