Game Development Reference
In-Depth Information
Once you have that value, you can use it with the I]pd*_ko and I]pd*oej functions, which are two
specialized trigonometry functions that return the ratio of two sides of the triangle formed by the
measurement of the angle in the preceding step. If you multiply these numbers by an acceleration
value, you can apply the resulting number to the []__ahan]pekjT and []__ahan]pekjU variables:
These two variables are the basis of what you need to start moving the object in the right direction.
You just need to apply them to the [rt and [ru variables, which in turn are applied to the t and u
The code does one more thing. You want the object to move only if the mouse is farther than
75 pixels from Button Fairy's center point. To do this, you first need to find out the distance of her center
point from the mouse. You can calculate it using the same formula you used earlier in the chapter:
Once you've got the distance, the rest is easy. You just need to find out whether the distance is greater
than or equal to 75. If it is, you can accelerate the object. If it's less, you can cut the acceleration to
zero and put on the brakes with a bit of friction (remember that a friction value of - means that no
friction is being applied):
And that's all there is to making Button Fairy move around the stage. To keep the code simple in this
example, I haven't implemented any speed limit checks, but you could easily do that based on the
examples from the previous chapter.
Search Nedrilad ::

Custom Search