Hey everyone. I am doing a space game
Here is the code of the main function.
When i press space only one bullet is fired and it keeps reappearing when i press space.
can anyone tell me why does this happen.
i want as many bullets that i fire to appear on the screen. please help
int main()
{
int i=0;
Ship shipObject;
Bullet bullletObject;
vector <Bullet> bulletArsenal;
myGameGUI.create(sf::VideoMode(1000,680), "WorkingGameProject");///Creates the Window
sf::Style::Default;
Background();///Creates the background
shipObject.createShip(shipTexture, shipImage);///calls function ship class and creates the ship
while(myGameGUI.isOpen())
{
while(myGameGUI.pollEvent(action))
{
closeFunction();
}
bool fire =false;
shipObject.moveShip(action, shipImage,myGameGUI);///Calls function from ship class and Moves the ship
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)){
bulletArsenal.push_back(bullletObject);/// adds a new object to the vector
bulletArsenal[i].createBullet(bulletTexture,bulletImage,shipImage);/// creates a bullet of a specific object
fire=true;
}
bulletArsenal[i].moveBullet(bulletImage); ///move the bullet of a specific object
myGameGUI.clear();///clears screen
myGameGUI.draw(backgroundImage);///draws the background
shipObject.drawShip(myGameGUI,shipImage);///draws the ship
bulletArsenal[i].drawBullet(myGameGUI,bulletImage);///draws the bullet of a specific object
myGameGUI.display();
if(fire==true)
i++;
}
return 0;
}