Game Development Reference
In-Depth Information
Figure 1-6.
Balloon Saw game screen
In this game, the player controls the spinning blade with the mouse. Balloons fly up from the bottom
of the screen. The player must move the spinning saw blade into the balloons to pop them and
make them disappear from the screen. As the player continues to pop balloons, the level increases,
and the balloons start to move faster. If the player misses five balloons, the game is over. There is
no end game sequence, so restarting means quitting the game and running it again.
Breaking down the Balloon Saw code
We'll now take apart the code one section at a time and explain what is happening in detail. We
have left the unchanged code in these code segments so you can view it in context, but we won't
describe much of this code as it was just covered in the last section.
Imports
First, we must import the necessary classes into our
Game
class. The
flash.geom.Rectangle
class
is used to create a bounding box for the mouse;
flash.media.Sound
is used to play the
pop()
sound, and
flash.text
will be used to create
TextField
objects for our scoreboard.
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
import flash.media.Sound;
import flash.text.*;