Hi there,
I would like to know how would I loop this piece of code once it has hit the bottom of the form?
Private Sub moveasteroid()
'Asteroid 1
If asteroiddown = True Then
PictureBox1.Top += asteroidspeed
Else
PictureBox1.Left -= asteroidspeed
End If
If PictureBox1.Left + PictureBox1.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox1.Top += asteroiddrop
End If
Private Sub checkgameover()
If PictureBox1.Top + PictureBox1.Width >= Me.ClientRectangle.Bottom And PictureBox1.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
So once this ^ has happened, a box loads explaining the above, once the x is clicked how can I load this all over again? Could someone please explain using an example, this may help other beginners.
Thank you.
Loading
RichPosted Jan 14, 2014, 10:01 AM
FroglegPosted Jan 13, 2014, 2:41 PM
RichPosted Jan 13, 2014, 6:31 AM
If run = True Then If PictureBox1.Top + PictureBox1.Width >= Me.ClientRectangle.Bottom And PictureBox1.Visible = True Then Timermain.Enabled = False MsgBox("Game Over- Region of space not protected!") End If
Me.Refresh()
moveasteroid() End If
RichPosted Dec 28, 2013, 9:13 AM
RichPosted Dec 22, 2013, 11:48 AM
Dim rocketleft As Boolean
Dim rocketright As Boolean
Dim asteroidspeed As Integer
Dim asteroiddrop As Integer
Dim asteroiddown As Boolean
Dim rocketspeed As Integer = 24
Dim missilespeed As Integer = 24
Private Sub Timermain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timermain.Tick
moveasteroid()
checkgameover()
moverocketship()
firemissile()
checkhit()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
loadsettings()
End Sub
Private Sub loadsettings()
asteroiddown = True
asteroidspeed = 3
asteroiddrop = 40
checkgameover()
rocketspeed = 18
missilespeed = 24
missile.Visible = False
firemissile()
checkhit()
End Sub
Private Sub moveasteroid()
'Asteroid 1
If asteroiddown = True Then
PictureBox1.Top += asteroidspeed
Else
PictureBox1.Left -= asteroidspeed
End If
If PictureBox1.Left + PictureBox1.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox1.Top += asteroiddrop
End If
'Asteroid 2
If asteroiddown = True Then
PictureBox2.Top += asteroidspeed
Else
PictureBox2.Left -= asteroidspeed
End If
If PictureBox2.Left + PictureBox2.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox2.Top += asteroiddrop
End If
'Asteroid 3
If asteroiddown = True Then
PictureBox3.Top += asteroidspeed
Else
PictureBox3.Left -= asteroidspeed
End If
If PictureBox3.Left + PictureBox3.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox3.Top += asteroiddrop
End If
'Asteroid 4
If asteroiddown = True Then
PictureBox4.Top += asteroidspeed
Else
PictureBox4.Left -= asteroidspeed
End If
If PictureBox4.Left + PictureBox4.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox4.Top += asteroiddrop
End If
'Asteroid 5
If asteroiddown = True Then
PictureBox5.Top += asteroidspeed
Else
PictureBox5.Left -= asteroidspeed
End If
If PictureBox5.Left + PictureBox5.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox5.Top += asteroiddrop
End If
'Asteroid 6
If asteroiddown = True Then
PictureBox6.Top += asteroidspeed
Else
PictureBox6.Left -= asteroidspeed
End If
If PictureBox6.Left + PictureBox6.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox6.Top += asteroiddrop
End If
'Asteroid 7
If asteroiddown = True Then
PictureBox7.Top += asteroidspeed
Else
PictureBox7.Left -= asteroidspeed
End If
If PictureBox7.Left + PictureBox7.Width > Me.ClientRectangle.Bottom Then
asteroiddown = False
PictureBox7.Top += asteroiddrop
End If
'Asteroid 8
If asteroiddown = True Then
PictureBox8.Top += asteroidspeed
Else
PictureBox8.Left -= asteroidspeed
End If
End Sub
Private Sub firemissile()
If missile.Visible = True Then
missile.Top -= missilespeed
End If
If missile.Top + missile.Height < Me.ClientRectangle.Top Then
missile.Visible = False
End If
End Sub
Private Sub checkhit()
If (missile.Top + missile.Height >= PictureBox1.Top) And (missile.Top <= PictureBox1.Top + PictureBox1.Height) And (missile.Left + missile.Width >= PictureBox1.Left) And (missile.Left <= PictureBox1.Left + PictureBox1.Width) And missile.Visible = True Then
PictureBox1.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox2.Top) And (missile.Top <= PictureBox2.Top + PictureBox2.Height) And (missile.Left + missile.Width >= PictureBox2.Left) And (missile.Left <= PictureBox2.Left + PictureBox2.Width) And missile.Visible = True Then
PictureBox2.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox3.Top) And (missile.Top <= PictureBox3.Top + PictureBox3.Height) And (missile.Left + missile.Width >= PictureBox3.Left) And (missile.Left <= PictureBox3.Left + PictureBox3.Width) And missile.Visible = True Then
PictureBox3.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox4.Top) And (missile.Top <= PictureBox4.Top + PictureBox4.Height) And (missile.Left + missile.Width >= PictureBox4.Left) And (missile.Left <= PictureBox4.Left + PictureBox4.Width) And missile.Visible = True Then
PictureBox4.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox5.Top) And (missile.Top <= PictureBox5.Top + PictureBox5.Height) And (missile.Left + missile.Width >= PictureBox5.Left) And (missile.Left <= PictureBox5.Left + PictureBox5.Width) And missile.Visible = True Then
PictureBox5.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox6.Top) And (missile.Top <= PictureBox6.Top + PictureBox6.Height) And (missile.Left + missile.Width >= PictureBox6.Left) And (missile.Left <= PictureBox6.Left + PictureBox6.Width) And missile.Visible = True Then
PictureBox6.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox7.Top) And (missile.Top <= PictureBox7.Top + PictureBox7.Height) And (missile.Left + missile.Width >= PictureBox7.Left) And (missile.Left <= PictureBox7.Left + PictureBox7.Width) And missile.Visible = True Then
PictureBox7.Visible = False
missile.Visible = False
End If
If (missile.Top + missile.Height >= PictureBox8.Top) And (missile.Top <= PictureBox8.Top + PictureBox8.Height) And (missile.Left + missile.Width >= PictureBox8.Left) And (missile.Left <= PictureBox8.Left + PictureBox8.Width) And missile.Visible = True Then
PictureBox8.Visible = False
missile.Visible = False
MsgBox("Region of space protected!")
End If
End Sub
Private Sub checkgameover()
If PictureBox1.Top + PictureBox1.Width >= Me.ClientRectangle.Bottom And PictureBox1.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox2.Top + PictureBox2.Width >= Me.ClientRectangle.Bottom And PictureBox2.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox3.Top + PictureBox3.Width >= Me.ClientRectangle.Bottom And PictureBox3.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox4.Top + PictureBox4.Width >= Me.ClientRectangle.Bottom And PictureBox4.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox5.Top + PictureBox5.Width >= Me.ClientRectangle.Bottom And PictureBox5.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox6.Top + PictureBox6.Width >= Me.ClientRectangle.Bottom And PictureBox6.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox7.Top + PictureBox7.Width >= Me.ClientRectangle.Bottom And PictureBox7.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox8.Top + PictureBox8.Width >= Me.ClientRectangle.Bottom And PictureBox8.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space not protected!")
End If
If PictureBox8.Top + PictureBox8.Width >= Me.ClientRectangle.Bottom And PictureBox8.Visible = True Then
Timermain.Enabled = False
MsgBox("Game Over- Region of space protected!")
End If
End Sub
Private Sub moverocketship()
If rocketleft = True And rocketship.Left + rocketship.Width > Me.ClientRectangle.Left Then
rocketship.Left -= rocketspeed
End If
If rocketright = True And rocketship.Left + rocketship.Width < Me.ClientRectangle.Width Then
rocketship.Left += rocketspeed
End If
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If (e.KeyCode = System.Windows.Forms.Keys.Left) Then
rocketleft = True
rocketright = False
End If
If (e.KeyCode = System.Windows.Forms.Keys.Right) Then
rocketright = True
rocketleft = False
End If
If (e.KeyCode = System.Windows.Forms.Keys.Up) And missile.Visible = False Then
missile.Top = rocketship.Top
missile.Left = rocketship.Left + (rocketship.Width / 2) - (missile.Width / 2)
missile.Visible = True
End If
If (e.KeyCode = System.Windows.Forms.Keys.Down) Then
Application.Exit()
End If
End Sub
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
If (e.KeyCode = System.Windows.Forms.Keys.Left) Then
rocketleft = False
End If
If (e.KeyCode = System.Windows.Forms.Keys.Right) Then
rocketright = False
End If
End Sub
End Class
RichPosted Dec 20, 2013, 4:38 PM
FroglegPosted Dec 20, 2013, 1:26 PM
RichPosted Dec 20, 2013, 8:15 AM
FroglegPosted Dec 19, 2013, 4:20 PM