Jump to content

  • Log In with Google      Sign In   
  • Create Account





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

Posted by superman3275, in Beginners 26 October 2012 · 490 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!




June 2013 »

S M T W T F S
      1
2345678
9101112131415
16171819 20 2122
23242526272829
30      
PARTNERS