The Control Loop
This is THE timeout loop to control everything your baddy does.
Assuming you visited my other pages, and read about my other functions, this will tie everything together to make a complete baddy.
 
if (timeout){ 
  if (this.mode==0){ 
    Movement()
    AttackCheck()
  }else if (this.mode==1) SwordAttack()
  if (hearts>0) timeout=.05; 
}
Right off, this will not even work unless the timeout has already been set for this baddy.  Usually this will occur in your Initialize() function.  First, the statement checks to see what the mode of the baddy is.  If the mode is 0, then it is not doing anything (just because I have designated it that way, you can make it whatever you want.)  so if this.mode is equal to 0, then the statement will first call the Movement() function (which of course houses all the targeting stuff and what not), then it will call the AttackCheck() function (to see if the baddy can attack yet).  BUT, if this.mode is equal to 1 (which I have designated to be this baddy's sword attack) then it will call the function SwordAttack() .  Of course once SwordAttack() is done executing, then this.mode is automatically set back to 0, so it can begin moving again.  The very last part of the Control Loop checks to see if the baddy is still alive (if it wasn't then it would have less than or equal to 0 hearts ), and if the baddy is still alive, it re-initializes the timeout var so the whole thing can begin again.
This just needs to be put in the main body of your script.  Hell, it IS your script.
 
Next I will show you a control loop using some of the optional stuff I spoke about.  I'm not gonna explain the entire thing again though.
 
if (timeout){ 
  if (this.mode==0){ 
    Movement(); 
    AttackCheck(); 
    RadialHitDetection()
  }else if (this.mode==1)SwordAttack();  
  if (hearts>0) timeout=.05; 
  else SpinMove();  
}
The first difference here is the inclusion of the RadialHitDetection() function.  I threw it in right there because I wanted to make that if anything touched my baddy physically, it would be hurt. 
The other difference is the inclusion of a single else statement.  This states that if there are no more hearts left (the baddy has died) then it is to do the SpinMove() function {which is your typical dying animation; and houses the Reward() function}.
Not a whole lot different, but does include a few optional things.
 
Previous Topic          Home           Next Topic