This post is a portion of Part 13 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 13.0 – Game States
- 13.1 – Implementing Game States
- 13.2 – Better Game State Implementation
- 13.3 – Finite State Machine Artificial Intelligence
In this video we focus on improving out game state system. Using a method ‘ChangeState()’ we are able to add robustness. The video covers the use of pre and post state change commands. That is to say, we can execute code when we leave a state and when we enter a state to help improve the overall flow of our games.
Full source can be found here.
Why not using switch?
Thanks for that info on removing the console window, I get so annoyed with that thing, it becomes an eyesore when that’s all you’ve ever coded on pre-allegro.
I use Ubuntu 11.10 to compile this, and if I use give me the the next error:
/tmp/ccU6EFl0.o: In function `__static_initialization_and_destruction_0(int, int)’:
main.cpp:(.text+0x656): undefined reference to `std::ios_base::Init::Init()’
main.cpp:(.text+0x65b): undefined reference to `std::ios_base::Init::~Init()’
so, because in ubuntu the console is open already(compile with commands), I use the header and for the outputs a simple printf(“Entering MENU state”) and it works 🙂