gladiator, if you plan to use picture boxes to hold your images, then Rectangle API functions will be very useful to you. You will perform the following steps to detect a collision.
1. Get the window rectangles of the two PBs.
2. Intersect the two rectangles.
3. If the resultant rectangle is not empty then the two PBs collide.
Here is a sample program to demonstrate this.
1. Start a new project.
2. Place a picture box on the form and set its Index = 0.
3. Place a timer on the form and set its Interval = 100.
4. Place the following code in the form.
___
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Private Declare Function IsRectEmpty Lib "user32" (lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Load Picture1(1)
Picture1(0).Move 1000, 1000, 1000, 1000
Picture1(1).Move 2500, 1000, 1000, 1000
Picture1(1).Visible = True
WindowState = vbMaximized
End Sub
Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
With Picture1(Index)
.CurrentX = X
.CurrentY = Y
.ZOrder
End With
End Sub
Private Sub Picture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
With Picture1(Index)
.Move .Left + X - .CurrentX, .Top + Y - .CurrentY
End With
End If
End Sub
Private Sub Timer1_Timer()
Dim R0 As RECT, R1 As RECT, R As RECT
Dim Collision As Boolean
GetWindowRect Picture1(0).hwnd, R0
GetWindowRect Picture1(1).hwnd, R1
IntersectRect R, R0, R1
Collision = IsRectEmpty(R) = 0
If Collision Then
Picture1(0).BackColor = vbRed
Picture1(1).BackColor = vbRed
Else
Picture1(0).BackColor = vbGreen
Picture1(1).BackColor = vbGreen
End If
End Sub
___
Run the program, you will see two green boxes (PBs) on your form. Drag them using the mouse around the form. As they cross the border of each other, they will turn red indicating a collision. As they are moved apart they will again turn green.
Read the code in Sub Timer1_Timer carefully. This is where the collision detection is being performed.