PDA

View Full Version : 2d OpenGL top-down shooter game



-Tony-
09-14-2002, 10:04 AM
Hi, I'm trying to make top-down shooter game with C/SDL/OpenGL
http://w1.853.telia.com/~u85324201/game.zip

The problem is that when you shoot, the bullets don't come from the plane but from somewhere from the middle of the screen or near the plane.
The planes Xpos,Ypos are the same as the bullets when you fire it so I don't understand why this happens.

Here's the source: http://w1.853.telia.com/~u85324201/main.htm http://w1.853.telia.com/~u85324201/texture.h.htm

I've posted this in many other forums but nobody knew the solution...

Could somebody help?

nexusone
09-15-2002, 04:54 AM
Frist off the textures look nice... once you get it going will be a nice looking game.


I think you that one problem is with using glLoadIdentity() for drawing each object.

But after looking closer at your program it also could be that your using perspective view. Perspective view is for drawing 3D real world view of object. as they move away on the Z axis they get smaller.

Your plane is at -32, your bullet is at -100.
Think about your at one end of a football field and looking down at two players. One player is at your end, the other is at the other end. Even though they maybe on the same spot at each end of the field, one will look like he is closer in to the center.

Two solutions to your problem, one is to move the bullet to the same z as the plane.
Other would be to switch from perspective view to ortho view.

In ortho view, objects look the same no matter where they are on the Z-axis.

Also try this:

display()
{

glClear(GL_COLOR_BUFFER_BIT);

glLoadIdentity(); Keep

glPushMatrix(); Replace all other glLoadIdentity with this

glBindTexture(GL_TEXTURE_2D, textures[0].texID);
glTranslatef(0.0f,0.0f,-1.0f);

glCallList(quad);

glPopMatrix(); // end of first object

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, textures[1].texID);
glTranslatef(Xpos,Ypos,-32.0f);

glCallList(quad);
glPopMatrix();

glBindTexture(GL_TEXTURE_2D, textures[2].texID);

for(register short i = 0; i < ENEMIES; i++)
{

if(Enemy[i].Active==true)
{
glPushMatrix();
glTranslatef(Enemy[i].Xpos,Enemy[i].Ypos, -28.0f);

glCallList(quad);
glPopMatrix();
Enemy[i].Ypos -= Enemy[i].Speed;
}

}

glBindTexture(GL_TEXTURE_2D, textures[3].texID);

for(register short j = 0; j < BULLETS; j++)
{
if(Bullet[j].Active==true)
{
glPushMatrix();
glTranslatef(Bullet[j].Xpos,Bullet[j].Ypos, -32.0f);

glCallList(quad);
glPopMatrix();
if (Bullet[j].Ypos > 40.0f)
{
Bullet[j].Active = false;
}

Bullet[j].Ypos += 0.50f;

}

}


Hope this helps.... keep us posted on your progress...

http://www.opengl.org/discussion_boards/ubb/smile.gif


Originally posted by -Tony-:
Hi, I'm trying to make top-down shooter game with C/SDL/OpenGL
http://w1.853.telia.com/~u85324201/game.zip

The problem is that when you shoot, the bullets don't come from the plane but from somewhere from the middle of the screen or near the plane.
The planes Xpos,Ypos are the same as the bullets when you fire it so I don't understand why this happens.

Here's the source: http://w1.853.telia.com/~u85324201/main.htm http://w1.853.telia.com/~u85324201/texture.h.htm

I've posted this in many other forums but nobody knew the solution...

Could somebody help?



[This message has been edited by nexusone (edited 09-15-2002).]

-Tony-
09-15-2002, 06:49 AM
I changed the bullets Z position and it works now..Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

I've tried to use ortho view like this

glOrtho(0.0f,1024,768,0.0f,-1.0f,1.0f);

but the screen turns black.

nexusone
09-15-2002, 09:06 AM
The reason it turns black with ortho is you are drawing past the far cliping plane.
In ortho the last two items are far and near cliping. maybe need to expand them..



Originally posted by -Tony-:
I changed the bullets Z position and it works now..Thanks http://www.opengl.org/discussion_boards/ubb/smile.gif

I've tried to use ortho view like this

glOrtho(0.0f,1024,768,0.0f,-1.0f,1.0f);

but the screen turns black.