Game Development Reference
In-Depth Information
Figure 8-10 . Create a public abstract class Hero extends Actor and add a constructor method and a super() con-
structor
Adding Update and Collision Methods: .update() and
.collide()
Now that we have a basic constructor method, which we'll be adding to a bit later, let's
add the required abstract .update() method, as well as a .collide() method, as motion
sprites are moving, and therefore can collide with things! First let's add in the public
abstract void .update(); method, as it is required by our Actor superclass.
Doing this essentially passes down (or up, if you prefer) the implementation require-
ment for this .update() method, from Actor superclass to Hero subclass, and on to any
future subclasses of Hero (which will make Hero into a superclass, and more reflective
of its name). Future non-abstract (functioning) classes will implement this .update()
method, which will be utilized to do all the heavy lifting for the game programming lo-
gic. As you can see in Figure 8-11 , motion sprites (Hero subclasses) will also need to
have a collision detection method, which I will call .collide() , as that is a shorter name,
and that, at least for now, will remain unimplemented except for returning a boolean
false (no collision here, Boss!) boolean data value. Your Java code for the .collide()
method structure will take an Actor object as its parameter, since that is what your
Hero object will be colliding with, and should look like the following:
public boolean collide ( Actor object ) {
return false ;
}
 
 
Search WWH ::




Custom Search