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

Figure 8-11. Add the @Override public abstract void .update() and public boolean .collide(Actor object) methods<br />

Next, let’s add another eleven variables into this Hero class. These will hold data values that apply to motion<br />

sprites, which have to deal with colliding with things, and obey the laws of physics. We will also need things such as a<br />

lifespan variable, and one that holds the accumulation of damage (points), which may be incurred if enemies shoot<br />

at each other. We’ll add protected variables such as X and Y velocity, X and Y offset (for fine-tuning positioning<br />

of things relative to a sprite), and collision shape rotation and scaling factors, and finally, friction, gravity, and<br />

bounce factors.<br />

Adding Sprite Control and Definition Variables to the Hero Class<br />

The next thing that we need to do is to make sure that all of the variables that we will need to hold data for motion<br />

sprites are defined at the top of the Hero class, as seen in Figure 8-12. This information will be used by NetBeans to<br />

create getter and setter methods for the Hero class. The <strong>Java</strong> code should look like this:<br />

protected double vX;<br />

protected double vY;<br />

protected double lifeSpan;<br />

protected double damage;<br />

protected double offsetX;<br />

protected double offsetY;<br />

protected double boundScale;<br />

protected double boundRot;<br />

protected double friction;<br />

protected double gravity;<br />

protected double bounce;<br />

www.it-ebooks.info<br />

179

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

Saved successfully!

Ooh no, something went wrong!