Hello.
I think the best way is to start with an example of my problem. I made a little game with diffrent objects. Each object interacts with the others and access them. (Like if a bullet hits a enemy, it destroys the enemy). So maybe you would put all this code in the Game-function()-Method.
I read somewhere that each object should update itself. So i made a Update()-function for every class.
Example:
I got a Ball-Class that checks in his Update()-Function if it collides with the player or other game objects. If the ball touches the lower border, the players lifes are decreased.
The Question:
How do i realise that? I first thought of giving the player each game-loop through the update-function. That wasn't that clean. So i changed the Ball Class
Ball::Ball( Player *player, posX, ....
Now i could access the player in the Update()-function to change its values. But i dont know if this is good practise. One big thing is, that i dont only have to access the player, but nearly every object in the game.
Here is an example of my Ball Class-Structure:
class Ball :
public cEntity
{
private:
double m_VelX;
double m_VelY;
double m_Speed;
bool m_Super;
Player* m_Player;
vector<Ufo*> *m_Ufos;
vector<PowerUp*> *m_PowerUps;
cAnimationManager *m_AnimationManager;
cSound *m_Sound;
public:
Ball(cGraphics *graphics, cAnimationManager *animManager, cSound *sound, Player *player, vector<Ufo*> *ufos, vector<PowerUp*> *powerups, string texture, int posX, int posY, int width, int height);
~Ball();
void Update( double delta );
void CheckCollision();
void Draw();
void Reset();
Should i continue this way?
Thanks,
Daniel