The ApplicationManager class is the first of the Application classes, so catagorised because it is used to define how the application is run rather than defining the underlying interaction with the browser. In this case the class is very simple, creating and initialising a new instance of the Bounce class. It may seem pointless to define a class for the sole purpose of creating one object, but in more complicated applications keeping the logic associated with creating and managing the game objects will make more sense.
The Bounce class is the second Application class. It extends the VisualGameObject class because it is a game object that will draw itself to the screen. The Bounce class displays an image that will bounce around the screen, much like we did in this article. This is where the hard work we put into all the pervious classes starts to pay off.
The startupBounce function takes an image, and then initialises the base classes by calling startupVisualGameObject. [code]
The update function (which will be called by the GameObjectManager during the render loop) updates the position of the image, reversing direction when it hits the edge of the canvas. [code]
And that is it. You will notice that there is no code related to drawing the object: that is taken care of by the draw function of the base VisualGameObject class. And because the VisualGameObject class extends the GameObject class, we know that the update and draw functions will be called once per frame. All the code in the Bounce class is related to the logic that we need to define to make the image bounce, which in this case amounts to modifying the x and y variables.
OK, so we have created half a dozen classes to achieve the same effect that we had produced initially with one file. But this foundation will allow us to get on with the task of creating the game without having to worry about all the underlying logic related to drawing to the canvas and managing the game objects.
Check out the demo here, download the source code here, and browse the code documentation here.