Jump to content
  • Advertisement
  • entries
  • comments
  • views

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

Sign in to follow this  


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

enum GameState { Loading,
Exiting }
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
void UpdateState();
void HandleLogic();
void HandleRendering();
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  


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
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!