Simple C++ Game
Classes | Public Member Functions | List of all members
Entity Class Reference

An entity in the game's component entity system. More...

#include <Entity.hpp>

Classes

class  Component
 A component of an entity in the game's component entity system. More...
 

Public Member Functions

 Entity ()
 Construct a new Entity with a random ID.
 
 Entity (int id)
 Construct a new Entity object with a specific ID. More...
 
int getId () const
 Get the ID of the Entity. More...
 
void add (const std::shared_ptr< Component > &component)
 Adds the provided component to the entity. More...
 
bool hasComponent (const std::string id) const
 Check if the Entity has a component of the specified type. More...
 
std::shared_ptr< ComponentgetComponent (const std::string id) const
 Get the Component object. More...
 

Detailed Description

An entity in the game's component entity system.

The Entity represents a collection of attributes, called Components, that together are acted upon by EntitySystem objects that form a complete game world.

Constructor & Destructor Documentation

◆ Entity()

Entity::Entity ( int  id)

Construct a new Entity object with a specific ID.

Parameters
idThe ID of the Entity

Member Function Documentation

◆ add()

void Entity::add ( const std::shared_ptr< Component > &  component)

Adds the provided component to the entity.

The entity will create a new std::shared_ptr pointing to the Component using the copy constructor that will stay in scope with the entity.

Parameters
componentThe Component to add to this Entity.

◆ getComponent()

std::shared_ptr<Component> Entity::getComponent ( const std::string  id) const

Get the Component object.

Parameters
id
Returns
std::shared_ptr<Component>

◆ getId()

int Entity::getId ( ) const

Get the ID of the Entity.

Returns
int the entity's ID

◆ hasComponent()

bool Entity::hasComponent ( const std::string  id) const

Check if the Entity has a component of the specified type.

Parameters
idThe ID of the Component type.
Returns
true if the Entity has a component of the specified type.
false if the Entnity doeso not have a component of the specified type.

The documentation for this class was generated from the following file: