Game Development Reference
In-Depth Information
//trace("AI DOWN");
moveDirectionsToTest.push(MOVE_DOWN);
moveDirectionsToTest.push(MOVE_UP);
}
}else {
//horizontal
if (horizontalDiff >0) {
//trace("AI LEFT");
moveDirectionsToTest.push(MOVE_LEFT);
moveDirectionsToTest.push(MOVE_RIGHT);
}else if (horizontalDiff < 0) {
//trace("AI DOWN");
moveDirectionsToTest.push(MOVE_RIGHT);
moveDirectionsToTest.push(MOVE_LEFT);
}
}
}
if (horizontalDiff == 0 && verticalDiff == 0) {
//trace("AI STOP");
moveDirectionsToTest = [MOVE_STOP];
}
//as a final move for all, push in a MOVE_STOP
moveDirectionsToTest.push(MOVE_STOP);
//moveDirectionsToTest should now have a list of moves in it.
//loop though those, check them and set the dx and dy of the enemy.
var moveFound:Boolean = false;
var movePtr:int = 0;
var move:int;
while (!moveFound) {
move = moveDirectionsToTest[movePtr];
if (move==MOVE_UP && predator.inTunnel==false) {
if (checkTile(MOVE_UP, predator)) {
switchMovement(MOVE_UP, predator );
moveFound = true;
}
}
if (move==MOVE_DOWN && predator.inTunnel==false) {
//trace("player.currentDirection=" + player.currentDirection);
if (checkTile(MOVE_DOWN, predator)) {
switchMovement(MOVE_DOWN, predator );
Search WWH ::




Custom Search