I've started developing a game in C++. To begin with i just did some proof of concept with lots of (bad?) global variables.
After cleaning up and attempting to exhibit better programming practises i have been moving my variables into my main function and passing them to parameters. This is from my understanding the way to go since you have control of what functions can modify what variables.
The problem is that i'm passing way too many variables to functions that shouldnt need them.
An example is an objects move() function, this move function checks for collisions, if there is a collision it calls a damage function which might cause the player to die and then call a GameOver() function which resets the game.
The game over function needs to reset alot of variables which i as a (good?) c++ developer is passing to it as parameters, but those parameters come from the damage function which gets them from the move function. So when i call the move function in the main function, it basically needs pointers to all the variables in the game which seems really really silly!
I can't possibly believe this is the way to go, but neither is global variables.
So my question is if i should put these variables as static data members of a static class as a way to avoid global variables. But i've heard that this is just as bad as global variables as they suffer from the same problems (Who modified what?)
I've tried to find some high quality open source games on here, but every post with that purpose just tells the OP to go and get his hands dirty himself.
Any advice is appriciated! thanks!
tl;dr Should i use static members for game global variables, or if not, then what?
Edited by crovea, 07 June 2012 - 11:47 AM.