28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 17 ■ Enhancing Game Play: Creating a Scoring Engine, Adding Treasure and an Enemy Auto-Attack Engine<br />

Figure 17-50. Add a boolean bulletType variable at top of the Enemy class, then set it equal to .nextBoolean() method<br />

To implement this boolean bulletType flag, we will need to convert your if(!takeSides) evaluator to be an<br />

if(!bulletType && !takeSides) evaluator, so that both the side of the screen and bullet-type boolean flags are taken<br />

into consideration. The new conditional if() structures, seen in Figure 17-51, should look like the following <strong>Java</strong> code:<br />

if(!bulletType && !takeSides) {<br />

invinciBagel.iBullet.spriteFrame.setTranslateY(randomOffset);<br />

invinciBagel.iBullet.spriteFrame.setScaleX(-0.5);<br />

invinciBagel.iBullet.spriteFrame.setScaleY(0.5);<br />

bulletRange = -50;<br />

if(bulletOffset >= bulletRange) {<br />

bulletOffset-=4;<br />

invinciBagel.iBullet.spriteFrame.setTranslateX(bulletOffset);<br />

} else { shootBullet = false; }<br />

}<br />

if(!bulletType && takeSides) {<br />

invinciBagel.iBullet.spriteFrame.setTranslateY(randomOffset);<br />

invinciBagel.iBullet.spriteFrame.setScaleX(0.5);<br />

invinciBagel.iBullet.spriteFrame.setScaleY(0.5);<br />

bulletRange = 624;<br />

if(bulletOffset

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!