Game Development Reference
In-Depth Information
Figure 8-11
.
Add the @Override public abstract void .update() and public boolean .collide(Actor object) methods
Next, let's add another eleven variables into this Hero class. These will hold data
values that apply to motion sprites, which have to deal with colliding with things, and
obey the laws of physics. We will also need things such as a
lifespan
variable, and one
that holds the accumulation of
damage
(points), which may be incurred if enemies
shoot at each other. We'll add protected variables such as X and Y
velocity
, X and Y
offset
(for fine-tuning positioning of things relative to a sprite),
and
collision shape
ro-
tation
and
scaling
factors, and finally,
friction
,
gravity,
and
bounce
factors.
Adding Sprite Control and Definition Variables to the
Hero Class
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 sprites are defined at the top of the Hero class, as seen in
Figure 8-12
.
This information will be used by NetBeans to create getter and setter
methods for the Hero class. The Java code should look like this:
protected double
vX
;
protected double
vY
;
protected double
lifeSpan
;
protected double
damage
;
protected double
offsetX
;
protected double
offsetY
;
protected double
boundScale
;
protected double
boundRot
;