Game Development Reference
In-Depth Information
Much of this code you will recognize from previous examples, so if you're unsure about how the
=@@A@[PK[OP=CA and NAIKRA@[BNKI[OP=CA events are working, refer to Dungeon Maze Adventure, in
which you took an in-depth look at these events and why you need to use them. What's very impor-
tant here, however, is the system of “manufacturing” bullets.
The >qhhap class is bound to the >qhhap symbol in the Library . The >qhhap symbol is made up of three
frames: on the first frame is a graphic of a red star, on the second is a blue circle, and on the third is
a green square (see Figure 10-16).
Figure 10-16. The three frames of the Bullet symbol
In the >qhhap class, these three frames are represented by constants:
lner]pa_kjopOP=N6qejp9-7
lner]pa_kjop?EN?HA6qejp9.7
lner]pa_kjopOMQ=NA6qejp9/7
These constants simply represent numbers that relate to the frames on the bullet's timeline: 1, 2, and
3. I could have easily dropped these constants from the class and just used the frame numbers directly
in the code. The code would have worked just fine. But you'll soon see how using constants like this
makes the code much more readable and easier to understand.
The >qhhap class creates bullets by accepting the values that you supplied it in the Lh]uan class. Do
you remember this directive from the Lh]uan class?
r]n^qhhap6>qhhap9jas>qhhap$^qhhap[Rt(^qhhap[Ru(^qhhap[Op]npT( ±
^qhhap[Op]npU(omq]na%7
Those variables from the Lh]uan class are sent to the >qhhap class. They appear as parameters in the
>qhhap class's constructor method:
lq^he_bqj_pekj>qhhap$rt6Jqi^an(ru6Jqi^an(op]npT6Jqi^an( ±
op]npU6Jqi^an(^qhhapPula6Opnejc%
The parameters are local variables that the class can use. They contain the same values that were
passed to it when the bullets were created in the Lh]uan class. The >qhhap class needs the values of
these variables to make bullets. I could have used the same variable names, but I changed their names
to stress the point that they are new variables that are being created in the >qhhap class.
These are the values you need, but there's a snag. Those variables in the parameters are available only
to be used in the constructor method; they can't be used anywhere else in the class. To get around
this, you can copy their values into instance variables. Instance variables are available everywhere in
the class.
 
Search Nedrilad ::




Custom Search