Game Development Reference
In-Depth Information
Entities
This 2D game demo we created only has one entity in it (the player character). In
game development, the term entity refers to an object that can interact with the game
world or other objects in the game world. An entity would typically be implemented as
a class. So, we would create a class to represent our player object. In this demo, our
player object was very simple and had no methods in it, so we just made it a struct
instead. In a real-game engine, you might have an Entity base class that all oth-
er entity classes would inherit from. This base class would define methods such as
Update() and Draw() so that every entity has them. Each entity class would then
override them to provide its own custom update and draw code.
Asinglelevelorgameworldcanhavehundredsofentitiesinit,sohowdowemanage
them? One way is to create an EntityManager class that simply holds the collec-
tion of entities that are in the currently loaded level or world. The EntityManager
class will have an Update() method and a Draw() method. The Update() method
would, of course, get called once per frame by the UpdateScene() method of our
game window class. Likewise, the Draw() method would be called once per frame
by the RenderScene() method. The entity manager's Update() method would iter-
ate through all of the entities and call each one's Update() method so that the entity
can update itself. And of course, the entity manager's Draw() method would do the
same thing, but instead it would call each entity's Draw() method so that the entity
can draw itself.
In some games, entities are able to communicate with each other via a messaging
system of sorts. A good example of this is the inputs and outputs system used in
Half-Life 2 . For example, there is a button on a wall next to a door. We will set
up an output on the button that fires when the button is pressed. We will connect it to
the input on the door that makes the door open. So, basically, when the output of the
button fires, it activates the specified input on the door. In short, the button sends a
message to the door telling it to open. The output of one object can potentially send
parameters to its target input as well. The big benefit here is that many interactions
between objects can be handled like this and don't need to be specifically coded as a
result, but instead can simply be set up in the game's level editor.
Search WWH ::




Custom Search