Game Development Reference
In-Depth Information
lifeIndex of 900 units of life and no hits on its life, would be facing West , and would
not be currently moving.
You can have as many (overloaded) constructor methods as you like, so long as
they are each 100 percent unique. This means that overloaded constructors must have
different parameter list configurations, including parameter list length (the number of
parameters) and parameter list types (order of data types). As you can see, it is the
parameter list (length, data types, order) that allows a Java compiler to differentiate
overloaded methods from one another.
Java Variables and Constants: Values in
Data Fields
The next level down (progressing from API, to package, to class, to method, to the ac-
tual data values that are being operated on in Java classes and methods) is the data
field . Data values are held inside something called a variable ; if you fix, or make per-
manent, the data, it is called a constant . A constant is a special type of variable (which
I will cover in the next section), because declaring a constant correctly is a bit more in-
volved (advanced) than declaring a Java variable.
In the Java lingo, variables declared at the top of a class are called member vari-
ables , fields , or data fields , although all variables and constants can be considered data
fields, at a fundamental level. A variable declared inside a method or other lower-level
Java programming structure declared inside a class or method, is called a local vari-
able , because it can only be seen locally, inside the programming constructs delimited
by curly braces. Finally, variables declared inside a parameter list area of a method de-
claration or method call are, not surprisingly, called parameters .
A variable is a data field that holds an attribute of your Java object or software
that can (and will) change over the course of time. As you might imagine, this is espe-
cially important for game programming. The simplest form of variable declaration can
be achieved by using a Java data type keyword , along with the name that you want to
use for the variable in your Java program logic. In the previous section, using the con-
structor method, you declared an integer variable named hitsIndex to hold the damage,
or hits, that your InvinciBagel object will sustain during game play. You defined the
variable data type, and named it, using the following Java variable declaration pro-
gramming statement:
Search WWH ::




Custom Search