Following the State pattern, every state in my game is a derived object that reflects a particular segment of the game (MenuState, PlayingState, GameOverState, etc.)
Each of those state objects holds a container of objects pertinent to that world state (eg. menuButtonOBject for MenuState, playerObject/enemyObject for PlayingState, etc.)
For each frame, every object from that particular state makes a call to its update() method:
#include "GameState.h"
#include "GameObject.h"
class MenuState : public GameState {
public:
// member functions...
virtual void update() {
//pseudocode
foreach (object in objectContainer)
object->update();
}
private:
std::vector<GameObject*> objectContainer;
}
My question being: what is the most common way to make the GameObject's update() method to have access to every other object in the state?
Eg: my veryBadassEnemyObject needs to know if the playerObject is within a particular x0,y0 -> x1,y1 rectangular area.
The straightest approach I can think of is simply passing the object container to the update function as a parameter, but I have the feeling that there is a much more professional, better way to do it.