First, just on an efficiency note, removing an element from a vector at any point other than the end is quite expensive (it needs to shift all the values in front along one) - you may want to consider using a
std::deque if removals from the front as well will be common.
The other advantage is that with a
std::deque you can turn it into a queue (actually, there is an STL class that is a wrapper on
std::deque called
std::queue), so you can use its
pop_front method to remove the first Coin off the front of the list. Though, this is assuming that a Coin 'pushed' onto the queue will always be cleared first, otherwise there isn't much point to this approach.
Also, @tath, what is with line 6? And why do you feel the need to go backwards along the vector? All you've done is make segfaults, remember it starts at element 0 and goes to size() - 1. Maybe you meant this:
1 2 3 4 5 6 7 8 9
|
for (std::vector<Coin>::size_type i = 0; i < CoinSet.size(); ++i) {
CoinSet[i].move(player.collider());
player.move(CoinSet[i].collider());
// The above line - why is the player moving for every coin?
if (CoinSet[i].ClearCoin()) {
numbers.erase(CoinSet.start() + i);
}
}
|