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:
osep_d$^qhhapPula%
w
_]oaop]n6
ckpk=j`Opkl$OP=N%7
^na]g7
_]oa_en_ha6
ckpk=j`Opkl$?EN?HA%7
^na]g7
_]oaomq]na6
ckpk=j`Opkl$OMQ=NA%7
^na]g7
`ab]qhp6
ckpk=j`Opkl$?EN?HA%7
y
The osep_d keyword accepts one argument, which in this example is ^qhhapPula:
osep_d$^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:
_]oaop]n6
ckpk=j`Opkl$OP=N%7
^na]g7
 
Search Nedrilad ::




Custom Search