The MainMenu class is a very simple class that displays an image on the screen, and calls the ApplicationManager startLevel function when a key has been pressed.
The last additional class is the LevelEndPost. This class is very similar to the Powerup class, except that it calls the ApplicationManager openMainMenu function when the player touches it, effectively ending the current level. [code]
One thing that is worth mentioning here is that each class that extends the GameObject class has two functions to enable them to be cleaned up: shutdown and shutdownClassName. This is because you can not override a parent function, and then still call that parent function.
That was a bit of a mouthful, but the following diagram should make it easier to understand. Take the classes VisualGameObject, AnimatedGameObject and Powerup. See how a call to the shutdown function in each class flows through to the base classes.
shutdown -> shutdownVisualGameObject -> shutdownGameObject
shutdown -> shutdownAnimatedGameObject -> shutdownVisualGameObject -> shutdownGameObject
shutdown -> shutdownPowerup -> shutdownAnimatedGameObject -> shutdownVisualGameObject -> shutdownGameObject
By adding the shutdownAll function to the GameObjectManager, and implementing a system whereby the shutdown function on all classes that extend the GameObject will recursively shutdown parent classes, we have a very easy way to clean up any game objects and swap back and forth between a main menu screen. In future articles we will use this ability to load new levels, and implement high score screens.
Check out the online demo here, download the source code here, and browse the source code documentation here.