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 10 ■ Directing the Cast of Actors: Creating a Casting Director Engine and Creating the Bagel Actor Class<br />

Figure 10-12. Use the New <strong>Java</strong> Class dialog and create the Bagel.java class in the invincibagel package<br />

The first thing that you will want to do is to add the <strong>Java</strong> extends keyword to the end of your public class Bagel<br />

{...} class declaration statement that NetBeans wrote for you, so that your Bagel class inherits all of the power<br />

(variables and methods) from the Hero class that we created back in Chapter 8. The <strong>Java</strong> code for this currently empty<br />

class should look like the following:<br />

package invincibagel;<br />

public class Bagel extends Hero {<br />

// an empty class structure<br />

}<br />

The first thing that we will want to write is the Bagel() constructor method, since we want to create a Bagel<br />

character to place onto the screen so that we can start to work on movement code, and later collision code. This code<br />

will take in the same exact parameters that the Hero class Hero() constructor method needs to receive, and will pass<br />

them “up” to the Hero class Hero() constructor using the <strong>Java</strong> super keyword (I like to call this a super constructor)<br />

in the form of a super() constructor method call. Your <strong>Java</strong> code for this Bagel() constructor method should look just<br />

like the following <strong>Java</strong> class and constructor method structure:<br />

public class Bagel extends Hero {<br />

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

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

}<br />

}<br />

As you can see in Figure 10-13, there is a wavy red error underline highlight, under the Bagel class name. If you<br />

mouse-over this you will see the “Bagel is not abstract and does not override abstract method .update() in Hero,”<br />

which tells you that you either need to make Bagel a public abstract class, which we are not going to do because we<br />

wish to actually use this class to hold a character (object) and its attributes (variables) and capabilities (methods), so<br />

the other option to eliminate this error is to add in your @Override public void update() {...} method structure,<br />

even if it is an empty method for now.<br />

224<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!