This project is not designed to run on your device. Add it to a collection to play later, or you can try to run it anyway.

Game States

This cart demonstrates how to have different game states for your game. (Such as menu, game, game over, etc.)

Simple Version

Notes: The basic idea is that PICO-8 normally runs _update() and _draw() 30 times a second. Instead of putting all our code into those two functions, we make separate update and draw functions for each of the states we need for the game. Then we have a variable called state that stores which state the game is currently in. Then, based on that variable, _update() and _draw() will run the appropriate update and draw function for the current state. (Such as menu_update() and menu_draw() for the menu state.

Advanced Version

Notes: The basic idea is that PICO-8 normally runs _update() and _draw() 30 times a second. However, because you can treat functions like variables, you can store one function's code in another function.

So for changing states, we just make our own separate _update() and _draw() functions for each state. Such as menu_update() and menu_draw() for the menu state. Then we make an _init() function for each state, such as menu_init() that re-assigns _update() to menu_update() and _draw() to menu_draw(). Then PICO-8 will run those functions 30 times a second until we say otherwise.

StatusReleased
CategoryOther
PlatformsHTML5
Rating
Rated 5.0 out of 5 stars
(1 total ratings)
AuthorMBoffin (Dylan Bennett)
GenreEducational
Made withPICO-8
TagsPICO-8, sourcecode

Download

Download
game_states_simple.p8.png 6 kB
Download
game_states_advanced.p8.png 6.3 kB

Install instructions

Save these files to your PICO-8 carts folder. Then load the one you want by typing either load game_states_simple or load game_states_advanced in the command line mode of PICO-8.