I've previously made a game using a system like this (psuedo code):
ConstructGameObjects()
{
//these are all globals
player = new Player;
enemies = new list;
}
updategame()
{
player.update();
for (enemy: enemies) enemy.update();
if(time to create enemy) createEnemy();
}
createEnemy()
{
Enemy newEn = new Enemy(player);
enemies.add(newEn);
}
render(Canvas c)
{
player.render(c);
//etc. etc.
}
Obviously this became ridicously large and annoying to deal with when the game got to contain around just 30 different things to update.
So after reading various articles, I decided to go with a generic Entity object (that has components). Any entity in the world would be added to a entity list, which would update, render, etc. If I wanted to have new enemies be created during the game, then at the beginning of the game I would add something like EnemyGenerator which would have it's own creation logic built in, and would add enemies to the entity list as needed. The problem I ran into was, how would I get access to the player object now? Before, there was a global I could call from anywhere. How should I go about solving this? I have a few ideas but I'd like to see what other people say.