Shooting the Arrow
This function will pause the NPC for a little bit, make it shoot an arrow in the direction it is facing, pause for a little more, then send it on its way.

function ShootBow(){
if (this.shoot<10)this.shoot ++;
else {
   this.shoot =0;
   this.mode =0;
}
if (this.shoot ==5){
   shootarrow dir;
   sprite =0;
}
}

If this function has been called, then the archer has decided that it is ok to shoot an arrow, or it already has shot the arrow and is just waiting a second from the recoil. The first if and else statements are what pause the NPC. When this.shoot is equal to 10, then the NPC will be done firing, that is why this.shoot is reset to 0, and this.mode is also put back to 0. So if it is less than 10, the NPC is not done yet, so this.shoot needs 1 added to it. I made it so that when this.shoot is equal to 5, the actual arrow is shot, and the NPCs sprite is returned to 0. Since this occurs within the Control Loop, when 5 counts have gone by it will have been .25 seconds. 10 clicks is .5 seconds. So if you want the archer to be paused for greater or shorter periods of time adjust these values.

This function needs to be called within the Control Loop when the NPC's mode is set to shoot an arrow.

Previous Topic         Home         Next Topic