The answer to your first question is simple, check if the PictureBox.Bottom is greater than or equal to the Form's height or bottom. If it is, then set the PictureBox.Location equal to a random x and a constant y:
As for your second question, I'm not sure I understand your question. Is it: if the picturebox hits the bottom 4 times, the game ends? If so, then declare an integer variable and increment it by 1 when you set the PictureBox.Location:Code:Option Strict On Option Explicit On Public Class Form1 'Declare a new instance of the random object here, 'or declare it here, and set it as a new instance at the form load Private r As New Random Private Sub check_pb() For Each pb As PictureBox In Me.Controls.OfType(Of PictureBox)() If pb.Bottom >= Me.Bottom Then pb.Location = New Point(r.Next(0, Me.Width), 5) End If Next End Sub End Class
Code:Option Strict On Option Explicit On Public Class Form1 'Declare a new instance of the random object here, 'or declare it here, and set it as a new instance at the form load Private r As New Random Private bottom_hit As Integer = 1 Private Sub check_pb() For Each pb As PictureBox In Me.Controls.OfType(Of PictureBox)() If pb.Bottom >= Me.Bottom AndAlso bottom_hit < 3 Then pb.Location = New Point(r.Next(0, Me.Width), 5) bottom_hit += 1 ElseIf pb.Bottom >= Me.Bottom AndAlso bottom_hit = 4 Then 'End the game here End If Next End Sub End Class




Reply With Quote