Game Development Reference
In-Depth Information
Bullet factory: Using switch
The >qhhap class now knows the velocities it needs to make bullets fly in the right direction, but
there's still the question of that mysterious fifth parameter in the constructor method:
lq^he_bqj_pekj>qhhap$rt6Jqi^an(ru6Jqi^an(op]npT6Jqi^an( ±
op]npU6Jqi^an( ^qhhapPula6Opnejc %
This is a Opnejc variable called ^qhhapPula. It contains whatever you supplied as the fifth argument in
the directive that created the bullet (it can be op]n, _en_ha, or omq]na). It tells the >qhhap class
what kind of bullet you want to create.
The class needs to do something with this information. It needs to match the name of the shape to the
correct frame in the timeline shown in Figure 10-16.
There is more than one way to do this. The “lazy” way is to use an eb/ahoa statement. The slightly bet-
ter way is to use a osep_d statement, which works by selecting (or “switching between”) one option
from many, depending on a value supplied to it. Although the syntax is different, the osep_d state-
ment has exactly the same function as an eb/ahoa statement.
Here's the osep_d statement that finds out what the value of ^qhhapPula is and moves the timeline to
the frame that displays the correct bullet shape:
The osep_d keyword accepts one argument, which in this example is ^qhhapPula:
You know that ^qhhapPula can have three possible values: op]n, _en_ha, or omq]na. In a osep_d
statement, the value is known as a _]oa, and each _]oa can have a different outcome. Let's look at
the first case, op]n:
Search Nedrilad ::

Custom Search