Reputation: 3020
I'm developing a game using OpenGL. I have a Game
class that contains all the environment variables (by environment, I mean things like gravity or tile sets). There's only one Game
object. I also have another class called Entity
, which contains properties to display objects on the screen.
I'm finding myself needing access to more and more Game
variables in my Entity
class. At the moment i'm just using parameters to pass data into each function, but I'm considering just passing a pointer to the Game
class? Is there anything wrong with that? Is there a better way?
Upvotes: 1
Views: 72
Reputation: 15334
I think this is good practice. It is good idea to replace a group of parameters with a parameter object.
Just make sure that Game
remains cohesive. The variables contained within Game
should be related.
Upvotes: 1
Reputation: 1594
Make Entity a Friend of the Game class.
Please see
http://msdn.microsoft.com/en-us/library/465sdshe.aspx
Note: If this is ever done in C#, there isn't a friend keyword or exact equivalent.
Upvotes: 0