Game Development Reference
In-Depth Information
Each of these getter functionsprovideseasyaccesstovarious
properties of the tunnel without making them writeable. One could
argue that the tunnelTiles getter should return a copy of the tunnel
array, not the original, but since you would also have to copy all
the arrays inside it as well, it is not a very efficient way to manage
the list. It is better to just be mindful that any edits made to
the tunnelTiles list could break the tunnel
s functionality of
public function highlightSide(angle:Number):void {
if (angle < 0) angle = Math.PI*2 + angle;
var index:int = Math.round((angle * _sides)/(Math.PI * 2));
if (_highlightIndex == index) return;
for (var i:int = 0; i < _tunnelTiles.length; i++) {
if (_highlightIndex
= 0) _tunnelTiles[i]
_highlightIndex = index;
The final method in the Tunnel class is one that will be of
particular use to the Game class. It allows an entire side (from
the top to the bottom) to be highlighted or
This will be
useful if we need to point out which side the player is currently
on or if we need to notify the player of an enemy on a particular
side. It accepts an angle as a parameter to match with its corre-
sponding side. If the angle is negative, we convert it to its positive
equivalent by adding 2
lit up.
). Once we know the correct side,
and if it is not already highlighted, we loop through the list from
top to bottom to call the activate method of each tile and the
deactivate method of any tiles that are previously highlighted.
Afterwards, we set the value of _highlightIndex to the currently
selected side for reference later. Let
(or 360
s look at the entire class now
in context:
package tunnelshooter {
import flash.display.Sprite;
import flash.geom.ColorTransform;
public class Tunnel extends Sprite {
protected var _radius:Number;
protected var _sides:int, _depth:int;
protected var _tileWidth:Number, _tileHeight:Number;
protected var _tunnelTiles:Array;
Search Nedrilad ::

Custom Search