Game Development Reference
In-Depth Information
protected function movePlayer():void {
var mouseAngle:Number = Math.atan2(mouseY, mouseX);
var roundedAngle:Number = _angleIncrement * Math.round
_player.x = _tunnel.radius * Math.cos(roundedAngle);
_player.y = _tunnel.radius * Math.sin(roundedAngle);
var oldRotation:Number = _player.rotation;
_player.rotation = roundedAngle * (180/Math.PI) + 180;
if (oldRotation != _player.rotation) _tunnel.highlight
When startGame is called, the Timer object is started to create
new enemies, and a frame script is attached to the enterFrame
event. This frameScript method simply calls movePlayer ,which
reads the position of the mouse around the center of the tunnel and
adjusts the Player
s x and y positions accordingly to stay along the
outside edge. It also rotates the Player so it is always pointing inward
toward the tunnel. If the player moves to a new side, that side of the
tunnel is highlighted using the methods we looked at earlier.
protected function addEnemy(e:TimerEvent):void {
var index:int = Math.round(Math.random()*(_tunnel.sides-1));
var enemy:Enemy = new Enemy(index);
enemy.x = _tunnel.tunnelTiles[0][index].x;
enemy.y = _tunnel.tunnelTiles[0][index].y;
enemy.z = _tunnel.tunnelTiles[_tunnel.depth-1][index].z;
enemy.rotation = index * (360/_tunnel.sides) - 180;
enemy.brightness = .5;
addChildAt(enemy, getChildIndex(_player));
_enemyList[enemy] = enemy;
var tween:TweenLite =, _enemyTime,
{z:0, brightness:1, ease:Quad.easeIn, onComplete:
enemyMovementFinished, onCompleteParams:[enemy]});
protected function enemyMovementFinished(target:Enemy):void {
delete _enemyList[target];
The addEnemy function picks a side at random, creates a new
enemy object, and positions it on that side, at the bottom of the
tunnel. It also sets the enemy to start out at half brightness, so
it will be visible, but blend in much more with the tiles. Once
the enemy is added, a new tween is created using TweenLite (dis-
cussed in Chapter 7), which will animate the enemy from bottom
to top over the time we specified earlier. Once the tween is
Search Nedrilad ::

Custom Search