Game Development Reference
In-Depth Information
This code is a little bit confusing because it's being run from inside the `qjcakjKja object. It's almost
as if one of your socks were calling out to you from the drawer, “Hey, it's dark in here, take me out!”
Ideally, you wouldn't want objects to be responsible for adding or removing themselves like this, just
as you wouldn't want your socks telling you what to do. It's much better to have the actual object
that's doing the adding or removing do it directly itself. That way, the control of the game is more
centralized, which can help when you need to make changes.
With a bit more programming, you can create a document class and remove `qjcakjKja directly, like
this:
naikra?deh`$`qjcakjKja%7
This works because the document class is attached to the op]ca that contains `qjcakjKja. You'll find
more information on how to add a document class to manage the game near the end of the chapter.
Picking up the star weapon
When the player touches the star weapon, the weapon's t property is positioned on the left side of
the player, so it looks like it is being carried:
eb$lh]uan*depPaopK^fa_p$sa]lkj%%
w
sa]lkj*eo=nia`9pnqa7
sa]lkj*t9lh]uan*t)$lh]uan*se`pd+.%7
sa]lkj*u9lh]uan*u7
y
This code demonstrates another way you can have the player carry an object—without using ]``?deh`.
The weapon's t and u properties match the player's.
When the weapon's eo=nia` property is pnqa, the player can fire bullets. Here's the entire Sa]lkj class
(I'll show you how it is used to fire bullets next):
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
eilknpbh]od*arajpo*Gau^k]n`Arajp7
eilknpbh]od*qe*Gau^k]n`7
eilknpbh]od*arajpo*Arajp7
lq^he__h]ooSa]lkjatpaj`oIkrea?hel
w
lner]par]n[eo=nia`6>kkha]j7
lq^he_bqj_pekjSa]lkj$%
w
]``ArajpHeopajan$Arajp*=@@A@[PK[OP=CA(kj=``a`PkOp]ca%7
y
 
Search Nedrilad ::




Custom Search