Game Development Reference
In-Depth Information
able equal to the result of a call to the .nextBoolean() method made off of the ran-
domNum Random object. The Java code, which is shown highlighted in
Figure 17-50
,
should look like the following Java statements:
boolean
bulletType
= false;
bulletType
= randomNum.nextBoolean();
Figure 17-50
.
Add a boolean bulletType variable at top of the Enemy class, then set it equal to .nextBoolean() method
To implement this boolean bulletType flag, we will need to convert your
if(!takeSides)
evaluator to be an
if(!bulletType
&&
!takeSides)
evaluator, so that both
the side of the screen and bullet-type boolean flags are taken into consideration. The
new conditional if() structures, seen in
Figure 17-51
, should look like the following
Java code:
if(
!bulletType
&&
!takeSides
) {
invinciBagel.
iBullet
.spriteFrame.setTranslateY(randomOffset);
invinciBagel.
iBullet
.spriteFrame.setScaleX(-0.5);
invinciBagel.
iBullet
.spriteFrame.setScaleY(0.5);
bulletRange = -50;
if(bulletOffset >= bulletRange) {
bulletOffset-=4;