The following example is intended for vb6:
The code below shows a simple bounding box collision. Your planes and your missles make up an invisible boxes on the screen defined by:
left=left
right = left+width
top=top
bottom=bottom+height.
These bounding boxes can be coded as RECT data types and Windows can check if they collide by creating an intersection of rectangles then checking if the new rectangle has any area.
Put this code in a form and run and in the caption it will tell you if the rectangle controlled by the mouse has collided with the red rectangle. No math no border checks. Press any key to exit demo.
Code:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function IsRectEmpty Lib "user32" (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 ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Dim s1 As RECT
Private Sub Form_KeyPress(KeyAscii As Integer)
showmouse
Unload Me
End Sub
Private Sub Form_Load()
Me.hidemouse
With Me
.MousePointer = 15
.BackColor = 0
.WindowState = 2
.AutoRedraw = True
.ScaleMode = vbPixels
.Show
s1.Left = .ScaleWidth / 2
s1.Right = .ScaleWidth / 2 + .ScaleWidth / 15
s1.Top = .ScaleHeight / 2
s1.Bottom = .ScaleHeight / 2 + .ScaleHeight / 15
Line (s1.Left, s1.Top)-(s1.Right, s1.Bottom), RGB(255, 0, 0), B
Me.AutoRedraw = False
End With
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim m1 As RECT, x1 As RECT
m1.Top = Y: m1.Bottom = Y + 15
m1.Left = x: m1.Right = x + 15
Me.Refresh
Line (m1.Left, m1.Top)-(m1.Right, m1.Bottom), RGB(0, 0, 255), B
IntersectRect x1, m1, s1
If IsRectEmpty(x1) Then
Me.Caption = "Out of the box"
Else
Me.Caption = "In the box"
End If
End Sub
Sub showmouse()
Dim RET As Long
Do Until RET > 0
RET = ShowCursor(1&)
Loop
End Sub
Sub hidemouse()
Dim RET As Long
Do Until RET < 0
RET = ShowCursor(0&)
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
showmouse
End Sub
And if I were you, I'd get rid of the sun it's gonna melt that snowman!