Game Development Reference
In-Depth Information
Optimizing the Hero Class Via Compound Statements
and Default Variable Values
I am going to do two major things to reduce the amount of code in this primary portion
of the Hero class, before we have NetBeans write our getter and setter methods for us.
The first is to use compound declaration for all of our similar data types, declaring the
protected double and protected float modifiers and keywords first, and then listing all
of the variables after those, separated by commas, which is called “comma delimited”
in programming terms. The Java code for the eleven Hero class variable declarations
will now look like the following:
protected double vX, vY, lifeSpan, damage, offsetX,
offsetY;
protected float boundScale, boundRot, friction, gravity,
bounce;
As you can see in Figures 8-13 and 8-14 , we did the same type of compound state-
ment for the initializations:
lifeSpan = 1000;
vX = vY = damage = offsetX = offsetY = 0;
boundScale = boundRot = friction = gravity = bounce = 0;
 
 
Search WWH ::




Custom Search