dEngine
Simple 2D C++ game engine
|
A base object for a game The gameobject can be considered the most basic building block of a game. Everything in a game is considered a gameobject and it's functionality are determined by it's Components. More...
#include <GameObject.h>
Public Member Functions | |
GameObject (std::string objectName) | |
std::string | GetName () |
Returns the object's name. More... | |
void | AddComponent (Component *component) |
Adds a component to the GameObject. More... | |
void | RemoveComponent (Component *component) |
Removes a component from the GameObject. More... | |
bool | HasComponent (std::string name) |
Does it have a component? More... | |
virtual void | Start () |
Called on object instantiation. More... | |
virtual void | NotifyCollision (GameObject &other) |
virtual void | Update () |
Runs every frame performing any required logic. More... | |
virtual void | Render () |
Performs render on all attached components. More... | |
void | SetPos (float xPos, float yPos) |
Set position. More... | |
std::weak_ptr< Component > | GetComponentByName (std::string name) |
Get a reference to a component. More... | |
void | AddTag (std::string tag) |
Add a tag to the game object. More... | |
bool | HasTag (std::string tag) |
Check if game object has a tag. More... | |
void | RemoveTag (std::string tag) |
Remove tag from game object. More... | |
Public Attributes | |
SDL_Rect | box |
A rect denoting the object's position in space. More... | |
Private Attributes | |
std::vector< class Component * > | components |
A vector containing any components that may be on the GameObject. More... | |
std::string | name |
A string containing the object name. More... | |
std::vector< std::string > | tags |
A base object for a game The gameobject can be considered the most basic building block of a game. Everything in a game is considered a gameobject and it's functionality are determined by it's Components.
GameObject::GameObject | ( | std::string | objectName | ) |
void GameObject::AddComponent | ( | Component * | component | ) |
Adds a component to the GameObject.
component | The component to add to the object |
|
inline |
Add a tag to the game object.
std::weak_ptr< Component > GameObject::GetComponentByName | ( | std::string | name | ) |
Get a reference to a component.
name | Name of the component to get |
std::string GameObject::GetName | ( | ) |
bool GameObject::HasComponent | ( | std::string | name | ) |
Does it have a component?
Checks if the gameobject has a component with the specified name
name | The name of the component to check |
Referenced by GetComponentByName().
|
inline |
Check if game object has a tag.
|
virtual |
Notify the gameobject and any components of a collision
other | The other gameobject being collided with |
void GameObject::RemoveComponent | ( | Component * | component | ) |
Removes a component from the GameObject.
component | The component to remove |
|
inline |
Remove tag from game object.
|
virtual |
Performs render on all attached components.
void GameObject::SetPos | ( | float | xPos, |
float | yPos | ||
) |
Set position.
Set the position of the game object
xPos | X position |
yPos | Y position |
|
virtual |
Called on object instantiation.
|
virtual |
Runs every frame performing any required logic.
SDL_Rect dengine::GameObject::box |
A rect denoting the object's position in space.
Referenced by dengine::Sprite::Render(), dengine::SpriteSheet::Render(), SetPos(), and dengine::Collider::Update().
|
private |
A vector containing any components that may be on the GameObject.
Referenced by AddComponent(), GetComponentByName(), HasComponent(), NotifyCollision(), RemoveComponent(), Render(), Start(), and Update().
|
private |
A string containing the object name.
Referenced by GameObject(), GetComponentByName(), GetName(), and HasComponent().
|
private |
Referenced by AddTag(), HasTag(), and RemoveTag().