SDL Minigame  1.0
Loading...
Searching...
No Matches
Entity Class Reference

Main class for any object in game, stores associations, labeling and components. More...

#include <Entity.h>

Public Types

enum class  GroupLabel {
  MAPTILES , PLAYERS , ENEMIES , COLLIDERS ,
  PROJECTILE , HEARTS , POWERUPS
}
 Used for rendering order (last is highest) or retrieving entities of group. More...
 
enum class  TeamLabel { NONE , BLUE , RED }
 Allows grouping entities by team association for hits, win conditions, etc. More...
 

Public Member Functions

 Entity (Manager &mManager)
 
void update () const
 
void draw () const
 
bool isActive () const
 
void destroy ()
 
bool hasGroup (Group mGroup)
 
void addGroup (Group mGroup)
 
void delGroup (Group mGroup)
 
std::bitset< MAX_GROUPS > getGroupBitSet ()
 
void setTeam (TeamLabel teamLabel)
 
TeamLabel getTeam ()
 
ManagergetManager ()
 
template<typename T >
bool hasComponent () const
 
template<typename T , typename... TArgs>
T & addComponent (TArgs &&...mArgs)
 Adds specified type as component and calls Component::init()
 
template<typename T >
T & getComponent () const
 

Detailed Description

Main class for any object in game, stores associations, labeling and components.

The entity class is the primary class each object in the game needs to use. Add components to assign functionality.

Todo

More detailed description

Some functions in entity class are only supposed to be called in specific context, which might be valid uses for friend keyword. Example: Entity() should only be called from Manager::addEntity(). Verify each functions intended use/scope.

Member Enumeration Documentation

◆ GroupLabel

Used for rendering order (last is highest) or retrieving entities of group.

Todo

Label used in singular entity shouldn't use plural

HEARTS are rendered above POWERUPS, missleading order

PROJECTILE are rendered above POWERUPS, missleading order

Generalize HEARTS as UI or similar

Enumerator
MAPTILES 

Entity using TileComponent.

PLAYERS 

Primary entity in player controll.

ENEMIES 
Deprecated
All players now grouped as Entity::PLAYERS
COLLIDERS 

Fixed collider entity, e.g. a wall.

PROJECTILE 
Todo
Document
HEARTS 
Todo
Document
POWERUPS 
Todo
Document

◆ TeamLabel

Allows grouping entities by team association for hits, win conditions, etc.

Enumerator
NONE 

No team, should be skipped in any checks.

BLUE 

Team blue.

RED 

Team red.

Constructor & Destructor Documentation

◆ Entity()

Entity::Entity ( Manager & mManager)
inlineexplicit
Todo
Document

Member Function Documentation

◆ addComponent()

template<typename T , typename... TArgs>
T & Entity::addComponent ( TArgs &&... mArgs)
inline

Adds specified type as component and calls Component::init()

Parameters
mArgsConstructor arguments of component

◆ addGroup()

void Entity::addGroup ( Group mGroup)
See also
GroupLabel

◆ delGroup()

void Entity::delGroup ( Group mGroup)
See also
GroupLabel

◆ destroy()

void Entity::destroy ( )
inline

Mark for destruction for Manager::refresh() and disables collision

See also
ColliderComponent

◆ draw()

void Entity::draw ( ) const

Call after update to render components.

See also
SpriteComponent::draw()

◆ getComponent()

template<typename T >
T & Entity::getComponent ( ) const
inline
Returns
Component of type T

◆ getGroupBitSet()

std::bitset< MAX_GROUPS > Entity::getGroupBitSet ( )
Returns
bitset with true on position GroupLabel if the entity belongs to group
See also
GroupLabel

◆ getManager()

Manager & Entity::getManager ( )
inline
See also
Manager

◆ getTeam()

Entity::TeamLabel Entity::getTeam ( )
See also
TeamLabel

◆ hasComponent()

template<typename T >
bool Entity::hasComponent ( ) const
inline
See also
Component

◆ hasGroup()

bool Entity::hasGroup ( Group mGroup)
See also
GroupLabel

◆ isActive()

bool Entity::isActive ( ) const
inline
See also
destroy()

◆ setTeam()

void Entity::setTeam ( Entity::TeamLabel teamLabel)
See also
TeamLabel

◆ update()

void Entity::update ( ) const

Call each frame to update all components


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