Dana Vrajitoru
B583 Game Programming and Design
Arcade Games and General Concepts
2D Arcade Games
- The name of "arcade" games comes
from the coin-operated machines.
- A discrete world, iconic characters, multiple levels of rapidly
increasing difficulty.
- Simple animation techniques, limited storyline, easy learning
curve.
- Focus on the player's skills, mostly speed of reaction.
- It usually takes place on a 2D table or arena with integer
coordinates (discrete world).
- The table can be organized in cells containing a whole object, or
objects can expand over several cells of the table.
- The game is composed of several entities (objects or characters)
interacting with each other and the player.
- The game has a goal and a score. The game can sometimes be lost.
Game Objects
- The entities composing a game.
- Can be active, decorative, or interface objects. They usually have
properties that allow for their manipulation.
- Active objects are those that make the game happen. They
are often animated and they react to events.
- There can be static active objects, like maze walls.
- Decorative objects are sometimes called Graphic (Flash) or
Backdrop objects. They don't interfere with the game.
- They can even be animated if the game is ambitious - billboard,
background movie, etc.
- Interface objects must be explicitly added like any other
game object in some packages.
Active Game Objects
- There are several characters in the game with independent
behavior.
- The characters must also interact with each other and their
actions have global consequences.
- Certain actions in the game may generate new characters or delete
existing characters.
- The player is represented by a special character. They can have
several lives which can be lost / gained by actions in the game.
World Representation
- 3 types of world representation: implicit, explicit, and by zone.
- Environment . description/representation of the world in which the
game takes place.
- It has a spatial, dimensional, measurable quality.
- The 3 categories are based on how the interacting objects are
present in the environment representation, and the other way around.
Implicit World
- Example: Space Invaders, 2D Shooter games.
- The "environment" itself has no knowledge of the characters
involved. It is just a repository of non-interacting game components.
- An interactive object has no way of selecting the objects it might
interact with.
- We have to test all of them.
- It works for a low character density.
Explicit World
- Example: Tetris, PacMan, Bejeweled.
- Most of the interacting objects are explicitly part of the
environment.
- By knowing the exact position of a player in the environment, we
can select the objects present at that spot or in nearby cases.
- It reduces the need to test for object interaction to a minimum.
- The world representation is much heavier. Good for high character
density, small world.
Zone-Based World
- The environment is structured in geographical (spatial) zones or
subdivisions.
- Each zone contains a list of references to the objects present in
it.
- Any active object in the game has knowledge of the zone they are
in.
- We only need to test the interaction of the character with objects
in the zone, or in adjacent zones (if close enough to the border).
- A compromise solution often observed in complex games.
Animation Type
- State of the game: position of all the objects, internal
properties (phase), background color/theme.
- The animation is defined by any change in the state of the game,
and is composed of frames or cycles.
- Simplest form, reactive or iterative games: changes
happen only when the user does something (puzzle).
- Continuous animation: when characters in the game have a
continuous behavior, such that changes happen even in the absence of
user input.
- Distributed animation: when the behavior of each character in the
game is controlled by a different thread in the program.
Game Loop
- The essential component of any game.
- Usually similar to the classic GUI loop.
- For continuous animation the loop needs a periodic update (timed
repeated function call). In OpenGL: glutIdleFunc or glutTimerFunc.
- For distributed animation, objects run their own independent loop.
- If several objects are animated with their own timer, the overall
game timer must be the GCD of all the object timers.
Event Loop
Simple Action / Reaction
- Examples: hangman, mines, puzzles, some card games (Golf).
- Includes some games with a player avatar like Gold Digger.
Select 1 Object
Most card games (select card, move to another stack), jigsaw puzzles,
sudoku.
Select Multiple Objects
- The main action in the game requires two or more objects. They
need to be identified and stored between user actions.
- All the matching games: memory, Mahjong, GemSwap.
- All the token move games: chess, Othello, backgammon.
Animated Game Loops
- For all the games where the state changes periodically even
without user interaction.
- The system is a collection of objects/critters/sprites with
behavior defined by rules expressed in the function update or move.
- The state of the system is the set of values/attributes for each
object at a given time.
- One or more timers cause the move functions to be called.
Timing in a Game
- Frames per second (fps): the number of times per second that the
graphics display can be updated.
- Cycles per second (cps): the number of times per second that the
game updates itself.
- Physics engine time step: a constant (dt) representing the lapse
of time used by the physics engine in the game to compute the next
state of the game.
- 1/dt <= fps <= cps.
Generic Game Loop
game_loop()
{
while (not exit)
{
for (1/(cps * dt) times)
physics.update();
updateUserInput();
for (all the characters in the game)
character.update();
checkSolveInteractions();
redisplay();
playSound();
restartTimer(1/cps);
}
}
Multi-Threaded Loops
- An independent thread can update the physics engine. Then the
physics and game engines each have their own loop.
- Physics update:
- Object update: position, velocity, acceleration;
- Object interactions: collisions and consequences.
- Other game update:
- Object update: other non-physical attributes (is open/close, is
active, color, power, size, etc.).
- Object interactions: related to behavior and game mechanics: hit
each other, eat, kill, move, use, pick up, dialogs, etc.
- Action consequences can affect each other.
Character Interaction
- Question: how do we detect that a couple of objects came close
enough to interact?
- Answer: depends on the representation of the game world.
- First step: identify the two objects that may interact.
- Second step: test if they are close enough to interact (collision
detection).
Collision Detection
- Complex problem. It depends on the object representation.
- Much reduced if the objects have a bounding box or sphere.
- A point P intersects a sphere S(C, r) if
d(P, c) <= r
- A box intersects a sphere if any of its corners does (this is a
sufficient but not necessary condition).
- Two spheres S(C1, r1) and S(C2, r2) intersect if
d(C1, C2) <= r 1 + r 2
Intervals
- Two real intervals, (a,b) and (c,d) intersect, if either a < c < b,
or c < a < d.
( (a <= c && c <= b) || (c <= a && a <= d))
- If we don't know that a<b and c<d, we can write
( (c-a) * (c-b) <= 0 || (a-c) * (a-d) <= 0)
Intersecting Boxes
Two boxes intersect if they intersect in all dimensions.
Point and Triangle
- If the equation of AB is y = m x + n, then P(xp,
yp) is on the same side of AB as C(xc,
xc) if
(m xp + n - yp) * (m
xc + n - yc) >= 0
- P is inside the triangle if it's
on the same side of AB as C,
onthe same side of AC as B, and
on the same side of BA as A.
Two Triangles
You need to check for both:
- a vertex from one triangle being inside the other triangle (a and
b);
- an edge from the first triangle intersecting one from the second
(b and c).
Collision Detection in Unity
A Rigidbody2D has two collision detection modes:
- Discrete - when the body moves, only collisions at the new
position are detected.
- Continuous - all intermediate collisions are detected when
the body moves.
A Rigidbody (3D) has 3 collision detection modes:
- Discrete - Continuous collision detection is off.
- Continuous - Continuous collision detection for colliding
with static mesh geometry.
- ContinuousDynamic - Continuous collision detection for
colliding with static and dynamic geometry.