Part 6 - Keeping things in view
The
KeepInBounds method checks to see if the player is within the bounds of
the forms client area and if not prevents it from moving outside that
area. It then perform the same checking for each fly in the flies
collection.
Copy and paste the fallowing code into Form1
- Private Sub KeepInBounds()
- ' keep the player within the visible area of the form
- mobjPlayer.Position.X = RestrictValue(mobjPlayer.Position.X, 0, Me.ClientSize.Width - 1)
- mobjPlayer.Position.Y = RestrictValue(mobjPlayer.Position.Y, 0, Me.ClientSize.Height - 1)
- ' keep all flies within the visible area of the form
- For Each F As Fly In mobjFlies
- F.Position.X = RestrictValue(F.Position.X, 0, Me.ClientSize.Width - 1)
- F.Position.Y = RestrictValue(F.Position.Y, 0, Me.ClientSize.Height - 1)
- Next
- End Sub