HTML and CSS Reference
In-Depth Information
if (hDiff >0){
directionsToTest.push("left");
directionsToTest.push("right");
}else if (hDiff <0){
directionsToTest.push("right");
directionsToTest.push("left");
}
}else if (Math.abs(hDiff) < Math.abs(vDiff)) {
if (hDiff >0){
directionsToTest.push("left");
directionsToTest.push("right");
}else if (hDiff<0){
directionsToTest.push("right");
directionsToTest.push("left");
}else if (vDiff > 0){
directionsToTest.push("up");
directionsToTest.push("down");
}else if (vDiff <0){
directionsToTest.push("down");
directionsToTest.push("up");
}
}else if (Math.abs(hDiff) == Math.abs(vDiff)) {
//make an educated random guess
if (Math.floor(Math.random()*2)==0){
//try vertical first
if (vDiff >0){
directionsToTest.push("up");
directionsToTest.push("down");
}else if (vDiff<0){
directionsToTest.push("down");
directionsToTest.push("up");
}
}else{
//try vertical first
if (hDiff >0){
directionsToTest.push("left");
directionsToTest.push("right");
}else if (hDiff<0){
directionsToTest.push("right");
directionsToTest.push("left");
}
}
}
var chooseRandom = false;
var moveFound = false;
var movePtr = 0;
var move;
if (Math.floor(Math.random()*100)> chanceRandomEnemyMovement){
//not random movement
while(!moveFound){
move = directionsToTest[movePtr];
Search WWH ::




Custom Search