Chapter 4. Using HTML5 to Catch a Snake
This chapter is the first part of a two-part series, where we'll build the first version of a game, and then spice it up with more HTML5 APIs in the next chapter. Both versions will be complete and playable, but since covering all of the APIs in the same game within one chapter would make for a very large chapter, we'll break things up into smaller chunks, and write two separate games.
The first version of the game will cover five new concepts, namely, HTML5's 2D canvas API, offline application cache, web workers, typed arrays, and requestAnimationFrame. The canvas element allows us to draw 2D as well as 3D graphics, and manipulate image data at a very low level, gaining access to individual pixel information. Offline application cache, also known as app cache, allows us to cache specific assets from a server into the user's browser, so that the application can work even when no internet access is available. Web workers is a thread-like mechanism that...