• entries
    33
  • comments
    37
  • views
    38680

[Beginners] How To Move From Tutorials To Your Own Game Part 1

Sign in to follow this  
superman3275

837 views

One thing I see constantly on these forums are people who are having trouble actually making a game. They understand the language and library they're using, however making their own game is hard because they are so used to either tutorials, or they don't understand the large amount of knowledge you need to have to even get started. This series of articles aim is to resolve that issue.

A game needs a State Machine.

State machines allow your program to do different things depending on whether you're in the main-menu, playing the game, paused, or the game is over. Let's look at two common types:

1) Enumerated State Machines


//STATE MACHINE DECLARATION
enum GameState { Loading,
InMainMenu,
InCredits,
Playing,
InGameOver,
Exiting }
//GAME LOOP
if (GameState == Loading)
{
//Display Loading Screen
}
else if (GameState == InMainMenu)
{
//Check for Button Clicks
//Display Main Menu
}
else if (MyGameState == InCredits)
{
//Display Credits
}
else if (MyGameState == Playing)
{
//Game Logic
//Game Draw
}
//////////////////////////////////
// You Get The Idea //
//////////////////////////////////


Normally these are an enumeration that is equal to whatever State your game is in. However sometimes you want a more flexible system. When you want that you can use:

2) Objective State Machine

An Objective State Machine is an object that will handle whatever Logic and Rendering it needs depending on it's state and Updates itself. Here's an example of one:


class StateMachine
{
public:
void UpdateState();
void HandleLogic();
void HandleRendering();
private:
bool MainMenu;
bool Playing;
bool Exiting;
Window * DrawWindow;
Event * CheckEvent;
GameLogic MyLogic;
GameDraw MyDraw;
}


Of course this code isn't really though through, but it should give you an idea.

That's it for today, if you have questions ask below. A great area of reference for this if you want to read further is LazyFoo!
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now