Simple JavaScript RPG Game Engine

What structures are needed to move between different menus and levels and operational states within a game?

The first JavaScript game engine I built had the functionality to show one simple level, but the universe was basically a singleton. There was no mechanism to alter states, switch to new levels, or even show a start menu.

I didn't notice those shortcomings until I started to try and bootstrap a simple RPG game in it. That showed me that building a game engine requires more than just a rendering and logic loop. It requires finite state machines and the the ability to load in different assets at different times.

Demo