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-31. Add an if-else structure inside of the initiateAttack() method, to alternate between the left and right sides<br />

Inside the if(takeSides){} structure set the Enemy object (which we named iBeagle in the InvinciBagel class) to<br />

an X location of 500, by using spriteFrame.setTranslateX(500); and to a random height on the screen, using a<br />

spriteFrame.setTranslateY() method call in conjunction with the random number generator object we<br />

installed in the previous section of the chapter. If you type in your randomNum object name and then hit the<br />

period key, you will be presented with a number of method call options, which is shown in Figure 17-32.<br />

Double-click the nextInt(int bound) option, and insert that method call off of the randomNum object inside the<br />

.setTranslateY() method.<br />

420<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!