Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
See more:
This is my code for the firing


Dim positionint = 1


  ' for when a key on the keyboard
  Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown


      ' Sets Handled to true to prevent other controls from
      ' receiving the key if an arrow key was pressed
      Dim bHandled As Boolean = False
      Select Case e.KeyCode
          Case Keys.Right
              positionint -= 1
              e.Handled = True
          Case Keys.Left
              positionint += 1
              e.Handled = True
          Case Keys.Space
              bullet.Size = New Point(10, 10)
              bullet.Visible = True
              bullet.BackColor = Color.Blue
              CentreOn(Car, bullet)

              Me.Controls.Add(bullet)
              bullet.Visible = True
              Bullettmr.Start()
          Case Keys.Z
              mutiplebullets()
      End Select

      If positionint = 0 Then
          Car.Location = New Point(p1.Location.X, Car.Location.Y)
          positionint += 1
      End If
      If positionint = 1 Then
          Car.Location = New Point(p1.Location.X, Car.Location.Y)
      End If
      If positionint = 2 Then
          Car.Location = New Point(p2.Location.X, Car.Location.Y)
      End If
      If positionint = 3 Then
          Car.Location = New Point(p3.Location.X, Car.Location.Y)
      End If
      If positionint = 4 Then
          Car.Location = New Point(p4.Location.X, Car.Location.Y)
      End If
      If positionint = 5 Then
          Car.Location = New Point(p5.Location.X, Car.Location.Y)
      End If
      If positionint = 6 Then
          Car.Location = New Point(p6.Location.X, Car.Location.Y)
      End If
      If positionint = 7 Then
          Car.Location = New Point(p7.Location.X, Car.Location.Y)
      End If
      If positionint = 8 Then
          Car.Location = New Point(p8.Location.X, Car.Location.Y)
          positionint -= 1
      End If
  End Sub



We Are Constrating on the Z on the key down

now the timer code
VB
Private Sub rockettmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rockettmr.Tick
       rocketnumber += 1
       rocket.Location = New Point(rocketnumber, rocket.Location - 20)
   End Sub


now the sub code

VB
Dim rocketnumber As Integer = 0
Public Sub mutiplebullets()
    Dim rocket As New PictureBox
    rocket.Name = "therocket" + rocketnumber.ToString
    rocket.Size = New Point(10, 10)
    rocket.Visible = True
    rocket.BackColor = Color.Green
    CentreOn(Car, rocket)

    Me.Controls.Add(rocket)

    rockettmr.Start()
End Sub


Whats meant to happen is that I press Z and a bullet should fire, but I can't seem to do that, the bullet doesn't move. and i also neeed to access the sub so when the bullet hits another picturebox somthing will happen
Posted
Comments
Sergey Alexandrovich Kryukov 8-Jul-12 14:09pm    
And..?
--SA
[no name] 8-Jul-12 20:44pm    
its not working I can only get 1 bullet to got at a time, I want to be able to shoot multiple bullets at a time and not have the bullet teleporting back the the car
Sergey Alexandrovich Kryukov 11-Jul-12 15:48pm    
It does not explain why you have a problem, where...
--SA
kornakar 9-Jul-12 2:38am    
I think you need a list which hold all the instances of the bullets. Then you can make a loop that moves each bullet and checks coillisions. Also it seems that rockettmr only moves *one* rocket, so maybe the loop should be there (for each rocket in me.controls or something).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900