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?
Printable View
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?
That R-Type_3D game I have has something to where you can fire repeatedly. You can download it here
www.angelfire.com/fl5/memorydll/index.html
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.
Jacob, I admire your game, but don't understand at all. I am using images. I have just one missile. How can I create a new missile everytime?
Look in my sub routines Control_Shots and Controls over where you press the space bar.
Better yet, wait till I get home and I'll show ya. :bigyello:
Alrighty then.
Ok right here is my control shots sub, which controls how the shots are shot.
VB Code:
Public Sub Control_Shots() Randomize Dim Current_Shot As Long Select Case Ship.Weapon_Number Case 1 For Current_Shot = 1 To MAX_NUMBER_OF_SHOTS If Ship.Weapon(Ship.Weapon_Number).Visible(Current_Shot) = True Then Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) = Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) + Ship.Weapon(Ship.Weapon_Number).Velocity_X Ship.Weapon(Ship.Weapon_Number).Y(Current_Shot) = Ship.Weapon(Ship.Weapon_Number).Y(Current_Shot) + Ship.Weapon(Ship.Weapon_Number).Velocity_Y Ship.Weapon(Ship.Weapon_Number).Z(Current_Shot) = Ship.Z If Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) >= Ship.X + 1000 Then Ship.Weapon(Ship.Weapon_Number).Visible(Current_Shot) = False End If Draw_Shots End If Next Current_Shot End Select End Sub
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.
VB Code:
'Weapons If DirectInput_Key_State(DX_KEY_SPACE) > 0 Then Select Case Ship.Weapon_Number Case 1 Ship.Weapon(1).Current_Seperation = Ship.Weapon(1).Current_Seperation + Ship.Weapon(1).Seperation_Rate If Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Shot_Start_Number Then DirectSound_Play DirectSound_Buffer(0) 'This If statement is for the FIRST SHOT fired for when you press 'the space bar quickly so the lag of time from the Seperation_Shot_Amount 'will not affect the FIRST SHOT thus causing it to fire anyways. Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Current_Shot + 1 Ship.Weapon(1).Current_Shot = Within_Range(Ship.Weapon(1).Current_Shot, 1, MAX_NUMBER_OF_SHOTS) Ship.Weapon(1).Visible(Ship.Weapon(1).Current_Shot) = True Ship.Weapon(1).X(Ship.Weapon(1).Current_Shot) = Ship.X + Ship.Animation_State(Ship.State).Center_X(Fix(Ship.Animation_State(Ship.State).Frame_Counter)) Ship.Weapon(1).Y(Ship.Weapon(1).Current_Shot) = Ship.Y - 7 Ship.Weapon(1).Z(Ship.Weapon(1).Current_Shot) = Ship.Z Ship.Weapon(1).Current_Seperation = 0 ElseIf Ship.Weapon(1).Current_Shot <> Ship.Weapon(1).Shot_Start_Number Then If Ship.Weapon(1).Current_Seperation >= Ship.Weapon(1).Seperation_Amount Then DirectSound_Play DirectSound_Buffer(0) 'This If statement is for every other shot fired when you do have the 'spacebar held so the lag of time for every shot is affected by the 'Seperation_Shot_Amount. Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Current_Shot + 1 Ship.Weapon(1).Current_Shot = Within_Range(Ship.Weapon(1).Current_Shot, 1, MAX_NUMBER_OF_SHOTS) Ship.Weapon(1).Visible(Ship.Weapon(1).Current_Shot) = True Ship.Weapon(1).X(Ship.Weapon(1).Current_Shot) = Ship.X + Ship.Animation_State(Ship.State).Center_X(Fix(Ship.Animation_State(Ship.State).Frame_Counter)) Ship.Weapon(1).Y(Ship.Weapon(1).Current_Shot) = Ship.Y - 7 Ship.Weapon(1).Z(Ship.Weapon(1).Current_Shot) = Ship.Z Ship.Weapon(1).Current_Seperation = 0 End If End If End Select Else Ship.Weapon(1).Shot_Start_Number = Ship.Weapon(1).Current_Shot End If
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. :bigyello:
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! :confused:
I'll try to learn again tomorrow. Thanks for the help though.
When you create the image on your form during development time, make it had an index of 0 so it is considered an array of controls.
Now each time you need to, use the Load func I think it was, to load a new control in the array you created.
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
http://img249.echo.cx/img249/6986/im...rums4pq.th.png
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.
Looking forward to it.
Here ya go. I must have written this control engine like 5 years ago! Good times. :bigyello: