Game Development Reference
5. Save the I]ej[Lh]ucnkqj`*]o file and test the project.
6. Use the arrow keys to move the lh]uan object so that it's touching the ]llha object. Press the
spacebar on the keyboard. The lh]uan object picks up the apple. Now move the lh]uan object
so that it's touching the ajaiu object. Press the spacebar again; the player drops the apple and
the dynamic text field displays the word Thanks!! If you move the player away from the apple,
it stays where it is. Figure 7-19 shows what this looks like. You can pick up and drop the apple
as many times as you want to, anywhere on the stage. For the purpose of this example, you
haven't disabled the health meter, but that's easy to do if you want to.
Figure 7-19. Friends at last! Use the spacebar to pick up the apple and carry it to the owl.
There are no new techniques here, but you've never seen all of these elements used together in this
combination before. Let's take a tour of this code and how it works. First, initialize the lh]uanD]o=llha
variable to b]hoa in the ejep method:
I'm sure you can see the logic of this. Obviously, the player doesn't have the apple when the program
first starts, so it should be set to b]hoa.
Next comes the new eb statement inside the kjGau@ksj event handler: