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-14. After adding declarations at the top of the class, instantiate the objects, and add them to a Scene Graph<br />

Let’s take a moment and use a Run ➤ Project work process and see if our Treasure Actors are on the screen!<br />

As you can see in the left half of Figure 17-15, all Treasure objects are visible in the Scene, and we’re ready to start<br />

enhancing our .scoringEngine() method, to support negative scoring as well as add in Treasure scoring values.<br />

Figure 17-15. Check Treasure placement (left) and test negative collision values (right) and Treasure collision detection<br />

As you’ll soon see (and is seen on the right side of Figure 17-15), a <strong>Java</strong> int (integer) data type supports negative<br />

values, so all you have to do in your .scoringEngine() method is to change += to -= for Actor objects that you want<br />

the game player to avoid. In our development scenario here, we’ll use collision with Prop objects to give a<br />

negative score.<br />

www.it-ebooks.info<br />

405

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

Saved successfully!

Ooh no, something went wrong!