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

and for this version of the game, having one .collide() method to process per pulse allows us to optimize the game<br />

play processing, while still having a game with the different game features that an arcade game would include. As you<br />

can see in the Enemy() constructor method, the Enemy character isAlive, isBonus, and hasValue, and so all of these<br />

properties or characteristics of the Enemy will be set to a boolean value of true inside of the constructor method, after<br />

the sprite location has been set using .setTranslateX() and .setTranslateY(), and after the SVG data, Image, and initial<br />

X,Y location data is passed up to the Actor() constructor using the super() constructor. The <strong>Java</strong> code for the Enemy.<br />

java class can be seen error-free in Figure 17-18, and should look like the following <strong>Java</strong> class structure:<br />

package invincibagel;<br />

import javafx.scene.image.Image;<br />

public class Enemy extends Actor {<br />

public Enemy(String SVGdata, double xLocation, double yLocation, Image... spriteCels) {<br />

super(SVGdata, xLocation, yLocation, spriteCels);<br />

spriteFrame.setTranslateX(xLocation);<br />

spriteFrame.setTranslateY(yLocation);<br />

isAlive = true;<br />

isBonus = true;<br />

hasValu = true;<br />

}<br />

@Override<br />

public void update() {<br />

// Currently Empty Method<br />

}<br />

}<br />

Figure 17-18. Create an Enemy.java class, override the .update() method, and code your Enemy() constructor method<br />

408<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!