Game Development Reference
In-Depth Information
protected double
friction
;
protected double
gravity
;
protected double
bounce
;
Figure 8-12
.
Add eleven variables at the top of Hero class defining velocity, lifespan, damage, physics, collision
Before we add all
22
of your getter and setter methods, which would be 11 .get()
and 11 .set() methods, to match our new Hero class variables, let's go back and finish
our
Hero()
constructor method, and initialize these eleven variables that we just added
at the top of the Hero class.
InitializingtheSpriteControlandDefinitionVariablesin
the Hero Constructor
Let's give our Hero Actor objects (motion sprites) a lifespan of 1000 units, and set the
other variables to zero, which you can see that I have done using compound initializa-
tion statements to save eight lines of code. As you can see in
Figure 8-13
,
the code is
error free, and the Java programming statements should take the following format: