Hi Nathan,
The following code was posted a while back. It does collision detection on
Controls.
To use it simply call it with a pair of Controls:
If ControlsOverlap (picBullet, picTarget) Then
MsgBox ("Target Destroyed!!")
End If
Regards,
Fergus
<code>
'--------------------------------------------------------------
'The Controls given as parameters are assumed to occupy rectangles
'as determined by .Top, .Left, .Height, and .Width properties.
'Returns True if, and only if, the rectangles occupied by the
'Controls overlap.
'
Function ControlsOverlap (c1 As Control, c2 As Control) As Boolean
Return IntervalsOverlap (c1.Top, c1.Top + c1.Height, _
c2.Top, c2.Top + c2.Height) _
And IntervalsOverlap (c1.Left, c1.Left + c1.Width, _
c2.Left, c2.Left + c2.Width)
End Function
'--------------------------------------------------------------
'An interval is a straight line. This function returns
'True if, and only if, intervals [a, b] and [x, y] intersect
'
Function IntervalsOverlap (a As Single, b As Single, _
x as Single, y As Single) As Boolean
Return WithinInterval (a, x, y) _
Or WithinInterval (b, x, y) _
Or WithinInterval (x, a, b) _
Or WithinInterval (y, a, b)
End Function
'--------------------------------------------------------------
'True if, and only if, x is within the interval [a, b]
'
Function WithinInterval (x As Single, _
a As Single, b As Single) As Boolean
Return (a <= x) And (x <= b)
End Function
</code>