Results 1 to 4 of 4

Thread: I can shoot only one bullet not 2 !

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Arlon, Belgium
    Posts
    477

    I can shoot only one bullet not 2 !

    Hi,

    I want to shoot more than 1 bullet but I can not do that. How can I do that with my code ?

    Code :
    // **********************************************
    void UpDate_Shoot(float X, float Y, float Z, float Shoot_Angle_Not_Locked, float Current_Time)
    {
     
    	// For all of the Players
    	for (int i = 0; i < MAX_PLAYERS; i ++)
    		{
     
    			// Have we shot ?
    			if (Shoot)
    				{
    					// We've fired, so we create 1 bullet
    					if (!Shoot_Bullet)
    						Number_of_Bullets_Shot += 1;
     
    					Shoot_Bullet = true;
     
    					for (int ii = 0; ii < Number_of_Bullets_Shot; ii ++)
    						{
    							// If the shoot angle is not yet locked, we set it
    							if (!Shoot_Angle_Locked) 
    								{
    									// We set the Shoot Angle
    									Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Shoot_Angle_Not_Locked = Shoot_Angle_Not_Locked;
     
    									// The Shoot Angle has been locked, so we set it
    									Shoot_Angle_Locked = true;
     
    									// Current Time for moving the Bullet
    									Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Time = Current_Time;
     
    									// Inital Bullet Position on X
    									Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_X = - X;
     
    									// Inital Bullet Position on Y
    									Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Y =  Y;
     
    									// Inital Bullet Position on Z
    									Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Z = - Z;
    								}
     
    							// We save the current matrix
    							glPushMatrix();
    								// Object Mouvement	+ Speed
    								Deplacement_Object = (Deplacement_A / Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Time) * 12;
     
    								// Current Bullet Position on X
    								Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_X = Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_X - (Deplacement_Object * sin(Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Shoot_Angle_Not_Locked * Piover180));		
     
    								// Current Bullet Position on Y
    								Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Y =  1.5f;
     
    								// Current Bullet Position on Z
    								Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Z = Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Z - (Deplacement_Object * cos(Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Shoot_Angle_Not_Locked * Piover180));
     
    								// We move the Bullet
    								glTranslatef(Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_X, 
    											 Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Y, 
    											 Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Z);
     
    								// We draw a Bullet (just for the example)
    								glutSolidSphere(0.1f, 10, 10);
     
    								// Collision Detection for the Bullet
    								Collision_Detection_Object(Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_X,
    														   Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Y,
    														   Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Z,
    														   0.1f);
     
    								// The Bullet has hit something, so we stop it
    								if (Number_Polygon_Collision_Object > -1)
    									{
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Hit = true;
     
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Impact_Bullet_Position_X = Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_X;
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Impact_Bullet_Position_Y = Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Y;
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Impact_Bullet_Position_Z = Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Current_Bullet_Position_Z;
     
    										// After the Collision, the "Shoot" variable is set to 'false'
    //										Shoot = false;
     
    										// We set the Shoot Angle
    //										Shoot_Angle = Shoot_Angle_Not_Locked;
     
    										// The Shoot Angle has been locked, so we set it
    //										Shoot_Angle_Locked = true;
    /*										
    										// Current Time for moving the Bullet
    										Time = Current_Time;
     
    										// Inital Bullet Position on X
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_X = - X;
     
    										// Inital Bullet Position on Y
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Y =  1.5f;
     
    										// Inital Bullet Position on Z
    										Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Z = - Z;
    */
    									}
     
     
    							// We load the saved matrix
    							glPopMatrix();
    						}
    				}
    			else
    				{
     
    					// We set the Shoot Angle
    //					Shoot_Angle = Shoot_Angle_Not_Locked;
     
    					// Bullet Position on X
    //					Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_X = - X;
     
    					// Bullet Position on Y
    //					Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Y =  Y;
     
    					// Bullet Position on Z
    //					Player_in_Game[i].Weapon_In_Game[0].Bullet[ii].Init_Bullet_Position_Z = - Z;		
    				}
    		}
     
    }

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    England
    Posts
    10

    Re: I can shoot only one bullet not 2 !

    Although not totally OpenGL orientated...where are you resetting your count?

    // We've fired, so we create 1 bullet if (!Shoot_Bullet) Number_of_Bullets_Shot += 1; Shoot_Bullet = true; for (int ii = 0; ii < Number_of_Bullets_Shot; ii ++)

    the number of bullets shot can ONLY ever be 1. As you check for a non true (false) value of Shoot_Bullet then set it to true but never undo this setting...therefore you never increment Number_of_Bullets_Shot giving you only one bullet.

    Allen

  3. #3
    Member Contributor
    Join Date
    Mar 2003
    Location
    Suffolk, United Kingdom
    Posts
    99

    Re: I can shoot only one bullet not 2 !

    Originally posted by Leyder Dylan:
    Code :
    if (!Shoot_Bullet)
    	Number_of_Bullets_Shot += 1;
    	Shoot_Bullet = true;
    	// ... and so on ...
    You do set this Shoot_Bullet variable back to false again somewhere else do you?

  4. #4
    Member Contributor
    Join Date
    Jan 2003
    Location
    coventry
    Posts
    72

    Re: I can shoot only one bullet not 2 !

    don't just dump your code (and a very tiresome one for the matter) on a forum and expect people to debug it for you. Especially when it's off topic and trivial. Debugging is a skill, learn it.

    grrrr...
    ----------------------------
    Non!

Similar Threads

  1. Basic Shoot Game but I could not manage to encoding
    By bequietmimix in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-20-2018, 02:21 AM
  2. 3D Bullet Trajectory
    By spoonbadger in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-12-2012, 12:55 AM
  3. Code Warrior and Win ME (Oh please, shoot me!)
    By kellody in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-28-2001, 04:59 PM
  4. Seleciting - Picking vertices - shoot-through
    By Uther_Pendragon in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 08-09-2001, 03:39 AM
  5. shooting a bullet
    By spot in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 02-15-2001, 10:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean