Game Development Reference
In-Depth Information
Limiting movement
You might have noticed that there's no limit to how high or low the cat can go on the stage. In fact,
you can make the cat go all the way to the top of the stage and continue going beyond it endlessly.
There is a kind of existential appeal to being able to model such an abstract concept as infinity in such
a concrete way, but it doesn't help your game!
You have to limit the cat's range by using a conditional statement with the eb keyword. The condi-
tional statement checks to see whether the cat's y position is in an allowable range; if not, it prevents
the directive in the event handler from running.
An eb statement is very easy to implement. It's a block statement that you can drop anywhere in the
program to check whether a certain condition is pnqa. If the condition is pnqa, the directives inside
the block run. If they're b]hoa, they don't run.
Here's a plain English example of how an eb statement works:
eb$sd]paraneoejoe`apdaoal]najpdaoaoeopnqa%
w
***pdajnqjpda`ena_peraoejoe`apdaoa^n]_ao*
y
Let's use a real-world eb statement in the methods you've just written to test it:
1. Add the following code in bold to the program (remember to replace -., and .., with what-
ever numbers you've been using):
bqj_pekjkjQl>qppkj?he_g$arajp6IkqoaArajp%6rke`
w
eb$dehhL]ca*_]p*u:9-.,%
w
dehhL]ca*_]p*u)9-17
y
y
bqj_pekjkj@ksj>qppkj?he_g$arajp6IkqoaArajp%6rke`
w
eb$dehhL]ca*_]p*u89..,%
w
dehhL]ca*_]p*u'9-17
y
y
2. Save the I]ej*]o file and test the project.
 
Search Nedrilad ::




Custom Search