Facing The Target
This function is purly for aesthetics.  Most people would consider it "necessary", but you know, your baddy does not have to look at his target, does it?
 
function Direction(){ 
  GetDist()
  if (this.distx<= this.disty){ 
    if (this.testy<y) dir=0; 
    if (this.testy>y) dir=2; 
  }else
    if (this.testx<x) dir=1; 
    if (this.testx>x) dir=3; 
  } 
}
The first thing this function does is call GetDist() .  This of course is so it knows its target's x y cords ( this.testx and this.testy) as well as the distance to the target.  Then what it does from there is compare the x and y distances.  If the x distance (this.distx ) is less than the y distance (this.disty), then it will check to see if the target is above or below the baddy; depending on which is true, the dir will be set appropriately. But if in the first place this.distx is greater than this.disty it goes to the else statement to determine if the target is to the left or right of the baddy, and sets its dir accordingly.
This function ought to be called anytime you want your baddy to look at, or face its target.  So if it were about to use a sword attack, if you did not have another function before it that calls the Direction() function, you may want to add this in so that the baddy will actually face its target when it swings its sword.
 
Previous Topic         Home           Next Topic