I'm making a game, where objects fall and you have to try to evade them. I'm using pictureboxes and they fall, and the object is able to move horizontally. The question I had was how do I make a loop so then once the pictureboxes fall off the form, they can spawn randomly (the pictureboxes have different set speeds) at the top and fall again?
Another problem I had was how do I have it so once a powerbar falls down to zero, the game ends, so say the object at the bottom gets hit 4 times, then the power bar falls to zero and the game ends. Those are the last two steps I need to finish the game.
first off
are you counting how many picture boxes you have are just throwing them down randomly, if you want another to appear when 1 has disappeared at the bottom then you need to keep a count.
Example,
you randomly spawn boxes at random speeds until you reach 10 total boxes, then after your collision detection detects a box has left the screen(collided with an invisible line under the play area) then remove the box, decrement the box count
on the next frame loop do a check if the number is not maximum if its not then add a box and start the process again
Second
you need to set conditions for pausing the game, bringing up menus, scores, continues etc
inside the main game loop you put a controllable infinite loop inside an if statment.
example
while gameon = true
------
--Game Code
------
if energybar = 0 then
ShowScoreForm = true
end if
while showscoreform = true
if scoreform.visible=false then
scoreform.visible = true
end if
------------
------------
-----------
loop
loop
you would have a button on the form which would stop the wholegame loop, or just the showscoreform loop and continue game after resetting it or something
and best put all codes into subs to keep your loop tidy, if yourusing a timer and not a loop then just change it as necessary
hope this helps
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work
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:
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
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 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
while gameon = true
------
--Game Code
------
if energybar = 0 then
ShowScoreForm = true
end if
while showscoreform = true
if scoreform.visible=false then
scoreform.visible = true
end if
------------
------------
-----------
loop
loop
thats a little tidier, dont forget to let your system breath, ill say put doevents method in all your tight loops, with something liki this performance wont be an issue.
no doubt 50 people will jump in here and shout all the better ways to do it
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work
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
I would actually select to have a random Y as well, a negative value so it doesn't immediately appear on screen again after its fallen down. Something like:
-rand.Next(10) * PictureBox.Height
I would actually select to have a random Y as well, a negative value so it doesn't immediately appear on screen again after its fallen down. Something like:
-rand.Next(10) * PictureBox.Height
That's true, it'd look kind of jumpy if it were to just appear on the screen.
no doubt 50 people will jump in here and shout all the better ways to do it
GBeats, I want you to take a look at this article.... When WinForms met the game loop that really helped me out that I think people should read when deciding when to use a 'game' loop and when to just draw in 'WinForm' fashion. In this case, I believe that it should be in a 'WinForm' fashion.
This should be in the games and graphics section as we got game experts here.
It is generally not wise to use a bunch of pictureboxes for games, let alone timers. There are graphical functions built in to vb.net, but if you want better graphics, you can use APIs such as BitBlt, StretchBlt, and TransparentBlt, all of which allow transparency which remove the background from an image, or if you wanna take advantage of the video hardware for either 2D / 3D theres DirectX and XNA.
You are also gonna need a gameloop locked at 60 frames per second. Im gonna be home shortly from work so Ill copy and paste code showing you how. And if you want real falling physics, Ill show you around that time as well.
there's pros and conns like it says dday9, like i say if your going to do it, might as well do it right, even if its not necessary its good practice.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work
At the bottom of the screen, there is a picturebox that you, the player controls and it moves souly on the x axis. As the pictureboxes from above fall, you have to move left or right to evade them. So if the object the player controls is hit 4 times by the falling object then the game is over.
This should be in the games and graphics section as we got game experts here.
It is generally not wise to use a bunch of pictureboxes for games, let alone timers. There are graphical functions built in to vb.net, but if you want better graphics, you can use APIs such as BitBlt, StretchBlt, and TransparentBlt, all of which allow transparency which remove the background from an image, or if you wanna take advantage of the video hardware for either 2D / 3D theres DirectX and XNA.
You are also gonna need a gameloop locked at 60 frames per second. Im gonna be home shortly from work so Ill copy and paste code showing you how. And if you want real falling physics, Ill show you around that time as well.
I would love to see that, but for the moment it's just a simple game. I've never used the hardware you're talking about and I'm relatively new to programming. I'd like to look at it and learn about it though.
At the bottom of the screen, there is a picturebox that you, the player controls and it moves souly on the x axis. As the pictureboxes from above fall, you have to move left or right to evade them. So if the object the player controls is hit 4 times by the falling object then the game is over.
Ahh I gotcha know! What you want to do is declare an integer variable like I did above, only check if the picturebox.Bounds intersects with the picturebox the user's controlling:
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 Sub check_pb()
For Each pb As PictureBox In Me.Controls.OfType(Of PictureBox)()
If pb.Bottom >= Me.Bottom AndAlso hit < 3 Then
'Falling pb hits the bottom
pb.Location = New Point(r.Next(0, Me.Width), -5 - pb.Height)
ElseIf pb.Bounds.IntersectsWith(player_picturebox.Bounds) Then
'Hit
hit += 1
ElseIf hit = 4 Then
'end game
End If
Next
End Sub
End Class
Public Class Form1
Dim RainDrops As Integer
Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyValue = Keys.Left Then
picCharmander.Left = picCharmander.Left - 10
End If
If e.KeyValue = Keys.Right Then
picCharmander.Left = picCharmander.Left + 10
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PictureBox2.Top = PictureBox2.Top + 6
PictureBox3.Top = PictureBox3.Top + 4
PictureBox4.Top = PictureBox4.Top + 5
PictureBox5.Top = PictureBox5.Top + 7
PictureBox6.Top = PictureBox6.Top + 5
PictureBox7.Top = PictureBox7.Top + 4.5
PictureBox8.Top = PictureBox8.Top + 3
PictureBox9.Top = PictureBox9.Top + 5
PictureBox10.Top = PictureBox10.Top + 5.7
End Sub
End Class
This is what I have right now, like I said, and if I didn't I'm sorry, but pretty basic. The pictures fall and the picture at the bottom moves. Also if there is a more efficient way to have this written, that would be nice. This is the only way I know to write it.
Last edited by cheekson; May 13th, 2013 at 02:20 PM.
Ahh I gotcha know! What you want to do is declare an integer variable like I did above, only check if the picturebox.Bounds intersects with the picturebox the user's controlling:
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 Sub check_pb()
For Each pb As PictureBox In Me.Controls.OfType(Of PictureBox)()
If pb.Bottom >= Me.Bottom AndAlso hit < 3 Then
'Falling pb hits the bottom
pb.Location = New Point(r.Next(0, Me.Width), -5 - pb.Height)
ElseIf pb.Bounds.IntersectsWith(player_picturebox.Bounds) Then
'Hit
hit += 1
ElseIf hit = 4 Then
'end game
End If
Next
End Sub
End Class
Ok, so how would I implament that into my game, with the names I have for things?
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
if you are familiar with classes and even if not, this would be a perfect opportunity to learn.
turn your pictureboxes into objects with falling speed, position, and picture properties with a contructor
just something simple like
class box
private FSpeed as single
private PosX as long
private PosY as Long
public sub New()
'for speed use 3+ a random number between 0 and 5 say
posy = top of course
posX = random numberbetween Left and width
end sub
create some functions to get the fspeed, posx,y inside the class
then you can create a list of boxes
public boxes as new list(of box)
then with every tick event if theres less then 10 in the list add a new one
boxes.add and it will calculate everything for you
then just handle the movement using the functions in the class
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work
if you are familiar with classes and even if not, this would be a perfect opportunity to learn.
turn your pictureboxes into objects with falling speed, position, and picture properties with a contructor
just something simple like
class box
private FSpeed as single
private PosX as long
private PosY as Long
public sub New(iPicture as object)
'for speed use 3+ a random number between 0 and 5 say
posy = top of course
posX = random numberbetween Left and width
end sub
create some functions to get the fspeed, posx,y inside the class
then you can create a list of boxes
public boxes as new list(of box)
then with every tick event if theres less then 10 in the list add a new one
boxes.add and it will calculate everything for you
then just handle the movement using the functions in the class
I'm vaguely familiar with classes. I'll look into that and when I get the chance, I'll try it out. I'm learning a lot here, Thanks.
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
I think this is the last question, how do I change the speed and number of pictureboxes falling. This is for harder or easier levels. Before, when I had all the pictureboxes typed out I could see and change what their falling speeds were, how do I do that with the new code written here?
Last edited by cheekson; May 13th, 2013 at 03:24 PM.
To change the speed, you have two options. Either decrease the timer interval so that they move more often, or increase the distance they move each time. The performance will be better if you choose the latter, but motion will be better if you choose the former. If you move too far in each interval, the motion will become jerky.
To add more pictureboxes, wouldn't you just add them to the pbList that you already have? You could create a bunch of them with visibility set to False, then move them in and out of the list to add more or less of them.
To change the speed, you have two options. Either decrease the timer interval so that they move more often, or increase the distance they move each time. The performance will be better if you choose the latter, but motion will be better if you choose the former. If you move too far in each interval, the motion will become jerky.
To add more pictureboxes, wouldn't you just add them to the pbList that you already have? You could create a bunch of them with visibility set to False, then move them in and out of the list to add more or less of them.
That's what I was thinking, just wasn't sure if there was some specific way to go about doing it.
Probably not, unless you start running into performance issues. There are many possible ways to do any part of that, some are a bit more efficient than others. Try whatever feels good to you, and if that proves to be too slow, then you can change it. I'd suggest altering the timer interval, first, as that will tend to have the best visual result. If you get enough pictureboxes, and they are falling fast enough, then the display might appear to stutter, in which case it is time to try something else.
One thing you might consider is that each control has a .Tag property that you can use for whatever you want. Suppose you put an integer into the .Tag property for each of your PB controls. Then, when the timer ticks, you might do something like this:
PB.Top += CInt(PB.Tag) * someFactor
The larger the integer in PB.Tag, the faster the PB will move down the screen. someFactor can start out at 1 for the first level, then become 1.1, 1.2, etc, for each subsequent level, and the PB will appear to move faster and faster as someFactor increases. However, this is changing the rate of change of the PB rather than changing the timer interval, so it could get ugly fast. Decreasing the interval rather than increasing someFactor would have the same result, but a smoother motion.
Probably not, unless you start running into performance issues. There are many possible ways to do any part of that, some are a bit more efficient than others. Try whatever feels good to you, and if that proves to be too slow, then you can change it. I'd suggest altering the timer interval, first, as that will tend to have the best visual result. If you get enough pictureboxes, and they are falling fast enough, then the display might appear to stutter, in which case it is time to try something else.
One thing you might consider is that each control has a .Tag property that you can use for whatever you want. Suppose you put an integer into the .Tag property for each of your PB controls. Then, when the timer ticks, you might do something like this:
PB.Top += CInt(PB.Tag) * someFactor
The larger the integer in PB.Tag, the faster the PB will move down the screen. someFactor can start out at 1 for the first level, then become 1.1, 1.2, etc, for each subsequent level, and the PB will appear to move faster and faster as someFactor increases. However, this is changing the rate of change of the PB rather than changing the timer interval, so it could get ugly fast. Decreasing the interval rather than increasing someFactor would have the same result, but a smoother motion.
What's "Cint"? Also, what if I want them to move at different speeds? I don't see how that would change.
But my point is, is that you should avoid using pictureboxes to make games with.
I'll start you off with built in graphics functions in vb.net. This is some source code that will allow you to load an image from file in memory, and display it with a game loop locked at 60 FPS and improved controls, so you don't get that lag of holding down the key:
vb.net Code:
Option Explicit On
Option Strict On
Public Class Form1
Private Declare Function QueryPerformanceCounter Lib "Kernel32" (ByRef X As Long) As Integer
Private Declare Function QueryPerformanceFrequency Lib "Kernel32" (ByRef X As Long) As Integer
Private Structure Sprite_Type
Public X As Integer
Public Y As Integer
Public Width As Integer
Public Height As Integer
End Structure
'Key Functions
Private Const P1_UP As Keys = Keys.Up
Private Const P1_DOWN As Keys = Keys.Down
Private Const P1_LEFT As Keys = Keys.Left
Private Const P1_RIGHT As Keys = Keys.Right
'Key Flags (MUST BE IN BINARY FORMAT THE MORE KEYS YOU USE: ex. 1, 2, 4, 8, 16, 32, 64, 128, etc.
Private Const P1_UP_FLAG As Integer = 1
Private Const P1_DOWN_FLAG As Integer = 2
Private Const P1_LEFT_FLAG As Integer = 4
Private Const P1_RIGHT_FLAG As Integer = 8
Private Ticks_Per_Second As Long
Private Start_Time As Long
Private Milliseconds As Integer
Private Get_Frames_Per_Second As Integer
Private Frame_Count As Integer
Private Keystate As Integer
Private Running As Boolean
Private Texture As Image
Private Texture_Graphics As Graphics
Private newGraphics As Graphics
Dim Backbuffer As Bitmap
Dim Backbuffer_Graphics As Graphics
Private Sprite As Sprite_Type
Private Function Hi_Res_Timer_Initialize() As Boolean
If QueryPerformanceFrequency(Ticks_Per_Second) = 0 Then
Texture_Graphics.DrawImage(Texture, New RectangleF(Sprite.X, Sprite.Y, Sprite.Width, Sprite.Height))
End Sub
Private Sub Game_Loop()
Do While Running = True
Keyboard_Control()
Render()
Lock_Framerate(60)
Me.Text = Get_FPS()
Application.DoEvents()
Loop
End Sub
Private Sub Main()
With Me
.Show()
.Focus()
.DoubleBuffered = True
.KeyPreview = True
End With
Backbuffer_Graphics = Me.CreateGraphics()
Load_Texture()
Setup_Sprite()
Hi_Res_Timer_Initialize()
Running = True
Game_Loop()
End Sub
Private Sub Shutdown()
Running = False
Application.Exit()
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case P1_UP
Keystate = Keystate Or P1_UP_FLAG
Case P1_DOWN
Keystate = Keystate Or P1_DOWN_FLAG
Case P1_LEFT
Keystate = Keystate Or P1_LEFT_FLAG
Case P1_RIGHT
Keystate = Keystate Or P1_RIGHT_FLAG
End Select
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
Select Case e.KeyCode
Case P1_UP
Keystate = Keystate And (Not P1_UP_FLAG)
Case P1_DOWN
Keystate = Keystate And (Not P1_DOWN_FLAG)
Case P1_LEFT
Keystate = Keystate And (Not P1_LEFT_FLAG)
Case P1_RIGHT
Keystate = Keystate And (Not P1_RIGHT_FLAG)
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Main()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.FormClosing
Shutdown()
End Sub
End Class
Its a rushed project but it works. I have the image you can download as an example, which is Link from Legend of Zelda. No pictureboxes or timers used :P
Now for falling physics, you just don't wanna have it go at a constant speed and hit the ground. You wanna make it interesting. The formula for gravity is F = MG which is force = mass * gravity. This is used in acceleration. Acceleration can equal this force. You are also gonna wanna integrate it. Im gonna start you off with the Forward Euler integrator:
Where dt is your time step. A basic time step would be 1 / 100, which are typically used in physics engines. Although there are more advanced integrators out there, this is the easiest to understand. The gravity constant youll need for earth gravity is 9.80665. Mass is measured in kilograms, however, if you want pounds, youll have to have your mass in pounds be converted to kilograms by this formula:
Code:
Dim POUNDS_TO_KG As Single = 0.45359237
Dim Mass as Single
Mass = 10 * POUNDS_TO_KG
To get these physics going, this is the code I use to update physics:
Code:
Private Sub Update_Physics
Delta_Time = Get_Elapsed_Time_Per_Frame
If Delta_Time > 0.25 Then Delta_Time = 0.25
Accumulator = Accumulator + Delta_Time
While (Accumulator >= Time_Step)
Accumulator = Accumulator - Time_Step
Integrate2D Obj, Time_Step
Time = Time + Time_Step
Wend
End Sub
And then it hits you. You need collision detection. So a basic box to box collision detection would be something like this:
Code:
Public Structure Box
X As Single
Y As Single
W As Single
H As Single
VX As Single
VY As Single
End Structure
Public Function AABBCheck(B1 As Box, B2 As Box) As Boolean
'returns true if the boxes are colliding (velocities are not used)
Dim B1 As Box
Dim B2 As Box
Return Not (((B1.X + B1.W < B2.X) Or (B1.X > B2.X + B2.W) Or (B1.Y + B1.H < B2.Y) Or (B1.Y > B2.Y + B2.H)))
End Function
And if you have any more questions, let me know
Last edited by Jacob Roman; May 13th, 2013 at 03:42 PM.
At the moment, I don't really get this, I haven't learned a lot of what you have written up there. I'd like to learn it, eventually. I'll look at it later this week and respond.
Yeah, I would avoid the use of Pictureboxes as well. And especially creating a new instance of one for every falling object. If you're going to be using Pictureboxes you should be trying to reuse them as much as possible for each "new" falling object. Create a max number of Picturebox instances, and then for how many you want to appear on screen, you'll need a way to measure that, which could be from a counter variable. A class could encapsulate the Picturebox itself, along with properties for direction, and speed (in case you wanted them to fall on angles perhaps). From here, the variables would stay constant, and be set to random values upon reset time; when they hit the bottom and are ready in the queue to become placed at the top again to "fall." These values would not be reset again, until the object has hit the bottom, giving the illusion that you have a new object falling each time because of a different in speed, and perhaps direction, image, or whatever else you decide to change...
That's if you use Pictureboxes though. You don't want to have to deal with creating new instances and managing each new instance all the time if you can avoid doing that.
The worst possible solution is to create new pictureboxes each time. That's about the most costly thing you can do, so do as AceInfinity said, or even better, figure out what JR is on about....then figure out what his post was about....and if you figure out the first part, let the rest of the world know. Still, the point is a good one. Manipulating controls can take you a fair distance, but you can only do a certain amount of that before you run up against the performance limits. I'm not quite sure where those limits are, but they aren't very far up. Eventually, the cost entailed in moving the controls around is going to make further performance improvements impossible. For a small number of PB, you should have no problems. Above that number the game will cease to function smoothly no matter what you do. The key question is: Where is that limit? It's probably in the vicinity of a dozen controls, but could be lower or higher. Creating new pictureboxes each time will drop the limit, reusing a collection of them will increase the limit.
CInt is the fastest way to convert a string or object into an Integer, but it only works if the item really can be converted (because it IS an integer, in the case of an Object, or because it is a string representation of an Integer in the case of a string).
You are only limited to 255 controls on the form at once. I hit that limit before.
VB6 had that limitation but not VB.Net.
In all honesty for a very simple game like this when you have some objects "falling" down the screen and one playable object that you move left and right using picture boxes is fine. As soon as one of the picture boxes fall below the the Form bottom just move it up again as suggested earlier in this thread. Learning more about graphics and DirectX is fine if you want to do more advanced stuff. Depending on the size of the falling object you probably don't need much more than 10 to 15 picture boxes and that is really nothing to worry about. Just reuse them by moving them to the top when they have fallen down. Doing anything else is just overkill.