Followers 0

shooting bullets

7 posts in this topic

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;
}
}


0

Share on other sites

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.

0

Share on other sites

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?

0

Share on other sites

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.

0

Share on other sites

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

0

Share on other sites

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

0

Share on other sites

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

0

Share on other sites

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)

Edited by SimonForsman
0

Create an account

Register a new account