either of those will work just as well, ThuGie. Although, AJ, I would use else ifs to end it if anything is found
Code:
public void getNextNPCMovement(NPC n) {
if (n == null) {
return;
}
else if (n.moveX == 0 && n.moveY == 0) {
return;
}
else if(n.freezeTimer > 0){
return;
}
int dir = direction(n.absX, n.absY, (n.absX + n.moveX), (n.absY + n.moveY));
else if (dir == -1) {
return;
}
n.updateReq = true;
dir >>= 1;
n.direction = dir;
n.absX += n.moveX;
n.absY += n.moveY;
}
this is much more efficient code. if you have else if, it will only check those if the above if was false. Without the else, it will check all the ifs, regardless of a return statement( I think, not 100% positive on that). Thugie's method is also efficient on accomplishing the else if stuff without the madness
Edit:
To respond to AJ's post, you can avoid the looping by adding one else statement to go with the first if statement.
Code:
ublic void getNextNPCMovement(NPC n) {
if (n != null ) { //First check if n isnt null since else it will error when checking.
if (n.moveX != 0 && n.moveY != 0 && n.freezeTimer <= 0) { //Check if x/y isnt 0, And npc isnt frozen.
int dir = direction(n.absX, n.absY, (n.absX + n.moveX), (n.absY + n.moveY)); //Get npc direction.
if (dir != -1) { //If dir isnt -1 update npc location.
n.updateReq = true;
dir >>= 1;
n.direction = dir;
n.absX += n.moveX;
n.absY += n.moveY;
}
}
}
else
return;
}