Game Development Reference
In-Depth Information
dehhL]ca*_]p*u9..,7
y
pn]_a$dehhL]ca*_]p*u%7
y
2. Save the I]ej*]o file and test the project.
3. Click the up and down buttons and see what happens to the cat when it reaches the outer
bounds of its range. It will stay in range and never move beyond the two values you gave it. The
traffic cop is doing its job!
How does this work?
Let's imagine that the cat is at y position 210. You click the button, and the first directive executes. It
assigns the cat a new y position of 225. But now you have an eb statement that runs immediately after
this one. Its job is to check to see whether the cat's y position is greater than 220. Yes, 225 is definitely
over, so the conditional statement resolves as pnqa, and the directive in the eb statement runs. That
directive is a really simple one:
dehhL]ca*_]p*u9..,7
All it does is force the cat to a y position of 220. So even though the first directive produced a value
of 225, the eb statement corrected it, and that's the result you see on the stage. The cat stops at a
y position of exactly 220 pixels. The traffic cop is doing its job!
The eb statement in the kjQl>qppkj?he_g method does exactly the same thing by checking whether
the cat's y position is less than 120 and then forcing it to position 120 if it is.
Bugs? Ha! You've got a real feature now!
This might all seem a little overly technical, but these kinds of bugs-that-aren't-really-bugs-but-things-
that-could-be-better will probably end up taking up the majority of your programming time as you
refine how your games work. As another rule of thumb, about 30% of development time is spent get-
ting a game to work; the other 70% is spent getting it to work well.
The other reason why this is such an important issue to deal with early on is that you'll be faced with
this exact same problem when you look at collision detection and stage boundaries—except that your
objects will be updating their positions 30 frames per second at speeds and in directions that you'll
have no direct control over. Remember this solution because it will come to your rescue in a massive
way a few chapters from now.
 
Search Nedrilad ::




Custom Search