Game Development Reference
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 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:
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):