Game Development Reference
In-Depth Information
}
break;
case MOVE_STOP:
//trace("stopped");
break;
}
}
tempEnemy.currRow = tempEnemy.nextY / tileWidth;
tempEnemy.currCol = tempEnemy.nextX / tileHeight;
tempEnemy.updateCurrentTile();
}
//** end added iteration #6
Remember that this code needs to be added to the existing update function. We have not shown
the final close bracket ( } ) to finish off the function because it is already in the existing code.
As you can see, the code to update the enemy and move them through tunnels is identical to the
code for the player.
Here are the additions to the render function that will handle enemy tanks. The render function
code for the enemy tanks is very similar to the render function code for the player. The biggest
difference is the inclusion of two function calls that perform artificial intelligence operations for the
enemy tanks. These two calls are chaseObject and the checkLineOfSight functions. Add this
code to the pre-existing render function under the code for the player render logic:
//** added in iteration #6
var enemyLength:int = enemyList.length-1;
for (var ctr:int = enemyLength; ctr >= 0; ctr--) {
tempEnemy = enemyList[ctr];
tempEnemy.x = tempEnemy.nextX;
tempEnemy.y = tempEnemy.nextY;
setCurrentRegion(tempEnemy);
if (checkCenterTile(tempEnemy)) {
//trace("enemy @ center tile");
if (!tempEnemy.inTunnel) {
switchMovement(MOVE_STOP, tempEnemy);
chaseObject(player, tempEnemy);
}
}
//should enemy fire
checkLineOfSight(player, tempEnemy);
tempEnemy.renderCurrentTile();
}
//** end added in iteration #6
Again, we have not shown the final } for the function, because it should already exist in the code.
Search WWH ::




Custom Search