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. |
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}. |