HTML and CSS Reference
In-Depth Information
Chapter 2
Making It a Game
What's in this chapter?
• Exploring scene management
• Adding projectiles and enemies
• Using collision detection
• Creating explosions
Wrox.com Code Downloads for this Chapter
The wrox.com code downloads for this chapter are found at www.wrox.com/rem-
title.cgi?isbn=9781118301326 on the Download Code tab. The code is in the chapter 02 download and individu-
ally named according to the names throughout the chapter.
Introduction
In Chapter 1, “Flying Before You Walk,” you put together the framework of your first HTML5 mobile game and
got a spaceship flying around the screen. Until this point what's been built so far is more a toy than a game. To
make it a game, you need to add some enemies and set up the various elements of the game so that they can
interact with each other.
Creating the GameBoard Object
The first step to turning Alien Invasion into a game is to add a mechanism that handles a bunch of sprites on the
page at the same time. The current Game object can handle a stack of boards, but those boards all act independ-
ently of each other. Also, although the Game object provides a mechanism to swap boards in and out, it doesn't
make it easy to add an arbitrary number of sprites onto the page. Enter the GameBoard object.
Understanding the GameBoard
The purpose of the GameBoard object is much like the game board in a game of checkers. It provides a spot to
drop all the pieces and dictates their movement. In this section you break down some of the responsibilities of
this object. The responsibilities of the GameBoard can be broken down into four distinct categories:
Search WWH ::




Custom Search