184
Video Game Design Foundations
language syntax. An exclamation point has different meaning than a question
mark. Capital letters also have special meaning in English language syntax.
Capital letters denote proper nouns or the start of a sentence. Syntax for
computer languages use symbols such as punctuation and capital letters just as
is done with the syntax for the English language.
Syntax for computer languages creates objects the same way the English
language uses nouns. Definition subroutines are called objects.
Objects
are
defined by their attributes and properties.
Attributes
are characteristics associated with an object. A ball with the
attribute red would be a red ball, as shown in Figure 5-14. An attribute makes
an object unique from others of the same type. Properties define the size,
shape, movement, and use of an object. The properties of a ball would be a
three-inch diameter sphere, five percent friction decrease, a weight 20 grams,
the maximum speed of ten, and so on.
Actions
are how an object reacts to input or interacts with other objects.
The actions of a ball would be to bounce against walls, accelerate when
thrown, arc toward gravity, move left when the left arrow button is pressed,
and so on. Attributes and properties are written in the object subroutine and
allow the computer to draw the correct object and determine how that object is
affected by the game environment.
Other subroutines are called methods.
Methods
are the actions or verbs
used in syntax. A
JUMP
method will execute instructions contained in the
JUMP
subroutine. The instructions would tell you how to bend your knees and
quickly snap them straight so your feet leave the ground.
Some symbols are used as operational syntax. Most of the mathematical
symbols, such as +,–,, , and parentheses, work just as they do in math
class. These symbols will add, subtract, and compare values. In a line of
computer code these symbols can also work like words.
Fruit = apples + bananas + grapes
In this example, the words and operational syntax form a sentence. This sentence
is also a formula to find the total number of fruit. Each word is also a variable.
Figure 5-14.
The attributes for
an object must be
programmed in a
video game.
Goodheart-Willcox Publisher; image: rook76/Shutterstock.com