Movemenet of an Archer
This function
controls how the archer moves. It also checks for when to make an attack.
function
Movement(){ sprite=(sprite%8)+1; GetDist(); TakingAim(); if (this.dist<=this.keepdist) Retreat (); if ( this.distx<=1||this.disty<=1){ this.mode =1; Direction(); setcharani shoot.gani,wbow1.png; } if ( this.dist<=this.closedist ){ this.mode =2; sprite =9; } |
The very first part of this function is the sprite control I explained earlier. Next GetDist() is called because the rest of the function needs to read the values found from it, this.distx, this.disty, and this.dist. Then TakingAim() is called to move the archer towards a worthy shot from its bow. Next, if the distance between the NPC and its target, this.dist, is less than the distance the NPC is trying to keep, this.keepdist, then the baddy is to be in a state of Retreat(). Next, if the horizontal distance, this.distx, between the NPC and its target is less than 1, or if the vertical distance, this.disty, is less than 1, then that means the archer and its target are realatively aligned, and so the baddy is to shoot its bow. To do that, I have designated a this.mode of 1 to mean the bow is to be shot; at the same time Direction() is called so the bow is shot the correct way, then the gani is set. The very last if statement for this function checks to see if the distance between the archer and its target is less than the distance specified by this.closedist in the Initialize() function, then the NPC is too close to its target to use the bow, so it will use its sword. Thus putting the NPC in this.mode of 2 and a sprite of 9 can begin the sword attack. |
This function is to be called within the
Control Loop in order to control all the actions of the archer.
Previous Topic Home Next Topic