Having rows of aliens move down the form in a space invaders style game

shaz1

Member
Joined
Jul 22, 2013
Messages
9
Programming Experience
Beginner
Hi,


With the assistance of another tutorial, I have managed to get a set row of aliens moving across the screen and then down and across the screen again, repeating this until they reach the bottom. However, I would like another row of aliens to do this as well but I can't seem to get them working. They are spawned on the screen just won't move.
Any assistance or help in doing this would be much appreciated. Below is code: Thanks

Dim numberofinvaders AsInteger = 11
Dim setofinvaders As Integer = 2
Dim invader(numberofinvaders) As PictureBox
Dim invadersspawned As Integer = 0
Dim alienmove As Integer = 5
Dim invaders As Integer = 5


Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

For column As Short = 0 To setofinvaders - 1
For lc = 1 To numberofinvaders
invadersspawned = invadersspawned + 1
invader(lc) = New PictureBox
invader(lc).Image = imginvader.Images(0)
invader(lc).Height = 16
invader(lc).Width = 16
invader(lc).Location = New System.Drawing.Point((lc * 22) + 10, 10 + column * 10)
Me.Controls.Add(invader(lc))

Next
Next

End Sub


 
Private Sub tmrInvader_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrInvader.Tick
For count = 1 To 11
invader(count).Left = invader(count).Left + invaders
Next count
If invader(11).Left + invader(11).Width > Me.Width - invader(11).Width Or invader(1).Left < 0 Then
invaders = -invaders
For count = 1 To 11
invader(count).Top = invader(count).Top + 10
Next

End If


EndSub

Thank you
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,553
Location
Sydney, Australia
Programming Experience
10+
Don't use individual PictureBoxes. Use a single PictureBox for the whole canvas and use GDI+ to draw everything on it. Whenever a part of the canvas changes or may have changed you Invalidate it and then you Update the canvas to repaint the invalidated areas. In the Paint event handler, you draw the entire canvas. You can draw whatever you want. You might want to use a collection of collections to represent the invaders and to add a new row you simply add another inner collection to the outer collection. When drawing the invaders, you use a nested loop to go through the contents of each row.
 

shaz1

Member
Joined
Jul 22, 2013
Messages
9
Programming Experience
Beginner
Are you able to give me some advice / help on how I would do this? I haven't done much with GDI+ and so am not sure where to start. Thanks
 
Top Bottom