Game Development Reference
In-Depth Information
I mentioned earlier that I]pd*omnp is one of the most processor-intensive of AS3.0's
math functions, so if you can avoid using it in your code, you'll give your games
a noticeable performance boost.
How can you avoid it? By exchanging CPU power for brain power: use a hand-held
calculator and precalculate the value yourself!
Here's how to change the code in this example to avoid using I]pd*omnp :
Where does 12.1 come from? It's 75 times 75 (75 squared). By calculating the value
yourself, you can drop I]pd*omnp , and the effect will be exactly the same, except that
you'll probably notice that your object moves a little more smoothly across the stage.
Of course, 12.1 is not really a very understandable number to work with, especially
while you're designing and testing a game, but you should always consider optimizing
any code that uses I]pd*omnp like this in the final stages of polishing up.
Rotating the wand
Button Fairy's wand is the yellow dot that fires stars in the direction of rotation. It's a separate subobject
called s]j` in the Lh]uan symbol. It's centered at an t and u position of zero, directly in the center of the
symbol, so it's easy for you to make it move around the center of the lh]uan object. To do this, you first
need to define the radius of the imaginary circle that you want the s]j` to move in:
I gave it a negative value so the wand will point in the direction of the mouse instead of away from it.
The wand's t and u position is obtained by multiplying the radius by the same angle ratios obtained
using I]pd*_ko and I]pd*oej that you looked at earlier. The work of calculating the angle has already
been done for you earlier in the code, so you can just reuse the same []jcha variable here:
The result is exactly as you see it on the stage.
Firing bullets in 360 degrees
The system you're using to fire bullets (or stars) is the same as the system you used in Dungeon Maze
Adventure. The Lh]uan class creates new instances of the >qhhap class. The only real difference is that
because you want the bullets to fire in 360 degrees, you need to supply the >qhhap class with extra
information as parameters. I also added a feature that lets the player fire star-shaped bullets, round
bullets, or squares.
Search Nedrilad ::

Custom Search