Game Development Reference
In-Depth Information
for (var j:int = 0; j < _depth; j++) {
var tileSet:Array = new Array();
for (var i:int = 0; i < _sides; i++) {
}
_tunnelTiles.push(tileSet);
}
Each time the outer loop runs, a new tile set is created that the inner
loop will fill. That tile set is then added to the larger _tunnelTiles array.
tempTile = new TunnelTile();
tempTile.width = _tileWidth;
Intheinnerloop,wecreateanewTunnelTileobjectandsetits
width to the predetermined value. Next, we need to position it
around the center point. We can once again break a side down
into right triangles. We know that the hypotenuse to be the value
of the radius and the angle is the value between the center points
of any two connecting sides, as shown in Fig. 11.16 .
tempTile.x = Math.cos(i*angle) * _radius;
tempTile.y = Math.sin(i*angle) * _radius;
tempTile.z=j*_tileHeight;
re dealing with,
from0to7.Wemultiplythe i valuebytheangleassociatedwith
eachsideandusethe sine and cosine functions to position x and y
coordinates of the tile. We then use the current depth level,
represented by j to position the tiles down the z-axis .Nowthetileis
positioned, but it would still appear to be a flat shape on the Stage.
We must rotate it in 3D space.
The value of i is the current side of the tunnel we
'
tempTile.rotationX = 90;
tempTile.rotationZ = i * Math.round(radiansToDegrees(angle)) + 90;
We rotate the tile along its x-axis to turn it parallel to the tunnel;
one end of the tile will now appear closer than the other. Next, we
rotate it along the z-axis so that each tile faces the center of the
tunnel. We convert the angle from radians to degrees (using a func-
tion we
Opposite
A °
Adjacent
hypotenuse
ll cover momentarily) and add 90. This is to compensate for
having rotated the tile along its x-axis already; without it, the tiles will
align perfectly perpendicular to the Stage and will disappear from
view. Now the tile is ready to use.
'
tileSet.push(tempTile);
addChild(tempTile);
Hypotenuse = radius
We add the tile to the tileSet array (which will get added to
_tunnelTiles) and then to the display list. If we were to stop here,
the tunnel would work just fine, but there
Figure 11.16 We know the
value of the hypotenuse and
the angle between each side.
'
s no real sense of depth,
Search Nedrilad ::




Custom Search