CS4850 Final Project
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
GameEntity Struct Reference

GameEntity class that represents an entity in the game. More...

#include <GameEntity.hpp>

Inheritance diagram for GameEntity:

Public Member Functions

 GameEntity (const GameEntity &entity)
 Copy constructor to create a new entity from an existing one.
 
virtual void Input (float deltaTime)
 Handle input.
 
virtual void Update (float deltaTime)
 Update the entity.
 
virtual void Render (SDL_Renderer *renderer)
 Render the entity.
 
template<typename T >
void AddComponent (std::shared_ptr< T > component)
 Add a component to the entity.
 
bool HasComponent (ComponentType type)
 Check if the entity has a component of a certain type.
 
template<typename T >
std::shared_ptr< T > GetComponent (ComponentType type)
 Get a component of a certain type.
 
void AddDefaultTransformComponent ()
 Add a default transform component to the entity.
 
std::shared_ptr< TransformComponentGetTransform ()
 Get the transform component of the entity.
 
void SetRenderable (bool value)
 Set the renderable flag.
 
bool IsRenderable () const
 Check if the entity is renderable.
 
bool Intersects (std::shared_ptr< GameEntity > e)
 Check if the entity intersects with another entity. Only checks for collision2D components.
 
void OnStart ()
 Run when the entity is started.
 
void AddTag (std::string tag)
 Add a tag to the entity for identification.
 
std::vector< std::string > GetTags () const
 Get the tags of the entity.
 
void SetOnStart (std::function< void()> onStart)
 Set the function to be called when the entity is started.
 
void SetOnInput (std::function< void(float)> onInput)
 Set the function to be called when the entity receives input.
 
void SetOnUpdate (std::function< void(float)> onUpdate)
 Set the function to be called when the entity is updated.
 

Protected Attributes

std::vector< std::string > mTags
 
std::map< ComponentType, std::shared_ptr< Component > > mComponents
 
bool mRenderable {true}
 
std::function< void()> mOnStart = nullptr
 
std::function< void(float)> mOnInput = nullptr
 
std::function< void(float)> mOnUpdate = nullptr
 

Detailed Description

GameEntity class that represents an entity in the game.

Constructor & Destructor Documentation

◆ GameEntity()

GameEntity::GameEntity ( const GameEntity & entity)

Copy constructor to create a new entity from an existing one.

Parameters
entity

Member Function Documentation

◆ AddComponent()

template<typename T >
void GameEntity::AddComponent ( std::shared_ptr< T > component)

Add a component to the entity.

Parameters
componentComponent to add

◆ AddTag()

void GameEntity::AddTag ( std::string tag)
inline

Add a tag to the entity for identification.

Parameters
tagTag to add

◆ GetComponent()

template<typename T >
std::shared_ptr< T > GameEntity::GetComponent ( ComponentType type)

Get a component of a certain type.

Template Parameters
TType of the component
Parameters
typeComponent type
Returns
std::shared_ptr<T>

◆ GetTags()

std::vector< std::string > GameEntity::GetTags ( ) const
inline

Get the tags of the entity.

Returns
std::vector<std::string> Tags

◆ GetTransform()

std::shared_ptr< TransformComponent > GameEntity::GetTransform ( )

Get the transform component of the entity.

Returns
std::shared_ptr<TransformComponent> Transform component

◆ HasComponent()

bool GameEntity::HasComponent ( ComponentType type)

Check if the entity has a component of a certain type.

Parameters
typeComponent type
Returns
true
false

◆ Input()

virtual void GameEntity::Input ( float deltaTime)
virtual

Handle input.

Parameters
deltaTimeTime since last frame

◆ Intersects()

bool GameEntity::Intersects ( std::shared_ptr< GameEntity > e)

Check if the entity intersects with another entity. Only checks for collision2D components.

Parameters
eEntity to check
Returns
true if intersects
false if does not intersect

◆ IsRenderable()

bool GameEntity::IsRenderable ( ) const
inline

Check if the entity is renderable.

Returns
true if renderable
false if not renderable

◆ Render()

virtual void GameEntity::Render ( SDL_Renderer * renderer)
virtual

Render the entity.

Parameters
rendererSDL renderer

◆ SetOnInput()

void GameEntity::SetOnInput ( std::function< void(float)> onInput)

Set the function to be called when the entity receives input.

Parameters
onInput

◆ SetOnStart()

void GameEntity::SetOnStart ( std::function< void()> onStart)

Set the function to be called when the entity is started.

Parameters
onStart

◆ SetOnUpdate()

void GameEntity::SetOnUpdate ( std::function< void(float)> onUpdate)

Set the function to be called when the entity is updated.

Parameters
onUpdate

◆ SetRenderable()

void GameEntity::SetRenderable ( bool value)
inline

Set the renderable flag.

Parameters
valueValue to set

◆ Update()

virtual void GameEntity::Update ( float deltaTime)
virtual

Update the entity.

Parameters
deltaTimeTime since last frame

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