I have begun a game project, and I would like a second opinion on a problem that has popped up.
The Problem:
This is my first game project as well as my first major C++ project, so if this is a horrid method of accomplishing this task, please inform me! I needed a way of organizing code for different screens in a game, so I asked a friend of mine who has had more experience in this field. This is what he tells me:
Each screen of the game (title, game, score, etc) is defined as a State. Each State should have functions:
- Code: Select all
void draw(); //Draws the States visuals to the canvas
void update(logic params); //Update logic of the State
void getName(); //Get the name of the state
State(canvas); //Constructor
Have a manager (StateHandler) contain States in an array. It should have the following functions:
- Code: Select all
void addState(); //Adds a state to the array
void switchState(std::string name); //Switch the active state
void drawState(); //Draw the current state
void updateState(); //Update the current state
StateHandler(input, canvas);
*input and canvas is whatever the sdk uses
Is this a good way of organizing a game? Even though he is more experienced than me in the game programming world, he codes in Java and C# not C++, so I’m not sure if his advice will apply.
Oh, one more thing that I came across, probably a silly question but:
- Code: Select all
int * p1;
int & p2;
I know that the first one is a pointer, but what is the second one called? A reference? What is the difference between them? When I try looking up pointers and references it just gives me that a pointer is something that returns the value of the variable at address of p1 (in the example) and a reference is what you set p1 to (p1 = &var). I'm not sure what the difference between what they hold are.
Thank you!
SFI
