Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launching Projectile [Game Issue]
#2
Well, I can definitely see your problem here! Well, the generally accepted solution to this problem would be to create an array which holds all of the bullets of the player, and every time the timer ticks, each bullet is moved. I have put what I am talking about into code:

Code:
Private playerBullets As List(Of PictureBox)

    Public Sub Player_Shoot(Sender As Object, e As System.EventArgs)
        'This method creates the new bullet!
        Dim pro As New PictureBox
        pro.Image = proj
        pro.Visible = True
        pro.Width = 9
        pro.Height = 32

        pro.Top = Player.Top - 20
        pro.Left = Player.Left + 20

        Controls.Add(pro)
        playerBullets.Add(pro)
    End Sub

    Public Sub PlayerBullets_Act(sender As Object, e As System.EventArgs)
        'This method moves the player bullets and detects their collisions. It should be called every
        'time the timer ticks
        For Each bullet As PictureBox In playerBullets
            If (bullet.Location.Y <= 0) Then
                'The bullet has moved off of the screen, we need to remove it to conserve system resources
                Controls.Remove(bullet)
                playerBullets.Remove(bullet)
            End If

            'TODO: Check for collisions with enemies here

            bullet.Location = New System.Drawing.Point(bullet.Location.X, bullet.Location.Y - 2) 'Move the bullet up
        Next


    End Sub

Pastebin Version: <!-- m --><a class="postlink" href="http://pastebin.com/1t5iazRR">http://pastebin.com/1t5iazRR</a><!-- m -->

So, essentially what we are doing is keeping track of all the bullets that the player has actually shot, and removing them once they go off the screen. In order to apply this procedure, simply make the timer call PlayerBullets_Act every time the timer ticks.
My Blog | My Setup | My Videos | Have a wonderful day.


Messages In This Thread
Launching Projectile [Game Issue] - by Vinwarez - 07-13-2012, 01:08 PM
Re: Launching Projectile [Game Issue] - by brandonio21_phpbb3_import2 - 07-13-2012, 01:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Full screen game overlay? Ecnarf 1 8,216 01-29-2013, 09:14 AM
Last Post: xolara
  Dual Menu Strip Issue Moldraxian 3 16,100 08-15-2012, 12:36 PM
Last Post: brandonio21
  MySQL Database Issue Moldraxian 7 27,890 08-13-2012, 08:58 PM
Last Post: brandonio21
  Module Issue Vinwarez 18 56,428 07-24-2012, 11:47 PM
Last Post: Vinwarez
  Remove Enemy [Game Issue] Vinwarez 3 13,784 07-14-2012, 02:15 PM
Last Post: brandonio21

Forum Jump:


Users browsing this thread: 1 Guest(s)