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 />

Powering the Enemy .update( ) Method: Using the GamePlayLoop .handle( ) Method<br />

Before we can start to test the code inside the Enemy.java class .update() method, we must “wire it up” to the<br />

.handle() method in the GamePlayLoop.java class. As you know, this method is our doorway into the <strong>Java</strong>FX<br />

pulse timing event processing engine that drives our game at a lightning fast 60 FPS. Now our GamePlayLoop<br />

.handle() method will be updating both an iBagel InvinciBagel character as well as the iBeagle Enemy auto-attack<br />

programming logic. It is easy to see why InvinciBagel and InvinciBeagle are enemies; it’s an identity crisis of sorts,<br />

kind of like one of those misspelled domain name disputes! Your <strong>Java</strong> code, seen error-free in Figure 17-34, will look<br />

like the following:<br />

@Override<br />

public void handle(long now) {<br />

invinciBagel.iBagel.update();<br />

invinciBagel.iBeagel.update();<br />

}<br />

Figure 17-34. Add a call to the invinciBagel.iBeagle.update() method inside of the GamePlayLoop .handle() method<br />

Use the Run ➤ Project work process to test your first round (level) of Enemy auto-attack <strong>Java</strong> code. As you can<br />

see in Figure 17-35, the InvinciBeagle appears on both sides of the screen, in random locations along the Y axis, and<br />

alternates between the left side of the screen and the right side of the screen. I left the Bullet and Cream Cheese<br />

Ball Projectile Actor objects visible on the screen for now, in the upper-left corner. We will eventually place these<br />

off-screen, and will shoot them at the InvinciBagel every few seconds using the InvinciBeagle’s powerful bazooka.<br />

www.it-ebooks.info<br />

423

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

Saved successfully!

Ooh no, something went wrong!