# Thread: I can shoot only one bullet not 2 !

1. ## 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. ## 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. ## 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. ## 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...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•