19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

376 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

Public Sub GoDown(plane As CPlane, ByVal FormHeight As Integer)<br />

Dim j As Integer<br />

imgBomb.Left = plane.X + 0.5 * plane.W<br />

imgBomb.Top = plane.Y + plane.H<br />

imgBomb.Visible = True<br />

Do While imgBomb.Top < FormHeight<br />

imgBomb.Top = imgBomb.Top + 5<br />

RaiseEvent BombPositionChanged(imgBomb.Left, imgBomb.Top, _<br />

imgBomb.Width, imgBomb.Height)<br />

‘Pause<br />

For j = 1 To 2000<br />

Next j<br />

Loop<br />

imgBomb.Visible = False<br />

End Sub<br />

Public Sub Destroy()<br />

imgBomb.Visible = False<br />

End Sub<br />

Private Sub Class_Terminate()<br />

Set imgBomb = Nothing<br />

End Sub<br />

‘Form code<br />

Private bomber As CPlane<br />

Private plane As CPlane<br />

Private WithEvents bomb As CBomb<br />

Private Sub Form_Load()<br />

Set bomber = New CPlane<br />

Set plane = New CPlane<br />

Set bomb = New CBomb<br />

bomber.imagePlane = imgBomberPic<br />

plane.imagePlane = imgPlanePic<br />

bomb.imageBomb = imgBombPic<br />

End Sub<br />

Private Sub bomb_BombPositionChanged(X As Integer, Y As Integer, H As Integer,<br />

W As Integer)<br />

‘Check to see if Plane is hit, i.e. the bomb is inside plane or vice<br />

versa.<br />

If plane.Present() Then<br />

If (plane.X = X) And _<br />

(plane.Y = Y) Or _<br />

(X = plane.X) And _<br />

(Y = plane.Y) Then<br />

plane.Destroy<br />

bomb.Destroy<br />

End If<br />

End If<br />

End Sub<br />

Private Sub cmdMove_Click()<br />

bomber.Fly cboDirection.Text, frmPlanes.Height, frmPlanes.Width

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!