And, yes, it HAS to be global. That's just plain retarded.
No it HAS NOT. You are missing the entire point of programming in any language above assembler: encapsulation. Even by keeping a procedural approach to the problem, wanna see how the global goes away? Here it is:
int main()
{
vector<Player*> players;
// CREATE 10 players
for (int i=0;i<10;i++)
{
players.push_back(new Player());
}
// GAME LOOP
while (true)
{
updatePlayers(players);
render(players);
}
// clean up yada yada
return 0;
}
void updatePlayers(vector<Player*>& players)
{
for (auto player : players)
{
// UPDATE THE PLAYER
}
}
there you go.. players is not global anymore and only functions that REQUIRE access to it receive it as a parameter.
This gives you the huge advantage that now you know which subset of your code can access to players.. and when your code reaches 100k lines of code possibly multithreaded, trust me, you'll be glad to be limited to 3-4 functions instead of the EVERYWHERE you get from a global.