Results 1 to 13 of 13

Thread: Quick Question about Shooters

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Quick Question about Shooters

    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?

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Quick Question about Shooters

    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

  3. #3
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Quick Question about Shooters

    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

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Re: Quick Question about Shooters

    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?

  5. #5
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Quick Question about Shooters

    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Re: Quick Question about Shooters

    Alrighty then.

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Quick Question about Shooters

    Ok right here is my control shots sub, which controls how the shots are shot.

    VB Code:
    1. Public Sub Control_Shots()
    2.    
    3.     Randomize
    4.    
    5.     Dim Current_Shot As Long
    6.    
    7.     Select Case Ship.Weapon_Number
    8.                
    9.         Case 1
    10.    
    11.             For Current_Shot = 1 To MAX_NUMBER_OF_SHOTS
    12.        
    13.                 If Ship.Weapon(Ship.Weapon_Number).Visible(Current_Shot) = True Then
    14.                    
    15.                     Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) = Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) + Ship.Weapon(Ship.Weapon_Number).Velocity_X
    16.                     Ship.Weapon(Ship.Weapon_Number).Y(Current_Shot) = Ship.Weapon(Ship.Weapon_Number).Y(Current_Shot) + Ship.Weapon(Ship.Weapon_Number).Velocity_Y
    17.                     Ship.Weapon(Ship.Weapon_Number).Z(Current_Shot) = Ship.Z
    18.        
    19.                     If Ship.Weapon(Ship.Weapon_Number).X(Current_Shot) >= Ship.X + 1000 Then
    20.                        
    21.                         Ship.Weapon(Ship.Weapon_Number).Visible(Current_Shot) = False
    22.                        
    23.                     End If
    24.                    
    25.                     Draw_Shots
    26.            
    27.                 End If
    28.    
    29.             Next Current_Shot
    30.    
    31.     End Select
    32.  
    33. 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:
    1. 'Weapons
    2.    
    3.         If DirectInput_Key_State(DX_KEY_SPACE) > 0 Then
    4.        
    5.             Select Case Ship.Weapon_Number
    6.        
    7.                 Case 1
    8.        
    9.                     Ship.Weapon(1).Current_Seperation = Ship.Weapon(1).Current_Seperation + Ship.Weapon(1).Seperation_Rate
    10.                
    11.                     If Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Shot_Start_Number Then
    12.                    
    13.                         DirectSound_Play DirectSound_Buffer(0)
    14.                    
    15.                         'This If statement is for the FIRST SHOT fired for when you press
    16.                         'the space bar quickly so the lag of time from the Seperation_Shot_Amount
    17.                         'will not affect the FIRST SHOT thus causing it to fire anyways.
    18.                    
    19.                         Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Current_Shot + 1
    20.        
    21.                         Ship.Weapon(1).Current_Shot = Within_Range(Ship.Weapon(1).Current_Shot, 1, MAX_NUMBER_OF_SHOTS)
    22.        
    23.                         Ship.Weapon(1).Visible(Ship.Weapon(1).Current_Shot) = True
    24.                         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))
    25.                         Ship.Weapon(1).Y(Ship.Weapon(1).Current_Shot) = Ship.Y - 7
    26.                         Ship.Weapon(1).Z(Ship.Weapon(1).Current_Shot) = Ship.Z
    27.                        
    28.                         Ship.Weapon(1).Current_Seperation = 0
    29.                        
    30.                     ElseIf Ship.Weapon(1).Current_Shot <> Ship.Weapon(1).Shot_Start_Number Then
    31.                
    32.                     If Ship.Weapon(1).Current_Seperation >= Ship.Weapon(1).Seperation_Amount Then
    33.                    
    34.                         DirectSound_Play DirectSound_Buffer(0)
    35.                        
    36.                         'This If statement is for every other shot fired when you do have the
    37.                         'spacebar held so the lag of time for every shot is affected by the
    38.                         'Seperation_Shot_Amount.
    39.                        
    40.                         Ship.Weapon(1).Current_Shot = Ship.Weapon(1).Current_Shot + 1
    41.        
    42.                         Ship.Weapon(1).Current_Shot = Within_Range(Ship.Weapon(1).Current_Shot, 1, MAX_NUMBER_OF_SHOTS)
    43.                        
    44.                         Ship.Weapon(1).Visible(Ship.Weapon(1).Current_Shot) = True
    45.                         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))
    46.                         Ship.Weapon(1).Y(Ship.Weapon(1).Current_Shot) = Ship.Y - 7
    47.                         Ship.Weapon(1).Z(Ship.Weapon(1).Current_Shot) = Ship.Z
    48.        
    49.                         Ship.Weapon(1).Current_Seperation = 0
    50.                    
    51.                     End If
    52.                
    53.                 End If
    54.                
    55.             End Select
    56.        
    57.         Else
    58.    
    59.             Ship.Weapon(1).Shot_Start_Number = Ship.Weapon(1).Current_Shot
    60.        
    61.         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.

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Re: Quick Question about Shooters

    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.

  9. #9
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Quick Question about Shooters

    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.
    "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

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Re: Quick Question about Shooters

    Alright, I made an example program to see if it would work. It does. This is what I came up with.

    VB Code:
    1. Dim x As Integer
    2. 'Dim ikey As Integer
    3.  
    4. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    5. If KeyCode = vbKeySpace Then
    6.     x = imgMissle.UBound + 1
    7.         Load imgMissle(x)
    8.             imgMissle(x).Visible = True
    9.    
    10. End If
    11. ' UBound is the last index in an array
    12. End Sub
    13.  
    14. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    15. ikey = 0
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.  
    20. Timer1.Enabled = True
    21.  
    22. End Sub
    23. Private Sub Timer1_Timer()
    24.  
    25. Dim y As Integer
    26.  
    27. For y = 1 To x
    28. imgMissle(y).Left = imgMissle(y).Left + 50
    29. Next
    30.  
    31.  
    32.  
    33. 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."
    Last edited by S4M_0; Apr 20th, 2005 at 02:28 PM.

  11. #11
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Quick Question about Shooters

    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.

  12. #12

    Thread Starter
    Member
    Join Date
    Jan 2005
    Posts
    62

    Re: Quick Question about Shooters

    Looking forward to it.

  13. #13
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Quick Question about Shooters

    Here ya go. I must have written this control engine like 5 years ago! Good times.
    Attached Files Attached Files

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