Hi, ive been able to draw as many shapes as i desire using a vector, the problem is im unsure of how to interact with them individually.
say for example, i want the max amount of enemies allowed to spawn to be 5, and when one of the currently spawned enemies exits the screen, it 'dies' then another one is allowed to spawn.
or in the case if when im making a snake game, how would i go about only drawing 1 shape at the end of my snake each time the snake 'eats' the 'food'.
do i have to use iterators? what would i have to use to do this kind of thing?
im not asking for anyone to write the code for me, i just dont know what i need to be using, and i dont have much experience with std::vectors and pretty much none of iterators. so just reading the C++ doc really hasn't helped me figure this out.
this is the basic (probably not optimal) code i have for drawing multiple shapes with a vector.(not full source, just the code for the shape vector)
(what i see that i could do, but am not sure if optimal, or even if it will work as i havent tried yet, is have:
int MaxSpawn = 5;
if(Alive == true)
{
for(int i = 0; i <= MaxSpawn; i++) Window.draw(Bricks);
}
but thats not how i want to do it, because it doesnt do what i want still.
outside the main game loop:
sf::RectangleShape Square;
vector<sf::RectangleShape> Bricks(10, sf::RectangleShape(Square));
for (int i = 0; i < Bricks.size(); i++)
{
Bricks[i].setSize(sf::Vector2f(25, 25));
Bricks[i].setFillColor(sf::Color::Green);
Bricks[i].setPosition(20 + (i * 15), Height/2);
}
inside main loop:
//Draw Here
Window.clear();
for(int i = 0; i < Bricks.size(); i++)
{
Window.draw(Bricks[i]);
}
Window.display();