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-49. Add calls to loadBullet(), loadCheese() and loadEnemy() to end of “move Enemy offscreen” else structure<br />

Next, let’s add a unique twist to our game play, and have a Projectile object, in the form of a Cream Cheese Ball,<br />

that will generate positive points if the InvinciBagel is able to put himself in a position to get hit by it.<br />

Shooting Cream Cheese Balls: Different Bullet Types<br />

To accommodate different types of projectiles, we will need to declare a new boolean variable, which we will name<br />

bulletType, so that we can have deadly projectiles (iBullet) and healthy projectiles (iCheese). In the .update()<br />

method, right before you set callAttack equal to true to start the attack sequence, you will set this bulletType variable<br />

equal to the result of a call to the .nextBoolean() method made off of the randomNum Random object. The <strong>Java</strong> code,<br />

which is shown highlighted in Figure 17-50, should look like the following <strong>Java</strong> statements:<br />

boolean bulletType = false;<br />

bulletType = randomNum.nextBoolean();<br />

www.it-ebooks.info<br />

443

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

Saved successfully!

Ooh no, something went wrong!