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

Figure 17-39. Add a <strong>Java</strong> this keyword inside the Enemy() constructor method call to pass over the InvinciBagel object<br />

For this to work, you need to also update your Enemy.java class to accommodate the InvinciBagel object. Add<br />

an InvinciBagel invinciBagel; object declaration, at the top of the Enemy.java class, and edit your Enemy()<br />

constructor method to support this object by adding an InvinciBagel iBagel parameter at the head end (beginning)<br />

of the parameter list definition. Inside of the Enemy() constructor method, set the invinciBagel InvinciBagel object<br />

equal to the iBagel InvinciBagel object reference passed into the Enemy() constructor method in its parameter list.<br />

The <strong>Java</strong> code for the amended Enemy() constructor method body is shown in Figure 17-40, and should look like the<br />

following:<br />

InvinciBagel invinciBagel;<br />

public Enemy( InvinciBagel iBagel,<br />

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

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

invinciBagel = iBagel;<br />

spriteFrame.setTranslateX(xLocation);<br />

spriteFrame.setTranslateY(yLocation);<br />

isAlive = true;<br />

isBonus = true;<br />

hasValu = true;<br />

}<br />

430<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!