A little while ago, I got some help in making state switching easy to understand and carry out without (too) many issues. Since I've been trying to get back into the swing of things, I decided to begin documenting the things I learn and turning them into proof-of-concept demos. My hope is to be able to come back to the code and understand why it was useful to me.
The eventual goal is to build and/or showcase some code that makes building PICO-8 games easy and fun for me.
The Closure State Demo is simple:
- There are two states: ring, and FOE (kudos to those who get the reference)
- You swap between the states using X
- The same variable name is used ("message") to display different text in each of the game states
- The FOE starts in the same place every time you begin its phase
I threw in a few extras, like movement and bounds-checking for the FOE sprite so it feels a little more "real".
More detailed notes are contained in the cartridge's comments. Let me know if it makes sense or is useful for you!