Building Game Engines
GameObject Class Reference

Base class for all entities in scenes. More...

#include <GameObject.h>

Inheritance diagram for GameObject:
Inheritance graph
Collaboration diagram for GameObject:
Collaboration graph

Public Member Functions

 GameObject ()
 Constructor. More...
 
 ~GameObject ()
 Destructor. More...
 
virtual void processInput (SDL_Event e)
 Virtual method. Process user input. More...
 
virtual void Update (int x, int y, int *params)
 Update the position of something. More...
 
virtual void Render (SDL_Renderer *ren)
 Render the gameobject to the active viewport. More...
 
void removeComponent (std::string key)
 Remove a component in this gameobject. More...
 
void addComponent (std::string key, Component *component)
 Add a component in this gameobject. More...
 
ComponentgetComponent (std::string key)
 Get an reference of a component. More...
 
void setActive (bool newState)
 activate / deactivate game object. inactive object won't be updated and rendered More...
 
bool isActive ()
 Get the state of the game. More...
 
int getID ()
 Get the unique id of the gameobject. More...
 

Static Public Attributes

static int idCounter = 0
 

Protected Attributes

std::map< std::string, Component * > m_components
 Store all the game components in a map. More...
 
bool objState
 deactivated objects won't get updated/rendered More...
 
int id
 the unique id More...
 

Detailed Description

Base class for all entities in scenes.

Constructor & Destructor Documentation

◆ GameObject()

GameObject::GameObject ( )
inline

Constructor.

◆ ~GameObject()

GameObject::~GameObject ( )
inline

Destructor.

Member Function Documentation

◆ addComponent()

void GameObject::addComponent ( std::string  key,
Component component 
)
inline

Add a component in this gameobject.

Parameters
keyThe name of the component.
componentThe reference of the component.

◆ getComponent()

Component* GameObject::getComponent ( std::string  key)
inline

Get an reference of a component.

Parameters
keyThe name of the component.

◆ getID()

int GameObject::getID ( )
inline

Get the unique id of the gameobject.

◆ isActive()

bool GameObject::isActive ( )
inline

Get the state of the game.

◆ processInput()

virtual void GameObject::processInput ( SDL_Event  e)
inlinevirtual

Virtual method. Process user input.

Parameters
eA SDL_Event that contains structures for the different event types.

Reimplemented in TileMapEditor, Player, Menu, and EnemyObject.

◆ removeComponent()

void GameObject::removeComponent ( std::string  key)
inline

Remove a component in this gameobject.

Parameters
keyThe name of the component.

◆ Render()

virtual void GameObject::Render ( SDL_Renderer *  ren)
inlinevirtual

Render the gameobject to the active viewport.

Parameters
renReference to SDL renderer.

Reimplemented in TileMapEditor, Player, Menu, Map, and EnemyObject.

◆ setActive()

void GameObject::setActive ( bool  newState)
inline

activate / deactivate game object. inactive object won't be updated and rendered

◆ Update()

virtual void GameObject::Update ( int  x,
int  y,
int *  params 
)
inlinevirtual

Update the position of something.

Parameters
xThe x location of something.
yThe x location of something.
paramsAn int array stores additional data.

Reimplemented in TileMapEditor, Player, Menu, Map, and EnemyObject.

Member Data Documentation

◆ id

int GameObject::id
protected

the unique id

◆ idCounter

int GameObject::idCounter = 0
static

◆ m_components

std::map<std:: string, Component*> GameObject::m_components
protected

Store all the game components in a map.

◆ objState

bool GameObject::objState
protected

deactivated objects won't get updated/rendered