PDA

View Full Version : Problems Rendering projectiles



johndolf123
04-17-2012, 05:16 AM
Hi everyone

This is my first post on here so please bear with me.

I am making a version of the space invaders game in 2d and I am having problems with the rendering side of things. My problem at the moment is the rendering of the bullets from the player ship. Every time I press the fire button (in this case the space bar) it renders the max number of bullets which i have set to 3 instead of just the one. Also it re-renders these bullets at the player ships position deleting the previous bullets. One more thing it also renders a bullet at a position on the screen without the fire button.

That's the main problem I am having at the moment.

If it helps here is the part that renders the bullets

glBindTexture(GL_TEXTURE_2D, shipBullet);



for(int i=0; i<NUM_SHELLS; i++)
{
glPushMatrix();
if(game.Shells[i].isDestroyed());
{

glBegin(GL_QUADS);
glTexCoord2d(0,0); glVertex2f(game.Shells[i].getX(), game.Shells[i].getY());
glTexCoord2d(1,0); glVertex2f(game.Shells[i].getX()+6, game.Shells[i].getY());
glTexCoord2d(1,1); glVertex2f(game.Shells[i].getX()+6, game.Shells[i].getY()+30);
glTexCoord2d(0,1); glVertex2f(game.Shells[i].getX(), game.Shells[i].getY()+30);
glEnd();

}
glPopMatrix();
}


Here is the function that handles the players fire button:


bool Game::HandleFireMessage()
{
if(!Ship.isDestroyed())
{
for(int i=0; i<NUM_SHELLS; i++)
{
if(Shells[i].isDestroyed())
{
Shells[i].setPieceDestroyed(false);
Shells[i].setX((float)Ship.getX()+37);
Shells[i].setY((float)Ship.getY()-20);
Shells[i].setYSpeed(-0.1);



return true;
}
}

}
return false;
}

If there is anything you else you need to know I will do my best to answer.

Hope someone can help me, thanks.

Rosario Leonardi
04-17-2012, 02:43 PM
Why are you doing

pushMatrix
popMatrix

if you are not modifing any matrix?
bullet position are in world space or local (or spaceship) space?
If are in world space the modelViewMatrix is set to camera matrix?
If are in local space where are the glMultMatrix (localBulletMatrix)?
How did you update the bullet position?

johndolf123
04-18-2012, 05:25 AM
I was just playing with statements trying to fix my problem.

To move the bullet position I have a move function that I have created inside a PlayingPiece class and then I created a Ship and Bullet object which I have called Shells. The move function looks like this,

bool PlayingPiece::move(double millieseconds)
{
setX(getX()+(getXSpeed()*millieseconds));
setY(getY()+(getYSpeed()*millieseconds));

return true;
}

This function is called within another function called makeOneMove() and this handles all the movement and collision detection, I haven't sorted the collision detection yet. makeOneMove() is called through every step of a while loop that runs until the program has exited.

I'm thinking now that the way I'm updating is wrong, so any help you can give would be appreciated

Thanks.

Rosario Leonardi
04-18-2012, 01:30 PM
Sorry but I can't debug from here and still I don't have a clear vision of the problem, looks more a game logic problem that a openGl problem.
Isolating the game logic from the problem, if you set the correct game state (harcoding buller and spaceship position) and put the game in pause the rendering is correct?

johndolf123
04-19-2012, 11:50 AM
I see, I will look closer at my logic. Thanks for your time anyway Rosario