Game Development Reference
In-Depth Information
Let's start with characteristics, which are things about an object that will not
change and which are thus represented using constants, variables that will not (cannot)
change. An important bagel characteristic is the type (flavor). We all have our favor-
ites; mine are plain, egg, rye, onion, and pumpernickel. Another characteristic is the
size of bagel; as we all know, there are minibagels, normal-size bagels, and giant ba-
gels.
private static final String FLAVOR_OF_BAGEL
= "Pumpernickel";
private static final String SIZE_OF_BAGEL = "Mini Bagel";
Thus, constants are used to define the characteristics, or attributes, of an object. If
you are defining a car, boat, or plane, the color (paint), engine (type), and transmission
(type) are attributes (constants), as they generally do not change, unless you are a
mechanic or own a body shop!
Things about an object that will change, such as its location, orientation, how it is
traveling (flying, driving, walking, running), and so on are called states and are defined
using variables, which can constantly change in real time, based on what is happening
in real life. These variables will allow any Java object to mimic, or virtualize, the real-
world object that they are creating in your Java universe's virtual reality. This is, of
course, especially true in games, which is why the topic of this topic, Java and games,
is especially relevant and applicable.
There will be more states (variables) than attributes (constants) for the InvinciBa-
gel, as it is the game piece and will be especially active trying to save its hole and score
points. Some of the states that you will want to define as variables include screen (x, y)
location, orientation, travel direction, travel type, hits taken, and life span used.
public int invinciBagelX = 0;
//
X screen location of the InvinciBagel
public int invinciBagelY = 0;
// Y
screen location of the InvinciBagel
public String bagelOrientation = "side";
//
Defines bagel orientation (front, side, top)
public int lifeIndex
= 1000;
//
Defines units of lifespan
used
public int hitsIndex = 0;
//
Defines units of damage (hits taken)
public String directionFacing
Search WWH ::




Custom Search