Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
using Microsoft.Xna.Framework.Graphics;
2
3
4
interface IGameLoopObject
{
5
void HandleInput(InputHelper inputHelper);
6
7
8
void Update(GameTime gameTime);
9
10
void Draw(GameTime gameTime, SpriteBatch spriteBatch);
11
12
void Reset();
}
13
Listing 21.1
The interface that specifies the methods implemented by objects that partake in the
game loop
21.2.2 The GameStateManager Class
Now we can start building our game state manager class. Just like the asset manager,
we add an instance of this class as a static member variable to the PenguinPairs class,
together with a static property so that we can easily retrieve it:
protected static GameStateManager gameStateManager;
public static GameStateManager GameStateManager
{
get { return gameStateManager; }
}
In the GameStateManager class, we want to keep track of all the different game
states. We also want to be able to find game states so that we can switch between
them at will. Therefore, we will store the different game states in a member variable
that is of type Dictionary :
protected Dictionary< string , IGameLoopObject> gameStates;
The key type of this dictionary is string , meaning that we can find game states by
using string identifiers. The value type is IGameLoopObject . So, any object that im-
plements the game loop methods can serve as a game state. Next to this dictionary
of game states, we also keep track of the current game state:
protected IGameLoopObject currentGameState;
Search WWH ::




Custom Search