Game Development Reference
In-Depth Information
}else {
difference = 0;
}
checkCol = predator.currCol;
checkRow = predator.currRow;
for (differenceCtr = 0; differenceCtr <= difference; differenceCtr++) {
checkCol += testDX;
checkRow += testDY;
if (checkCol < 0 || checkCol == mapColumnCount) {
break;
//trace("col hit border");
}else if (checkRow < 0 || checkRow == mapRowCount) {
break;
//trace("row hit border");
}else if (tileSheetData[levelTileMap[checkRow][checkCol]] == TILE_WALL) {
//trace("hit wall");
break;
}else if (checkCol == player.currCol && checkRow == player.currRow) {
//if predator is facing the player then fire
if (predator.rotation == testRotation) {
fireMissileAtPlayer(predator);
}
break;
}else {
//trace("hit nothing");
}
}
}
}
//** end added in iteration #6
These are the main points in the
checkLineOfSight
function:
1.
The
predator
and
prey
are passed in just as they are in the
chaseObject
function.
2.
If the
predator
and the
prey
are already in the same
region
, the local
act
variable is
set to
true
to force the later code to test line of sight.
3.
If the
predator
and
prey
are not in the same region, the
enemyIntel
value is used to
decide whether the
predator
object will test line of sight against the
prey
. The
act
variable is set to
true
if they share the same region or if the random generated value
is less than
enemyIntel
). Also, the
predator
is rotated toward the
prey
, so it looks
smart and the player can tell it is working.
4.
If
act
is true, we first check to see of the
predator
and
prey
are in the same column. If
so, we set the local
difference
variable to be the absolute value of the difference