shooting bullets

Started by
6 comments, last by SimonForsman 10 years, 10 months ago

I am working on a asteroids game. I am able to move the spaceship up and down and left and right. I just want it to shoot bullets using the space bar.

here is the code for the shooting bullets function.

void bullet()
{
glPointSize(2.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,up,0.0f);
glEnd();
up+=0.1f;
if(up >= 10.0f)
{
up=0.5f;
}
}

Advertisement

why do you have rendering code in your bullet function ?

you want to spawn a bullet with an initial position just in front of the ship and a velocity vector pointing in the direction the ship is facing, then you'll just update and render the bullet like any other gameobject.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!





Posted Today, 03:39 PM


why do you have rendering code in your bullet function

should I have the rendering code in my main rendering function?





Posted Today, 03:39 PM


why do you have rendering code in your bullet function

should I have the rendering code in my main rendering function?

if the main rendering function renders the ships and asteroids then yes, it should render your bullets as well.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!


if the main rendering function renders the ships and asteroids then yes, it should render your bullets as well.

hey I did the above and it worked, thanks

is there anyway to rotate an object without using the glRotatef function?

well I figured out how to rotate an object properly. I am actually getting this programming stuff using opengl and c++.

is there anyway to rotate an object without using the glRotatef function?

Yes, you can create a transformation matrix manually. (Rotatef is really just a shorthand function for creating and applying a rotation matrix to the current matrix (the one at the top of the stack). you can push and pop matrices to/from the stack using glpushmatrix/popmatrix and resetting the top matrix using glLoadIdentity(), or load your own matrix to the top of the stack using glLoadMatrix.

The only thing you should never do(unless you got a very low number of vertices in which case software transformation might be faster than creating the matrix, but then it most likely doesn't matter what you do anyway) is modify the vertex positions directly, each vertex is transformed using the transformation and projection matrices by the hardware (and it has to do that anyway)

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

This topic is closed to new replies.

Advertisement