Game Development Reference
In-Depth Information
Types of Game Objects
Of the three primary types of game objects, those that are both updated and drawn
are the most apparent. Any character, creature, or otherwise movable object needs
to be updated during the “update game world” phase of the game loop and needs
to be drawn during the “generate outputs” phase. In Super Mario Bros ., Mario,
any enemies, and all of the dynamic blocks would be this type of game object.
Objects that are only drawn but not updated are sometimes called static objects .
These objects are those that are definitely visible to the player but never need to be
updated. An example of this type of object would be a building in the background
of a level. A building isn't going to get up and move or attack the player, but it
certainly needs to be drawn.
The third type of game object, those that are updated but not drawn, is less ap-
parent. One example is the camera. You technically can't see the camera (you can
see from the camera), but many games feature moving cameras. Another example
is what's known as a trigger . Many games are designed so that when the player
movestoacertainlocation,somethinghappens.Forexample,ahorrorgamemight
want to have zombies appear when the player approaches a door. The trigger is
what detects that the player is in position and triggers the appropriate action. So a
trigger is an invisible box that must be updated to check for the player. It shouldn't
be drawn (unless in debug mode) because it suspends disbelief for the gamer.
Game Objects in the Game Loop
To use game objects in the game loop, we first need to determine how to represent
them. As mentioned, there are several ways to do this. One such approach, which
uses the OOP concept of interfaces, is outlined in this section. Recall that an in-
terface is much like a contract; if a class implements a particular interface, it is
promising to implement all of the functions outlined in the interface.
First, we need to have a base game object class that all the three types of game
objects can inherit from:
Click here to view code image
class GameObject
// Member data/functions omitted
...
end
Search WWH ::




Custom Search