10#include "Component.hpp"
11#include "TextureComponent.hpp"
12#include "TransformComponent.hpp"
13#include "Collision2DComponent.hpp"
19struct GameEntity :
public std::enable_shared_from_this<GameEntity> {
36 virtual void Input(
float deltaTime);
43 virtual void Update(
float deltaTime);
50 virtual void Render(SDL_Renderer* renderer);
130 void AddTag(std::string tag) { mTags.push_back(tag); }
137 std::vector<std::string>
GetTags()
const {
return mTags; }
161 std::vector<std::string> mTags;
162 std::map<ComponentType, std::shared_ptr<Component>> mComponents;
163 bool mRenderable{
true};
164 std::function<void()> mOnStart =
nullptr;
165 std::function<void(
float)> mOnInput =
nullptr;
166 std::function<void(
float)> mOnUpdate =
nullptr;
GameEntity class that represents an entity in the game.
Definition GameEntity.hpp:19
GameEntity(const GameEntity &entity)
Copy constructor to create a new entity from an existing one.
void AddComponent(std::shared_ptr< T > component)
Add a component to the entity.
void OnStart()
Run when the entity is started.
bool HasComponent(ComponentType type)
Check if the entity has a component of a certain type.
void AddDefaultTransformComponent()
Add a default transform component to the entity.
void SetOnInput(std::function< void(float)> onInput)
Set the function to be called when the entity receives input.
std::shared_ptr< TransformComponent > GetTransform()
Get the transform component of the entity.
virtual void Input(float deltaTime)
Handle input.
virtual void Update(float deltaTime)
Update the entity.
void AddTag(std::string tag)
Add a tag to the entity for identification.
Definition GameEntity.hpp:130
std::shared_ptr< T > GetComponent(ComponentType type)
Get a component of a certain type.
void SetOnUpdate(std::function< void(float)> onUpdate)
Set the function to be called when the entity is updated.
bool IsRenderable() const
Check if the entity is renderable.
Definition GameEntity.hpp:108
void SetOnStart(std::function< void()> onStart)
Set the function to be called when the entity is started.
std::vector< std::string > GetTags() const
Get the tags of the entity.
Definition GameEntity.hpp:137
virtual void Render(SDL_Renderer *renderer)
Render the entity.
bool Intersects(std::shared_ptr< GameEntity > e)
Check if the entity intersects with another entity. Only checks for collision2D components.
void SetRenderable(bool value)
Set the renderable flag.
Definition GameEntity.hpp:97