28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Figure 17-45. Add a launchIt flag to the if(onScreen) condition to make that code structure wait for the pauseCounter<br />

For the if(takeSides) version of this if(onScreen && launchIt) structure, make sure to change the destination to<br />

-70, make the counter if(spriteMoveL >= destination) and the counter update spriteMoveL-=1; and the takeSides<br />

equal to false in the else portion of this conditional structure. Next, let’s update our scoring engine in the Bagel class.<br />

Update the .scoringEngine( ) Method: Using .equals( )<br />

Let’s use a different approach for these last three object scoring else-if structures, and instead of using an if(object<br />

instanceof Actor) for more general object type comparisons, we will use the more precise .equals() method that<br />

allows us to specify the object itself, such as if(object.equals(invinciBagel.iBullet). You can see the complete if-else<br />

structure in Figure 17-46, and the <strong>Java</strong> code for the last three Enemy objects looks like the following:<br />

} else if(object.equals(invinciBagel.iBullet)) {<br />

invinciBagel.gameScore-=5;<br />

invinciBagel.playiSound5;<br />

www.it-ebooks.info<br />

437

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

Saved successfully!

Ooh no, something went wrong!