1
General / [Solved] How to assign directions to bullets in vector when they are created
« on: October 08, 2015, 10:23:39 am »
I have a vector, where i add bullets if a key is pressed. I would like to assign a direction (left/right) - or + upon creation. I can't figure it out. I thought about creating another vector for the bullets that i want going left, but it seems not the smartest solution.
this is how a new bullet is been created. IS it possible to add something like (-1*)so later when i call move on bullets the negative ones will fly left?
sf::Sprite *nshot = new sf::Sprite;
nshot->setPosition(player.getPosition());
nshot->setTexture(shoot);
bullets.push_back(*nshot);
this is how i move them atm. (direction_left is true when leftkey is pressed), this is no good, because when i press right they change their direction.
this is how a new bullet is been created. IS it possible to add something like (-1*)so later when i call move on bullets the negative ones will fly left?
sf::Sprite *nshot = new sf::Sprite;
nshot->setPosition(player.getPosition());
nshot->setTexture(shoot);
bullets.push_back(*nshot);
this is how i move them atm. (direction_left is true when leftkey is pressed), this is no good, because when i press right they change their direction.
for (auto i = bullets.begin(); i != bullets.end(); i++)
{
//according to direction fly left or right
if (direction_left)
i->move(-1000.f * bulletSpeed.asSeconds(), 0);
else
i->move(1000.f * bulletSpeed.asSeconds(), 0);
}
{
//according to direction fly left or right
if (direction_left)
i->move(-1000.f * bulletSpeed.asSeconds(), 0);
else
i->move(1000.f * bulletSpeed.asSeconds(), 0);
}