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

Figure 8-12. Add eleven variables at the top of Hero class defining velocity, lifespan, damage, physics, collision<br />

Before we add all 22 of your getter and setter methods, which would be 11 .get() and 11 .set() methods, to match<br />

our new Hero class variables, let’s go back and finish our Hero() constructor method, and initialize these eleven<br />

variables that we just added at the top of the Hero class.<br />

Initializing the Sprite Control and Definition Variables in the Hero Constructor<br />

Let’s give our Hero Actor objects (motion sprites) a lifespan of 1000 units, and set the other variables to zero, which<br />

you can see that I have done using compound initialization statements to save eight lines of code. As you can see in<br />

Figure 8-13, the code is error free, and the <strong>Java</strong> programming statements should take the following format:<br />

lifespan = 1000;<br />

vX = vY = damage = offsetX = offsetY = 0;<br />

boundScale = boundRot = friction = gravity = bounce = 0;<br />

180<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!