Game Development Reference
In-Depth Information
Figure 17-28 . Declare and instantiate a Random Number Generator at the top of the Enemy.java class using Ran-
dom()
We will be using this Random (number generator) object throughout the remainder
of this chapter to add random attack positions, sides, and bullets for our Enemy iBeagle
object, so that he can try his best to take down the InvinciBagel character (the game
player), or at least cause him to generate lots of negative scoring points if he can!
Mounting the Attack: Coding the Enemy
Onslaught
First we need to declare counter variables , seen highlighted in Figure 17-29 , using the
following two Java statements:
int attackCounter = 0;
int attackFrequency = 250;
Figure 17-29 . Add integer variables at the top of the Enemy.java class; set attackCounter=0, and attackFre-
quency=250
Now we are ready to start to put a half dozen fairly complicated methods into place
in the Enemy.java class. These will use the GamePlayLoop class's .handle() method,
to tap into the JavaFX 60 FPS pulse timing event engine, to drive a fully automated,
 
 
Search WWH ::




Custom Search