For a vector in c++ you use erase. I meant iterate through and delete one bullet that's off screen each loop.
int found = -1;
for(int i =0; i < bullets.size;i++)
if(bullets[i].y<500) // move code;
else found = i;
if(found > -1) bullets[found].erase;
or make it invisible or whatever.
Otherwise you could put the off screen bullets at the front and iterate at a higher starting number each time one went off screen, or at the back an stop iterating earlier. For that matter, there's about a million ways you could do it and why am I suggesting anything?
Pardon me, but that's an odd way to solve the problem, I think!
This is more or less how I solved it (in English):
I created a self-contained entity (a "bullet"), and assigned that to a "gun," and assigned that to a "player."
The gun can fire a bullet (if it contains any). The bullet will update it's own position. The bullet knows when it has been "fired."
The bullet also knows when to quit updating itself (due to an 'out-of-range' issue). That's about it!
An example of this (horray YouTube) in action:
Of course: The specifics of what library (if any) that you're using don't really apply here.
I figure if you're going to use C++: Why not do it in a C++-fashion (with objects)?
Yes! I am implying C++ should be more object-oriented. It's a beautiful feature for solving these type problems.
From a pure coding point, this is all that exists in the code that carries any real weight:
Player "3" is the yellow box.