Game Development Reference
In-Depth Information
This is just the tip of the iceberg in how to store actors. I could probably write an
entire book on the subject! The simple STL map solution we use here makes for a
good starting point, but just keep in mind that you
ll have some work to do when
you start thinking about taking this engine to the next level and making a real game.
'
Putting It All Together
Now that you
ve seen how actors are built up with components and you understand
the definitions for the Actor and ActorComponent classes, it
'
s time to see how it
all works together with a simple example showing you how to implement a simple
component for different kinds of pickups in the game. First, we need to define the
pickup interface that all pickups will derive from.
'
class PickupInterface : public ActorComponent
{
public:
const static ComponentId COMPONENT_ID; // unique ID for this component type
virtual ComponentId VGetComponentId(void) const
{
return COMPONENT_ID;
}
// Pickup interface
virtual void VApply(WeakActorPtr pActor) = 0;
};
At the top is the ID that must be unique for all component interfaces, as well as the
override for the VGetComponentId() function. This is the bare-minimum require-
ment for all components. Then the pickup interface itself is defined with declaring
the VApply() pure virtual function. All pickup implementations must override and
define this function.
Now let ' s write the actual implementation classes. This example will use an ammo
pickup and a health pickup.
class AmmoPickup : public PickupInterface
{
public:
virtual bool VInit(TiXmlElement* pData);
virtual void VApply(WeakActorPtr pActor);
};
class HealthPickup : public PickupInterface
{
 
 
Search WWH ::




Custom Search