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.