#include <tb_entity.hpp>
Public Member Functions | |
Entity (const EntityType &entityType) | |
virtual | ~Entity (void) |
EntityManager * | GetEntityManager (void) const |
void | Simulate (void) |
void | ClearBehaviors (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 | ClearBoundingVolumes (void) |
void | AddBoundingCircle (const float circleRadius, const tbMath::Vector2 ¢erOffset=tbMath::Vector2::Zero()) |
void | AddBoundingBox (const float boxWidth, const float boxHeight, const tbMath::Vector2 ¢erOffset=tbMath::Vector2::Zero()) |
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 |
const EntityTypeContainer & | GetEntityTypes (void) const |
void | AddEntityType (const EntityType &entityType) |
void | RemoveEntityType (const EntityType &entityType) |
bool | IsEntityOfType (const EntityType &entityType) const |
Public Member Functions inherited from TurtleBrains::Graphics::GraphicList | |
GraphicList (void) | |
virtual | ~GraphicList (void) |
void | ClearGraphics (void) |
void | AddGraphic (Graphic *graphic) |
void | AddGraphic (Graphic &graphic) |
void | RemoveGraphic (Graphic *graphic) |
virtual void | SetColor (const tbGraphics::Color &newColor) override |
virtual PixelSpace | GetPixelWidth (void) const |
virtual PixelSpace | GetPixelHeight (void) const |
void | RecalculateWidthAndHeight (void) |
Public Member Functions inherited from TurtleBrains::Graphics::Graphic | |
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) |
const tbMath::Vector2 & | GetOrigin (void) const |
void | SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) |
void | SetOrigin (const float originX, const float originY) |
void | SetOrigin (const tbMath::Vector2 &origin) |
float | GetDepth (void) const |
void | SetDepth (const float newDepth) |
const tbMath::Vector2 & | GetScale (void) const |
void | SetScale (const float scale) |
void | SetScale (const tbMath::Vector2 &scale) |
void | SetScale (const float scaleX, const float scaleY) |
float | GetRotation (void) const |
void | SetRotation (const float rotation) |
void | SetScroll (const float scroll) |
void | SetScroll (const float scrollX, const float scrollY) |
bool | IsRelative (void) const |
const Color & | GetColor (void) const |
float | GetWidth (void) const |
float | GetHeight (void) const |
float | GetScaledWidth (void) const |
float | GetScaledHeight (void) const |
bool | UnstableIsPointContained (const tbMath::Vector2 &point) 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 | OnDebugRender (void) const |
virtual void | OnCollide (const Entity &other) |
virtual void | OnAdd (void) |
virtual void | OnRemove (void) |
Protected Member Functions inherited from TurtleBrains::Graphics::Graphic | |
virtual void | ApplyTransform (void) const |
virtual void | PopTransform (void) const |
Friends | |
class | EntityManager |
class | TileSystem |
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.
|
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::Zero() |
||
) |
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::Zero() |
||
) |
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.
void TurtleBrains::Game::Entity::AddEntityType | ( | const EntityType & | entityType | ) |
Adds the entity type to the entity, in this way you can have multiple types for an entity. If the entityType is kInvalidType an error condition will be triggered.
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. |
void TurtleBrains::Game::Entity::ClearBehaviors | ( | void | ) |
Removes/clears all the behaviors from the entities behavior stack, same as PopAllBehaviors().
void TurtleBrains::Game::Entity::ClearBoundingVolumes | ( | void | ) |
Removes all bounding volumes the entity may have and will make the entity no longer collidable.
const EntityBehaviorInterface* TurtleBrains::Game::Entity::GetActiveBehavior | ( | void | ) | const |
TODO: TurtleBrains: Documentation: Teach the user how to use this.
EntityBehaviorInterface* TurtleBrains::Game::Entity::GetActiveBehavior | ( | void | ) |
TODO: TurtleBrains: 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.
const EntityType& TurtleBrains::Game::Entity::GetEntityType | ( | void | ) | const |
Returns the EntityType of the Entity.
const EntityTypeContainer& TurtleBrains::Game::Entity::GetEntityTypes | ( | void | ) | const |
Returns a container of all the EntityTypes for 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.
bool TurtleBrains::Game::Entity::IsEntityOfType | ( | const EntityType & | entityType | ) | const |
Checks through the entity types that have been added to the Entity for a match, returning true if a match is found or false if no match was found.
|
protectedvirtual |
This is called just after the Entity is added to an EntityManager, aka: the scene, so the entity can perform any logic before starting to perform in the game loop.
|
protectedvirtual |
This should be overridden 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.OnCollide(bullet) and bullet.OnCollide(target) would be made in no particular order.
|
protectedvirtual |
This should render the bounding volumes of the entity in a light red.
|
protectedvirtual |
This is called just before the Entity is removed from an EntityManager, aka the scene, so that any logic or resource cleanup can be performed.
|
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 | ) |
Removes/clears all the behaviors from the entities behavior stack, same as ClearBehaviors().
void TurtleBrains::Game::Entity::PopBehavior | ( | void | ) |
Pops the behavior at the top of the stack, and deletes the resources for it. Resumes the next Behavior which is now the active one and on top of the stack.
void TurtleBrains::Game::Entity::PopBehaviorIf | ( | EntityBehaviorInterface * | entityBehavior | ) |
Checks if the address of the current behavior, at the top of the stack, matches the address supplied, and only if these match does the behavior get popped by calling PopBehavior().
entityBehavior | The behavior to check against the top of the stack and pop if they match. |
void TurtleBrains::Game::Entity::PushBehavior | ( | EntityBehaviorInterface * | entityBehavior | ) |
Push the behavior onto the Entity so it becomes the active behavior controlling the Entity and the current behavior gets paused until this is popped. The behavior should be allocated with new, and the Entity will call delete on it when finished.
entityBehavior | The behavior to push and activate on the top of the entities behavior stack. Must be allocated with new, as the Entity will call delete on the behavior later. |
void TurtleBrains::Game::Entity::RemoveEntityType | ( | const EntityType & | entityType | ) |
Finds and removes an EntityType from the entity so it no longer counts as that type.
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 OnCollide() 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.
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: TurtleBrains: Documentation: Teach the user how to use this. TODO: TIM: This may get deprecated and replaced with "properties" / "flags", or, multiple types.