Game Development Reference
In-Depth Information
lh]uanD]o=llha9b]hoa7
eb$ajaiu*depPaopK^fa_p$]llha%%
w
iaoo]ca@eolh]u*patp9Pd]jgo7
y
y
y
y
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:
lh]uanD]o=llha9b]hoa7
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:
eb$arajp*gau?k`a99Gau^k]n`*OL=?A""lh]uan*depPaopK^fa_p$]llha%%
w
eb$lh]uanD]o=llha%
w
lh]uan*]``?deh`$]llha%7
]llha*t9,7
]llha*u9,7
 
Search Nedrilad ::




Custom Search