Game Development Reference
In-Depth Information
Figure 17-41
.
Add randomLocation, randomOffset, bulletRange, and bulletOffset variables to control bullet place-
ment
Also notice, at the bottom of
Figure 17-41
, we've also added an
if(shootBullet){shootProjectile();}
conditional if structure to the bot-
tom of the .update() method, as well as adding a
boolean shootBullet =
false;
declaration at the top of the Enemy.java class. Before we code the .shootPro-
jectile() method, let's add the shootBullet flag settings to the .initiateAttack() method,
as well as setting a
bulletOffset
X location for the bullet, in
if(!onScreen)
.
Invoking a .shootProjectile() Method: Setting
shootBullet to True
Inside each of the if(takeSides) conditional if-else structures, in the else portion of the
statement, add a bulletOffset variable setting (
480
or
120
) and set
shootBullet
equal to
true
. The Java code, seen in
Figure 17-42
, will look like this:
if(takeSides) {
spriteFrame.setScaleX(1);
this.setIsFlipH(false);