186
Video Game Design Foundations
Floats
refer to the floating decimal point that must be accounted for in
any decimal computation. The computer has to remember the position of the
decimal in the number calculation as well as doing the actual math. Floats can be
expressed using decimal notation (1. 0234, –36.7, 15.15, and so on) or scientific
notation (10 × e–16, 3.14 × e2, and so on). Scientific notation does not record the
non-significant digits of a number. As a decimal number extends past the decimal
point the value of those digits become less and less significant. Even extremely
exact measurements do not require more than a few digits after the decimal
point. Scientific notation includes the significant digits and then tells where to
place the decimal. Non-significant digits would be replaced with zero.
Variables can also store text. Text stored in a variable is called a
string.
A
string is a series of letters, numbers, or punctuation. The computer will not
try to interpret a string. It will only remember the order of the characters of a
string. A string is most often identified with quotation marks or quotes. “Hello
World”, “8746 Main Street”, “Applesauce!” or anything else set in quotes would
be a string. Strings are often used as labels in spreadsheets and databases or as
dialog in a video game.
Variables can contain formulas. In the world of mathematics, variables are
common. In the expression:
Y = mX + B
all of the values have been replaced with variables. The variable Y stores a
formula. Inside this formula, the variables m, X, and B can have a value that
changes.
At the root of the term variable is the idea a variable is something that
can be changed or changes as a result of other information. In a mathematical
formula, variables have letters or symbols that can make them hard to
remember. In the example Y = mX + B, the user would need to remember that
m is the slope and B is the Y axis intercept.
In programming, a variable name is not limited to letters and old Greek
symbols. Variable names should describe the information stored. These are
more like nicknames for the information inside. A variable with the name
strGreeting
might store the string, “Good morning, how are you today?” A
program may contain over 1000 variables. It is therefore important to give each
variable a name that is unique and helps describe the contents.
Variables can also contain symbols. Using a symbol to represent a
variable is common with mathematics and programming. A symbol can be
representational or abstract. A representational symbol might be something like
this or (produce by keying -- or --) to represent direction or vector.
Vector is a physics term that means direction. An avatar in the game moves
at a speed of 10. The vector of right, left, up, down, and so on determines
what direction the avatar is moving. Other symbols are abstract such as the pi
symbol (π) or dollar sign ($). These symbols have meaning only because they
are assigned meaning in a program. A $ in formula in an Excel spreadsheet is
used to lock an absolute cell reference and has nothing to do with currency.
Notice how a variable can change an action with the example shown in
Figure 5-16. Variables here will control the amount or direction of a property
that can be changed. In the statement “Jump 10 feet,” 10 is a variable.
Previous Page Next Page