Game Development Reference
In-Depth Information
2. Create the kjAj`C]ia event handler. Add it below kj?khheoekjSepdLh]uan:
lner]pabqj_pekjkjAj`C]ia$arajp6Arajp%6rke`
w
ejopnq_pekjo*patp9Reoeppdabnkcpkpahhdei ±
sd]pukq#ra_khha_pa`*7
eb$lh]uan*_khheoekj=na]*depPaopK^fa_p$bnkc%%
w
bkn$r]ne6ejp9,7e8[_khha_pekjF]n*hajcpd7e''%
w
eb$[_khha_pekjF]nWeY99ikqoa%
w
[ikqoaBkqj`9pnqa7
^na]g7
y
y
eb$[ikqoaBkqj`%
w
ejopnq_pekjo*patp9E`kj#phegaie_a7
y
ahoa
w
ejopnq_pekjo*patp9Pd]jgoranuiq_d7
y
naikraArajpHeopajan$Arajp*AJPAN[BN=IA(kjAj`C]ia%7
y
y
3. Save the I]ej[>qc?]p_dan*]o file and test the project. Now when you collect three items, you
can visit the frog. (The frog will you whether he's happy with what you caught.)
kjAj`C]ia implements the array search system that you looked at earlier. As soon as the lh]uan
touches the bnkc, these lines of code are run:
bkn$r]ne6ejp9,7e8[_khha_pekjF]n*hajcpd7e''%
w
eb$[_khha_pekjF]nWeY99ikqoa%
w
[ikqoaBkqj`9pnqa7
^na]g7
y
y
This code is almost identical to the code that you looked at earlier. If ikqoa turns up as an element
in the array, the [ikqoaBkqj` variable is set to pnqa, and the loop quits. Depending on the value
of [ikqoaBkqj`, a different message is displayed. Finally, the kjAj`C]ia listener is removed, and the
game finishes.
 
Search Nedrilad ::




Custom Search