Game Development Reference
Clicking the left mouse button fires the bullets:
The [odkpBena` variable keeps track of whether a shot has been fired. This prevents a bullet from being
fired more than once each time the left mouse button is clicked. You could actually have left out this check,
and the code would have worked pretty well, but occasionally a mouse click results in more than one bullet
being fired. Using a Boolean variable to limit bullets to one per mouse click is a fail-safe system.
The odkkp>qhhap method actually does the work of firing the bullet:
First, its velocity is calculated:
These directives reuse the jcha variable that you calculated earlier. I]pd*_ko and I]pd*oej are used
to find the ratio of two sides of the triangle formed by the angle, the same way you used them to help
move Button Fairy. These numbers are then multiplied by -10, which is the effective velocity of the
bullets: 10 pixels per frame. These numbers need to be negative so the bullets move in the right direc-
tion. The results of these calculations are stored in ^qhhap[Rt and ^qhhap[Ru. You'll soon be passing
these variables to the >qhhap class, which uses this information to help make the bullets.