Game Development Reference
In-Depth Information
callAttack boolean variable to a true value, so that the next time that the
if(!callAttack) conditional if-else structure is called, the else portion at the bottom of
the structure will execute and will call an initiateAttack() method. This method is
where the real heavy lifting is done, as far as animating the iBeagle Enemy character
onto the screen, having him pause and fire off a shot, and then retreat off-screen be-
fore the InvinciBagel can execute (collide with) him, gaining ten valuable scoring
points.
The else part of this if-else programming structure will call the initiateAttack()
function, once the callAttack variable has been set to a true value inside of the attack-
Counter timer section of your conditional programming logic.
Once your conditional if() timer logic has expired (completed its countdown), your
Enemy sprite is randomly positioned along the Y axis, moved into its starting position
using the spriteMoveR and spriteMoveL variables, and the attackCounter is reset to
zero for the next time the callAttack variable is set to false. At the end of the “set-up
initiate attack” sequence of Java statements, callAttack is set equal to true , as seen in
Figure 17-36 , using the following code:
public void update() {
if( !callAttack ) {
if(attackCounter >= attackFrequency) {
attackCounter = 0 ;
spriteFrame.setTranslateY(randomNum. nextInt (attackBoundary));
spriteMoveR = 700 ;
spriteMoveL = -70 ;
callAttack = true ;
} else { attackCounter+=1; }
} else { initiateAttack() ; }
}
Next we're going to rewrite our if(takeSides) logic structure to remove the Y axis
random number positioning statements, reposition the takeSides boolean flag program
logic, and add an if(!onScreen) nested structure, around a .setTranslateX() method call.
This will allow us to animate the iBeagle Enemy Actor sprite on and off of the screen.
Inside of the if(!takeSides) structure, you'll keep the first two statements that set
the sprite mirroring (facing direction), but remove the .setTranslateY() method call as
that is now accomplished in the .update() method. Add the if(!onScreen) conditional
structure, where you'll initialize the destination location to 500 pixels, and then nest
another counter if(spriteMoveR >= destination) structure, inside of which you'll
Search WWH ::




Custom Search