Game Development Reference
In-Depth Information
And here's the traced output:
rotation=30
carRadians=0.5235987755982988
Math.cos(carRadians)=0.8660254037844387
Math.sin(carRadians)=0.49999999999999994
dx=1.7320508075688774
dy=0.9999999999999999
There are some key things to note about this output.
First, Flash uses degrees to indicate angles on display objects, but we must first translate that
value to radians in order for it to be used in our calculations:
Radians = (rotation in degrees / 360) * (2 * pi)
So, for our example
Radians = 30/360 * (2 *pi)
Radians = .083 * (6.28)
Radians = .0.523
Next we find the vector for the x axis. If you remember from basic trigonometry (if you have had
the pleasure), the x axis and the cosine of the angle are closely related. The cosine of our angle
will be the magnitude in pixels on the x axis for our car to move. The dx value is going to be the
cosine of our radians multiplied by our velocity. When our car is moving with a velocity of 2 (in this
example), we get this calculation:
dx=cos(.523) * 2
dx=,866*2
dx=1.73;
Now, let's look at the dy vector. The axis and the sine of the angle are closely related. The sine of
our angle will be the magnitude in pixels our car will move in the y direction.
dy=sin(.523)*2
dy=.499 * 2
dy=0.999
To move our car at a 30-degree angle at a speed of 2 pixels, we would need to move 1.73 pixels
along the x axis and .999 pixels on the y axis.
Preparing to create our Drive She Said game
Our game will make use of the framework classes (with some modifications) and will use some
new custom classed that were mentioned earlier in the chapter.
No matter if you are using Flex, Flash Develop, Flash Builder, or the Flash IDE, you should create
a new project folder to hold all of the code for this game.
As with all of the games in this topic, Drive She Said will use the framework package structure we
created in Chapter 2. Let's begin by creating the package necessary for our game in both the
Flash IDE and Flash Develop (for use with the Flex SDK).
Search WWH ::




Custom Search