State machine example
Posted: Thu Jul 25, 2013 9:46 pm
This topic hopes to achieve two things:
1.) be a springboard for anybody struggling to implement a basic state machine for their game.
2.) be a space for more experienced programmers to see potential pitfalls or helpful features I can remove/add to this state machine.
The example I'm posting is only a few hundred lines, and pretty well commented. I'll say a few things about it here, too, though.
I got the idea from Axel, who developed the AxGL framework for flash game development. See axgl.org.
The way he implements states is to have a "stack" of states. Then the developer can create new states, push them on the stack, remove them from the top, or switch a top state with another new state. It's a helpful way to organize a game, IMO.
He has a picture that shows the states he used in his game Diamond Hollow and how they stack together:
And here is my .love example which you can dissect to see just how easy it is to implement yourself!
1.) be a springboard for anybody struggling to implement a basic state machine for their game.
2.) be a space for more experienced programmers to see potential pitfalls or helpful features I can remove/add to this state machine.
The example I'm posting is only a few hundred lines, and pretty well commented. I'll say a few things about it here, too, though.
I got the idea from Axel, who developed the AxGL framework for flash game development. See axgl.org.
The way he implements states is to have a "stack" of states. Then the developer can create new states, push them on the stack, remove them from the top, or switch a top state with another new state. It's a helpful way to organize a game, IMO.
He has a picture that shows the states he used in his game Diamond Hollow and how they stack together:
And here is my .love example which you can dissect to see just how easy it is to implement yourself!