I'm making a little mech game. But I can't figure out how to fire multiple missiles. It just fires one. And if the space bar is hit repeatedly, the missile image will go back to the mech image. Any help?
Just create a new bullet each time the button is hit instead of modifying the same bullet over and over. Keep a cap on how many bullets you can have created at once, or in your a case a weapons cache which is cleared and refilled.
I assume you are making this in VB using Picturebox's? I only assume this due to the nature of your question.
"From what was there, and was meant to be, but not of that was faded away." - - Steve Damm
"The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm
"When you do things right, people won't be sure if you did anything at all." - - God from Futurama
It's very simple if you look at this code snippet carefully. I done a Select Case method to check what weapon number I'm using. In this case, I only have one weapon. Then it cycles through a maximum of 50 shots that can appear on screen at once. If that shot is visible, then add velocity to it. If it's greater than the range from the ship, then make that visible shot invisible. Then it draws the shot. Make sense so far? Good. Now comes something that may be a little more complicated, but hopefully you will be able to understand it.
Ok right here is a small code snippet from my Controls sub routine. And in this is the part where if I press the space bar, it'll fire a shot. Holding it down will produce autofire like a machine gun.
Ok before I explain the code, I have two things that I need to clear up. In my Weapon_Type user defined type, there are two variables (actually more than two but two that need explaining). One is the the Separation_Amount, which is how far apart you want each shot before the next shot is fired. Setting it at 1 can produce what looks like a laser!!! The other is the Separation_Rate, which is the rate that each shot is fired. Working out the values for these can produce some killer shots. Oh shoot I gotta go, I'll be back to explain the rest. Peace.
Erg, this is kind of confusing, I guess I'll try and learn it later when I'm not so tired. I had 3 tests today, so my brain is fried!
I'll try to learn again tomorrow. Thanks for the help though.
Alright, I made an example program to see if it would work. It does. This is what I came up with.
VB Code:
Dim x As Integer
'Dim ikey As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeySpace Then
x = imgMissle.UBound + 1
Load imgMissle(x)
imgMissle(x).Visible = True
End If
' UBound is the last index in an array
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
ikey = 0
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim y As Integer
For y = 1 To x
imgMissle(y).Left = imgMissle(y).Left + 50
Next
End Sub
And this is what it looks like.
When I hold the space bar down, the images build up, and then it looks like a laser, as you explained it Jacob. But, unlike yours, it starts to lag. Now I have to understand the part you were also explaining. How to do the "Seperation_Amount."
Since you are using VB events for the keypress, you will be getting a slight delay holding down the spacebar before it starts firing. But i have a way around that. Unfortunately you are gonna have to wait till I get home from work.