Game Development Reference
In-Depth Information
Picking up the key
You'll see how simple the code of the game really is when you break it up piece by piece. The player's
first task is to pick up the key. The @qjcakjKja[I]j]can class uses depPaopK^fa_p to check for this:
eb$lh]uan*depPaopK^fa_p$`kknGau%%
w
lh]uan*d]oGau9pnqa7
lh]uan*]``?deh`$`kknGau%7
`kknGau*t9,7
`kknGau*u9,7
`kknGau*nkp]pekj9/,,7
y
If the lh]uan object touches the key, the key becomes a child object of the lh]uan by using ]``?deh`,
which allows the lh]uan to carry it around.
To center the `kknGau object over the lh]uan, you have to set its t and u positions to ,. Because it's
now a child of the lh]uan, , refers to position , on the lh]uan object, not the stage. The Lh]uan sym-
bol's center t and u point is ,. The key's rotation is set to /,,, which is just a simple effect to highlight
that it's been picked up.
A very important thing that this code does is set the player's d]oGau setter to pnqa, which will be
needed when the player tries to open a door. Figure 8-17 illustrates how the setter is set.
DungeonOne_Manager Class
eb$lh]uan*depPaopK^fa_p$`kknGau%%
w
lh]uan* d]oGau 9pnqa7
lh]uan*]``?deh`$`kknGau%7
`kknGau*t9,7
`kknGau*u9,7
`kknGau*nkp]pekj9/,,7
y
Player Class
lq^he_bqj_pekjoap d]oGau $gauOp]pa6>kkha]j%
w
[d]oGau9gauOp]pa7
y
The player's _hasKey
property is set to true.
Figure 8-17. The DungeonOne_Manager class sets the player's _hasKey property to true using the Player class's
hasKey setter.
 
Search Nedrilad ::




Custom Search