Game Development Reference
In-Depth Information
Name the class Bagel and accept the other default Project, Location, Package and
Created File option fields, by clicking on the Finish button, which will create the new
Bagel.java class, and open it up in a tab in NetBeans.
Figure 10-12 . Use the New Java Class dialog and create the Bagel.java class in the invincibagel package
The first thing that you will want to do is to add the Java extends keyword to the
end of your public class Bagel {...} class declaration statement that
NetBeans wrote for you, so that your Bagel class inherits all of the power (variables
and methods) from the Hero class that we created back in Chapter 8 . The Java code for
this currently empty class should look like the following:
package invincibagel;
public class Bagel extends Hero {
// an empty class structure
}
The first thing that we will want to write is the Bagel() constructor method, since
we want to create a Bagel character to place onto the screen so that we can start to
work on movement code, and later collision code. This code will take in the same exact
parameters that the Hero class Hero() constructor method needs to receive, and will
pass them “up” to the Hero class Hero() constructor using the Java super keyword (I
like to call this a super constructor ) in the form of a super() constructor method call.
 
Search WWH ::




Custom Search