#include <tb_entity.h>
Public Member Functions | |
Entity (const EntityType &entityType) | |
virtual | ~Entity (void)=0 |
EntityManager * | GetEntityManager (void) const |
void | Simulate (void) |
void | PushBehavior (EntityBehaviorInterface *entityBehavior) |
void | PopBehavior (void) |
void | PopBehaviorIf (EntityBehaviorInterface *entityBehavior) |
void | PopAllBehaviors (void) |
const EntityBehaviorInterface * | GetActiveBehavior (void) const |
EntityBehaviorInterface * | GetActiveBehavior (void) |
bool | IsCollidable (void) const |
void | SetCollidable (const bool isCollidable) |
bool | HasBoundingVolume (void) const |
void | RemoveBoundingVolumes (void) |
void | AddBoundingCircle (const float circleRadius, const tbMath::Vector2 ¢erOffset=tbMath::Vector2::kZero) |
void | AddBoundingBox (const float boxWidth, const float boxHeight, const tbMath::Vector2 ¢erOffset=tbMath::Vector2::kZero) |
bool | CheckCollisionWith (const tbMath::Vector2 &point) const |
bool | CheckCollisionWith (const tbMath::Vector2 ¢er, const float radius) const |
bool | CheckCollisionWith (const tbMath::Vector2 ¢er, const float width, const float height) const |
bool | CheckCollisionWith (const Entity &otherEntity) const |
const EntityType & | GetEntityType (void) const |
![]() | |
GraphicList (void) | |
virtual | ~GraphicList (void) |
void | AddGraphic (Graphic *graphic) |
void | AddGraphic (Graphic &graphic) |
void | RemoveGraphic (Graphic *graphic) |
virtual void | SetColor (const tbGraphics::Color &newColor) |
![]() | |
Graphic (void) | |
Graphic (const Graphic &other) | |
virtual | ~Graphic (void) |
bool | IsActive (void) const |
void | SetActive (const bool isActive) |
void | Update (const float deltaTime) |
bool | IsVisible (void) const |
void | SetVisible (const bool isVisible) |
void | Render (void) const |
const tbMath::Vector2 & | GetPosition (void) const |
void | SetPosition (const float x, const float y) |
void | SetPosition (const tbMath::Vector2 &position) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
bool | IsRelative (void) const |
Static Public Attributes | |
static const EntityType | kInvalidType |
Protected Member Functions | |
virtual void | OnSimulate (void) |
virtual void | OnUpdate (const float deltaTime) |
virtual void | OnRender (void) const |
virtual void | OnCollideWith (Entity &other) |
virtual void | OnAdded (void) |
virtual void | OnRemoved (void) |
![]() | |
const Color & | GetColor (void) const |
Friends | |
class | EntityManager |
The Entity object is a GraphicList to give it the ability to display itself with Graphic objects and the ability for subclasses to overload OnUpdate. Since entities will likely be performing game logic, Simulate and OnSimulate have been added to the interface to provide a fixed time step update that may be called 0 to N times per frame.
|
explicit |
Constructs an empty entity object which contains no Graphics and position is defaults to 0,0 but has the specified type.
|
pure virtual |
Destructs an entity which currently (TurtleBrains v0.2.0) does not have any resources to clean up after.
void TurtleBrains::Game::Entity::AddBoundingBox | ( | const float | boxWidth, |
const float | boxHeight, | ||
const tbMath::Vector2 & | centerOffset = tbMath::Vector2::kZero |
||
) |
Adds a bounding Box to the entity to perform collisions and enables the entity to be collidable. Multiple bounding volumes can be added to the entity, and if any bodies collide the collision check will return true.
void TurtleBrains::Game::Entity::AddBoundingCircle | ( | const float | circleRadius, |
const tbMath::Vector2 & | centerOffset = tbMath::Vector2::kZero |
||
) |
Adds a bounding Circle to the entity to perform collisions and enables the entity to be collidable. Multiple bounding volumes can be added to the entity, and if any bodies collide the collision check will return true.
bool TurtleBrains::Game::Entity::CheckCollisionWith | ( | const tbMath::Vector2 & | point | ) | const |
Checks to see if the Entity collides with the provided point in the same 2D space.
point | The point to check if it is contained within one of the bounding volumes for the entity. |
bool TurtleBrains::Game::Entity::CheckCollisionWith | ( | const tbMath::Vector2 & | center, |
const float | radius | ||
) | const |
Checks to see if the entity's bounding volumes collide with the circle provided, if the entity does not have any bounding volumes, this will instead check if the position of the entity is inside the circle, returning true if it is, false otherwise.
center | The center of the bounding circle to check for a collision with the entities bounding volumes. |
radius | The radius of the bounding circle for the collision check, for most projects this will be in pixels but it is possible that units are different. |
bool TurtleBrains::Game::Entity::CheckCollisionWith | ( | const tbMath::Vector2 & | center, |
const float | width, | ||
const float | height | ||
) | const |
Checks to see if the entity's bounding volumes collide with the axis-aligned box provided, if the entity does not have any bounding volumes, this will instead check if the position of the entity is inside the box, returning true if it is, false otherwise.
center | The center of the bounding box to check for a collision with the entities bounding volumes. |
width | The horizontal size of the bounding box for the collision check, for most projects this will be in pixels but it is possible that units are different. |
height | The vertical size of the bounding box for the collision check, for most projects this will be in pixels but it is possible that units are different. |
bool TurtleBrains::Game::Entity::CheckCollisionWith | ( | const Entity & | otherEntity | ) | const |
Checks to see if the Entity collides with the other entity provided.
otherEntity | The Entity to check for collisions with. |
const EntityBehaviorInterface* TurtleBrains::Game::Entity::GetActiveBehavior | ( | void | ) | const |
TODO: TIM: Documentation: Teach the user how to use this.
EntityBehaviorInterface* TurtleBrains::Game::Entity::GetActiveBehavior | ( | void | ) |
TODO: TIM: Documentation: Teach the user how to use this.
EntityManager* TurtleBrains::Game::Entity::GetEntityManager | ( | void | ) | const |
Returns the EntityManager the entity is managed by, which can be nullptr.
|
inline |
Returns the EntityType of the Entity.
bool TurtleBrains::Game::Entity::HasBoundingVolume | ( | void | ) | const |
Returns true if the entity has a bounding volume.
bool TurtleBrains::Game::Entity::IsCollidable | ( | void | ) | const |
Returns true if the entity will perform collision automatically each frame, it must also contain a bounding volume for collision to occur, call AddBoundingCircle() or AddBoundingBox() to create the bounding volume for the collision.
|
protectedvirtual |
TODO: TIM: Documentation: Teach the user how to use this.
|
protectedvirtual |
This should be overridded by a subclass if it needs to perform any game logic when a collision occurs with another entity type. This will be invoked on both entities, so if you had a bullet and a target the following calls: target.OnCollideWith(bullet) and bullet.OnCollideWith(target) would be made in no particular order.
|
protectedvirtual |
TODO: TIM: Documentation: Teach the user how to use this.
|
protectedvirtual |
Calls Render() on each Graphic object contained in the list which will then call OnRender() if the object is visible.
Reimplemented from TurtleBrains::Graphics::GraphicList.
|
protectedvirtual |
This should be overridden by a subclass if it needs to perform any game logic updates at a fixed time step for determinism. This function will be invoked when Simulate() is called and the entity IsActive(). This may be called from 0 to N times per frame.
|
protectedvirtual |
Calls Update() on each Graphic object contained in the list which will then call OnUpdate() if the object is active.
Reimplemented from TurtleBrains::Graphics::GraphicList.
void TurtleBrains::Game::Entity::PopAllBehaviors | ( | void | ) |
TODO: TIM: Documentation: Teach the user how to use this.
void TurtleBrains::Game::Entity::PopBehavior | ( | void | ) |
TODO: TIM: Documentation: Teach the user how to use this.
void TurtleBrains::Game::Entity::PopBehaviorIf | ( | EntityBehaviorInterface * | entityBehavior | ) |
TODO: TIM: Documentation: Teach the user how to use this.
void TurtleBrains::Game::Entity::PushBehavior | ( | EntityBehaviorInterface * | entityBehavior | ) |
TODO: TIM: Documentation: Teach the user how to use this.
void TurtleBrains::Game::Entity::RemoveBoundingVolumes | ( | void | ) |
Removes all bounding volumes the entity may have and will make the entity no longer collidable.
void TurtleBrains::Game::Entity::SetCollidable | ( | const bool | isCollidable | ) |
Sets a flag that when false causes the entity to skip automated collision checks within the entity manager and when true will check for collision and call OnCollideWith() when a collision event occurs. Defaults to false, and will lead to better performance if false when the object does not need to check collision with other objects.
TODO: TIM: Documentation: Teach the user how to use this.
void TurtleBrains::Game::Entity::Simulate | ( | void | ) |
First checks to see if the entity IsActive() and calls OnSimulate() if it is. If the entity is not active nothing happens.
|
static |
TODO: TIM: Documentation: Teach the user how to use this. TODO: TIM: This may get deprecated and replaced with "properties" / "flags", or, multiple types.