Game Development Reference
In-Depth Information
and a render function where the object can draw itself on screen. This can easily
be described in C# using an interface.
public interface IGameObject
{
void Update(double elapsedTime);
void Render();
}
Now anything you want to create in the game can inherit from this interface. The
I in IGameObject is used to identify the interface as an interface in the code.
When designing the game structure, the code can refer to IGameObject sin
general without having to worry about the specifics of what any game object
actually is. We can start using game objects right away to describe game state.
Handling Game State
Games are usually broken up into lots of different states. At the top level there's
perhaps a company splash screen followed by a title menu, there are submenus
for options such as sounds, an option to start the game, and perhaps several
others. Here's a na¨ve way to program that kind of game state.
enum GameState
{
CompanySplash,
TitleMenu,
PlayingGame,
SettingsMenu,
}
GameState _currentState = GameState.CompanySplash;
public void Update(double elapsedTime)
{
switch (_currentState)
{
case GameState.CompanySplash:
{
// Update the starting splash screen
} break;
 
 
Search WWH ::




Custom Search