Game Development Reference
In-Depth Information
ct.greenMultiplier *= (_depth - j)/_depth;
ct.blueMultiplier *= (_depth - j)/_depth;
tempTile.transform.colorTransform = ct;
tileSet.push(tempTile);
}
_tunnelTiles.push(tileSet);
}
}
This method is at the heart of this class. We start by determin-
ing the height and width each tile will need to be for the sides to
meet all the way around the tunnel. We assume that the artwork
for each tile will dictate the height of the tile; in order to maintain
the illusion of depth, the pieces will ultimately be taller than they
are wide. To determine the width of each tile, we will need to refer
back to the trig functions discussed earlier in this chapter. Since we
are building our tunnel to have eight sides, we
'
ll use that as our
visual reference.
In Fig. 11.15 , note the white dashed line represents the virtual
circle that touches the center points of all the sides of the octagon.
The radius of this imaginary circle is the value passed into the tunnel
constructor. In order to find the value of angle A , we divide
(which
is half the angle value of a circle) by the number of sides. Since we
now know one angle and one side, the best trig function to use is
tangent . Recall from the earlier discussion in the chapter that
π
tan A
=
So, it follows that in order to find the value of the opposite side,
we rearrange the equation as follows:
Opposite
opp
=
×
tan A
A °
However, this will only give us half the width of a side, so we
need to multiply it by 2 as well; thus, the line will be as follows:
_tileWidth = (_radius * Math.tan(Math.PI/_sides)) * 2;
Before we start the loops that create the tiles, we need to know
the angle value of each side, so that we can place the tiles. This is
simply the entire angle of the circle (2
π
) in radians, divided by the
number of sides (eight).
A = π
/
8
(
number of sides
)
var angle:Number = (Math.PI * 2)/_sides;
Figure 11.15 We can break
the shape down into right
triangles in order to use trig
functions to determine the
missing values.
Nowthatwehavetheinformationweneedtoplacethetiles
around the center of the tunnel, we need to run through two loops
to create a multidimensional array. Each layer of eight tiles
comprises its own array, stored in a larger array.