A few things:
1) You don't have to type out every picturebox like that
2) you don't have to set the Top like that as well
From what you gave me there I'd do something like this:
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 hit As Integer = 1 Private pbList As New List(Of PictureBox) Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load pbList.AddRange({PictureBox2, PictureBox4, PictureBox5, PictureBox6, PictureBox7, PictureBox2, PictureBox8, PictureBox9, PictureBox10}) Timer1.Start() End Sub Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick For Each pb As PictureBox In pbList pb.Top += 5 If pb.Bottom >= Me.Bottom Then 'Hit the bottom pb.Location = New Point(r.Next(0, Me.Width), -r.Next(0, 10)) ElseIf pb.Bounds.IntersectsWith(picCharmander.Bounds) Then 'Hit charmander hit += 1 pb.Location = New Point(r.Next(0, Me.Width), -r.Next(0, 10) - Me.Height) ElseIf hit = 4 Then 'end game Timer1.Stop() End If Next End Sub Private Sub Form1_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown If e.KeyCode = Keys.Left Then picCharmander.Left -= 10 ElseIf e.KeyCode = Keys.Right Then picCharmander.Left += 10 End If End Sub End Class




Reply With Quote