My Project
|
The GameEntity class serves as a base class for all entities in the game, providing basic functionalities like input handling, updating, and rendering. More...
#include <GameEntity.h>
Public Member Functions | |
GameEntity ()=default | |
Default constructor for GameEntity. | |
virtual | ~GameEntity () |
Virtual destructor for GameEntity. | |
virtual void | Input (float deltaTime) |
Handles input for the entity. | |
virtual void | Update (float deltaTime) |
Updates the entity and its components. | |
virtual void | Render (SDL_Renderer *renderer) |
Renders the entity and its components. | |
void | SetRenderable (bool value) |
Sets the entity's renderable state. | |
bool | IsRenderable () const |
Checks if the entity is renderable. | |
template<typename T , typename... Args> | |
T * | AddComponent (Args &&...args) |
Adds a component to the entity. | |
template<typename T > | |
T * | GetComponent () |
Retrieves the first component of type T. | |
template<typename T > | |
const T * | GetComponent () const |
Retrieves the first component of type T, const version. | |
bool | Intersects (const GameEntity *e) const |
Checks if the entity intersects with another entity. | |
SDL_Rect | ConvertFRectToRect (const SDL_FRect &frect) const |
Converts an SDL_FRect to SDL_Rect by casting float values to ints. | |
Protected Attributes | |
std::vector< std::shared_ptr< Component > > | components |
bool | mRenderable {true} |
The GameEntity class serves as a base class for all entities in the game, providing basic functionalities like input handling, updating, and rendering.
This class is designed to be extended by specific entities in the game. It holds a collection of components that define the entity's behavior and state. The class supports adding, retrieving, and updating components.
|
inline |
Adds a component to the entity.
args | Arguments to pass to the component's constructor. |
This method creates a component of type T, adds it to the entity's component list, and returns a pointer to it.
Converts an SDL_FRect to SDL_Rect by casting float values to ints.
frect | The floating point rectangle to convert. |
Utility method for converting between SDL rectangle types.
Retrieves the first component of type T.
This method searches for a component of type T in the entity's component list and returns a pointer to it.
Retrieves the first component of type T, const version.
This method searches for a component of type T in the entity's component list and returns a const pointer to it.
Handles input for the entity.
deltaTime | The time since the last update. |
This method is meant to be overridden by derived classes to handle specific input actions.
Reimplemented in BackGroundGameEntity, EnemyGameEntity, FoodGameEntity, GroundGameEntity, and PlayerGameEntity.
|
inline |
Checks if the entity intersects with another entity.
e | The other entity to check intersection with. |
This method checks if the bounding rectangles of the sprite components of two entities intersect.
|
inline |
Checks if the entity is renderable.
|
inlinevirtual |
Renders the entity and its components.
renderer | The SDL renderer to draw to. |
If the entity is marked as renderable, iterates over all components and renders each one.
Reimplemented in BackGroundGameEntity, EnemyGameEntity, FoodGameEntity, GroundGameEntity, and PlayerGameEntity.
Sets the entity's renderable state.
value | True if the entity should be rendered, false otherwise. |
Updates the entity and its components.
deltaTime | The time since the last update. |
Iterates over all components and updates each one. Can be overridden by derived classes for additional update logic.
Reimplemented in BackGroundGameEntity, EnemyGameEntity, FoodGameEntity, GroundGameEntity, and PlayerGameEntity.