Game Development Reference
In-Depth Information
lifespan = 1000 ;
vX = vY = damage = offsetX = offsetY = 0 ;
boundScale = boundRot = friction = gravity = bounce = 0 ;
Figure 8-13 . Add initialization for your eleven variables inside of your constructor method using compound state-
ments
Before we generate our getter and setter methods, let's take a look at how we can
use a combination of compound variable declaration statements and the knowledge of
what default variable type values Java will set for our variables if we do not explicitly
specify them to reduce the amount of code that it takes to write the entire Hero class
from its 25 lines of code (or 33 if we didn't use compound variable initialization state-
ments) to 14 lines of code.
If you don't count lines of code with one curly brace on them (three) we are talking
less than a dozen lines of Java statements, including package, class and import declara-
tions, to code this entire public abstract class. This is pretty impressive, given how
much motion sprite power and capabilities the core class gives us. Of course, after we
add the 22 getter and setter methods, which are 3 lines of code each, we will have
about 80 lines of total code, sans spacing. It is important to note that NetBeans will be
writing more than 75% of this class's code for us! Pretty cool.
 
Search WWH ::




Custom Search