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 8 ■ Creating Your Actor Engine: Design the Characters for Your Game and Define Their Capabilities<br />

Initializing Sprite Control and Definition Variables in an Actor Constructor Method<br />

For now we are going to initialize our pivot point pX and pY to 0 (the upper left corner origin) and all of our Boolean<br />

flags to a value of false except for the isFixed variable, which for a fixed sprite will always be set to a value of true. We will<br />

do this using the following eight lines of <strong>Java</strong> code inside of the current Actor() constructor method and underneath<br />

the initial four lines of code in the method that deal with configuring the Actor object using the method parameters:<br />

pX = 0;<br />

pY = 0;<br />

isAlive = false;<br />

isFixed = true;<br />

isBonus = false;<br />

hasValu = false;<br />

isFlipV = false;<br />

isFlipH = false;<br />

We could also do this using compound initialization statements. This would reduce the code to three lines:<br />

px = pY = 0;<br />

isFixed = true;<br />

isAlive = isBonus = hasValu = isFlipV = isFlipH = false;<br />

As you can see in Figure 8-8 we have now coded nearly three dozen lines of error-free <strong>Java</strong> 8 code, and we are<br />

ready to create the rest of the .get() and .set() methods that will make up the public abstract Actor superclass.<br />

Figure 8-8. Add initialization values to the eight new fixed sprite pivot and state definition variables you just declared<br />

www.it-ebooks.info<br />

173

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

Saved successfully!

Ooh no, something went wrong!