Game Development Reference
chapters. If you understand the problem now, you'll be miles ahead of the curve when you get into col-
lision detection and stage boundaries. What is it? Let's do a bit of detective work and find out.
You set up the conditional statements so that the directives execute only if the cat's y position is less
than 120 or greater than 220. But is that really what is happening? It is, but it's not working in the way
you might have expected. Let's use pn]_a to make a quick test:
1. Add the following two pn]_a directives in bold to the kjQl>qppkj?he_g and kj@ksj>qppkj?he_g
2. Save the I]ej*]o file and test the project.
3. Click the down button a few times and have a look at the Output panel. Do you see a number
greater than the maximum that you specified your cat should be allowed to go to?
4. Click the up button a few times. Does the cat's y position become less than the lowest position
that you specified in the conditional statement?
When I click the down button seven times in my storybook, I get this out-
put from the pn]_a statement, as shown in Figure 4-7.
I set my conditional statement to limit the cat's y position to 220, but the
trace clearly shows that the cat moves to a y of position of 225! What
It looks like a bug, but the code is actually working exactly as it should be.
Think about it carefully. Let's say I clicked the down button six times. That
would give the cat a y position of 210. The next time I click the button, the
conditional statement runs:
Figure 4-7. The cat's y position
value is higher than the limit you
set in the if statement.
At this stage in the program, you can interpret it to mean this: