#### Archived

This topic is now archived and is closed to further replies.

# Ahh! Weapons again!

This topic is 5734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In a Asteroids kinda game, I''m trying to make the weapon fire from the ship in the direction it is pointing. Unfortunately for me, pushing the button doesn''t exactly result in a weapon firing, was wondering if anyone could help debug.
  	glPushMatrix();
weapon1[uint_loop].fp_xspeed = 0.1;
weapon1[uint_loop].fp_deltavelocityy = sin(DEGTORAD * weapon1[uint_loop].fp_heading) * weapon1[uint_loop].fp_xspeed;   // Apply the change to the current velocity...

weapon1[uint_loop].fp_velocityx += weapon1[uint_loop].fp_deltavelocityx;
weapon1[uint_loop].fp_velocityy += weapon1[uint_loop].fp_deltavelocityy;

weapon1[uint_loop].fp_x += weapon1[uint_loop].fp_velocityx;
weapon1[uint_loop].fp_y += weapon1[uint_loop].fp_velocityy;

glTranslatef(weapon1[uint_loop].fp_x,weapon1[uint_loop].fp_y,fp_z1);

//		}

// Front Face

glNormal3f( 0.0f, 0.0f, 0.4f);
glVertex3f(-0.4f, -0.4f,  0.4f);
glVertex3f( 0.4f, -0.4f,  0.4f);
glVertex3f( 0.4f,  0.4f,  0.4f);
glVertex3f(-0.4f,  0.4f,  0.4f);
// Back Face

glNormal3f( 0.0f, 0.0f,-0.4f);
glVertex3f(-0.4f, -0.4f, -0.4f);
glVertex3f(-0.4f,  0.4f, -0.4f);
glVertex3f( 0.4f,  0.4f, -0.4f);
glVertex3f( 0.4f, -0.4f, -0.4f);
// Top Face

glNormal3f( 0.0f, 0.4f, 0.0f);
glVertex3f(-0.4f,  0.4f, -0.4f);
glVertex3f(-0.4f,  0.4f,  0.4f);
glVertex3f( 0.4f,  0.4f,  0.4f);
glVertex3f( 0.4f,  0.4f, -0.4f);
// Bottom Face

glNormal3f( 0.0f,-0.4f, 0.0f);
glVertex3f(-0.4f, -0.4f, -0.4f);
glVertex3f( 0.4f, -0.4f, -0.4f);
glVertex3f( 0.4f, -0.4f,  0.4f);
glVertex3f(-0.4f, -0.4f,  0.4f);
// Right face

glNormal3f( 0.4f, 0.0f, 0.0f);
glVertex3f( 0.4f, -0.4f, -0.4f);
glVertex3f( 0.4f,  0.4f, -0.4f);
glVertex3f( 0.4f,  0.4f,  0.4f);
glVertex3f( 0.4f, -0.4f,  0.4f);
// Left Face

glNormal3f(-0.4f, 0.0f, 0.0f);
glVertex3f(-0.4f, -0.4f, -0.4f);
glVertex3f(-0.4f, -0.4f,  0.4f);
glVertex3f(-0.4f,  0.4f,  0.4f);
glVertex3f(-0.4f,  0.4f, -0.4f);
glEnd();

if(boo_keys[VK_RETURN]){
if (weapon1[uint_loop].fp_life<0.0f)					// If weapon1 Is Burned Out

{
weapon1[uint_loop].fp_life=2.0f;					// Give It New Life

weapon1[uint_loop].fp_x=fp_x1;						// Center On X Axis

weapon1[uint_loop].fp_y=fp_y1;						// Center On Y Axis

}
glPopMatrix();

}  

##### Share on other sites
Check to make sure you''ve placed the firing function OUTSIDE of that big-assed loop. And hopefully you declared all the lives of all of the particles to < 0.0f (because you wont be firing anything if all their lives are defaulted to 0.0f).

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 10
• 9
• 9
• 11
• 11
• ### Forum Statistics

• Total Topics
633691
• Total Posts
3013344
×