Game Development Reference
If the spacebar or up arrow key is pressed, the code checks to see whether the object is on the
ground. If it is, it adds the jump force value to the vertical acceleration. It also sets the [eoKjCnkqj`
variable to b]hoa. In this example, it also makes the cat's ears flap.
The last little technical issue that you need to solve is that after the preceding code sets
__ahan]pekjU to -10, it remains that way until the jump keys are released. That means that if the keys are
held down, __ahan]pekjU will remain at -10, and the object will keep jumping. To fix this, you
need to give __ahan]pekjU a value of zero if the object is not on the ground. This section of code in the
kjAjpanBn]ia event handler accomplishes this:
One more little detail prevents the cat's ears from flapping when it descends from the apex of the
jump. This is easy to do:
The animation stops if the cat's vertical velocity is less than ,, which means it's moving toward the
bottom of the stage.
Finally, there's no speed limit set if the object ascends because that would conflict with the value of
Stage boundaries and subobjects
There's another feature in the Lh]uan[Fqil class that will get you thinking about some of the other
issues you'll be looking at in the example Bug Catcher game, coming up next. If you move the cat to
the left or right side of the stage, its ears extend beyond the stage boundaries. It is, in fact, the cat's
body that's being blocked at the edges.
This happens because the cat has a subobject called ^k`u. It's a round black circle that defines the
main area of the cat. It seemed to me that it looked more natural to use it as the cat's collision area
instead of using its overlong ears. The ears are great for flying, but seem to get in the way of every-