Results 1 to 5 of 5

Thread: [RESOLVED] (VB 2010) Score and Object Removal

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    2

    Resolved [RESOLVED] (VB 2010) Score and Object Removal

    This code is based on the space invaders but it lacks a few things. I have a ship that fires bullets and 3 asteroids that move left and right on the screen.
    How can I increment the score by 1 every time the bullet reaches the top of the form and how can I make the bullet dissapear(remove the bullet) if it touches one of the asteroids or the end of the form.

    Code:
    Public Class Form1
        Dim moveright As Boolean
        Dim moveright2 As Boolean
        Dim moveright3 As Boolean
        Dim score As Integer
    
    
        Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
            Dim Bullets() As PictureBox = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5}
            Static intCount As Integer
            Select Case e.KeyCode
                Case Keys.Space
                    Bullets(intCount).Location = ship.Location
                    tmrShoot.Enabled = True
                    intCount += 1
                    If intCount = 5 Then
                        intCount = 0
                    End If
                Case Keys.Left
                    ship.Left -= 20
                Case Keys.Right
                    ship.Left += 20
            End Select
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub tmrShoot_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrShoot.Tick
            Dim Bullets() As PictureBox = {PictureBox1, PictureBox2, PictureBox3, PictureBox4, PictureBox5}
            For x = 0 To Bullets.Length - 1
                Bullets(x).Top -= 10
            Next
           
    
        End Sub
        Private Sub tmrAst_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAst.Tick
            If asteroid1.Left <= 0 Then
                moveright = True
            End If
            If asteroid1.Right >= Me.ClientRectangle.Right Then
                moveright = False
            End If
            If moveright = True Then
                asteroid1.Left += 9
            Else : asteroid1.Left -= 9
            End If
        End Sub
    
        Private Sub tmrAst2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAst2.Tick
            If asteroid2.Left <= 0 Then
                moveright2 = True
            End If
            If asteroid2.Right >= Me.ClientRectangle.Right Then
                moveright2 = False
            End If
            If moveright2 = True Then
                asteroid2.Left += 8
            Else : asteroid2.Left -= 8
            End If
        End Sub
    
        Private Sub tmrAst3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrAst3.Tick
            If asteroid3.Left <= 0 Then
                moveright3 = True
            End If
            If asteroid3.Right >= Me.ClientRectangle.Right Then
                moveright3 = False
            End If
            If moveright3 = True Then
                asteroid3.Left += 7
            Else : asteroid3.Left -= 7
            End If
        End Sub
    
    End Class

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,501

    Re: (VB 2010) Score and Object Removal

    Welcome to VBForums

    Thread moved from the 'Game Demos' forum (which is for you to post working examples, not questions) to the 'Games and Graphics' forum

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: (VB 2010) Score and Object Removal

    How can I increment the score by 1 every time the bullet reaches the top of the form
    Well your bullet is a PictureBox, so what you should do whenever you move the PictureBox is check if it's Bottom property is equal to 0. If so then it is completely out of the view of the screen.
    Code:
    If bullet.Bottom = 0 Then
    how can I make the bullet dissapear(remove the bullet) if it touches one of the asteroids or the end of the form
    I'm not sure what your asteroid is, but if it's a PictureBox then I can give you some advise. Whenever you move the Bullet, check if it's Bounds property collides with the Asteroid by using the IntersectsWith method:
    Code:
    If bullet.Bounds.IntersectsWith(asteroid.Bounds) Then

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Posts
    2

    Re: (VB 2010) Score and Object Removal

    Thank you dday9, that solved my problem

  5. #5
    Android OpenGL ES Guru Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,278

    Re: [RESOLVED] (VB 2010) Score and Object Removal

    Im also working on a space invaders game using DirectX and VB so ill share that once i got a good chunk done. I have my aliens all have shields while you fire rapid fire, and they drop power ups to make you get better weapons.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width