Game Development Reference
In-Depth Information
currCol
attributes and call the
updateTile
function of the enemy tank. We do this to each enemy
tank by looping through the
enemyTanks
array.
This is
not
a complete rewrite of the
update
function. You should add this code in the current
update
function under the existing section for the player rendering that we have already placed
into the function. Here are the additions to the
update
function that will handle enemy tanks:
//** added iteration #6
var enemyLength:int = enemyList.length-1;
for (var ctr:int = enemyLength; ctr >= 0; ctr--) {
tempEnemy = enemyList[ctr];
tempEnemy.nextX = tempEnemy.x + tempEnemy.dx*tempEnemy.moveSpeed;
tempEnemy.nextY = tempEnemy.y + tempEnemy.dy * tempEnemy.moveSpeed;
//check to see is enemy off side of screen then set in tunnel
if (tempEnemy.y <yMin || tempEnemy.y>yMax ||
tempEnemy.x<xMin || tempEnemy.x >xMax){
tempEnemy.inTunnel = true;
}else {
tempEnemy.inTunnel = false;
}
if (tempEnemy.inTunnel) {
switch(tempEnemy.currentDirection) {
case MOVE_UP:
if (tempEnemy.nextY == yTunnelMin){
tempEnemy.nextY=yTunnelMax
}else if (tempEnemy.nextY == yMax) {
tempEnemy.inTunnel = false;
}
break;
case MOVE_DOWN:
if (tempEnemy.nextY == yTunnelMax){
tempEnemy.nextY = yTunnelMin;
}else if (tempEnemy.nextY == yMin) {
tempEnemy.inTunnel = false;
}
break;
case MOVE_LEFT:
if (tempEnemy.nextX == xTunnelMin){
tempEnemy.nextX = xTunnelMax;
}else if (player.nextX == xMax) {
tempEnemy.inTunnel = false;
}
break;
case MOVE_RIGHT:
if (tempEnemy.nextX == xTunnelMax) {
tempEnemy.nextX = xTunnelMin;
}else if (player.nextX == xMin) {
tempEnemy.inTunnel = false;