1#ifndef UTIL_GAME_OBJECT_HPP
2#define UTIL_GAME_OBJECT_HPP
6#include "Core/Drawable.hpp"
8#include "Util/Transform.hpp"
38 GameObject(
const std::shared_ptr<Core::Drawable> &drawable,
39 const float zIndex,
const glm::vec2 &pivot = {0, 0},
40 const bool visible =
true,
41 const std::vector<std::shared_ptr<GameObject>> &children =
42 std::vector<std::shared_ptr<GameObject>>())
43 : m_Drawable(drawable),
91 return m_Drawable->GetSize() * m_Transform.
scale;
99 const std::vector<std::shared_ptr<GameObject>> &
GetChildren()
const {
108 void SetPivot(
const glm::vec2 &pivot) { m_Pivot = pivot; }
124 void SetDrawable(
const std::shared_ptr<Core::Drawable> &drawable) {
125 m_Drawable = drawable;
140 void AddChild(
const std::shared_ptr<GameObject> &child) {
141 m_Children.push_back(child);
151 std::remove(m_Children.begin(), m_Children.end(), child),
158 std::shared_ptr<Core::Drawable> m_Drawable =
nullptr;
159 std::vector<std::shared_ptr<GameObject>> m_Children;
162 bool m_Visible =
true;
163 glm::vec2 m_Pivot = {0, 0};
A class representing a game object.
Definition: GameObject.hpp:20
GameObject(const std::shared_ptr< Core::Drawable > &drawable, const float zIndex, const glm::vec2 &pivot={0, 0}, const bool visible=true, const std::vector< std::shared_ptr< GameObject > > &children=std::vector< std::shared_ptr< GameObject > >())
Parameterized constructor.
Definition: GameObject.hpp:38
float GetZIndex() const
Get the z-index of the game object.
Definition: GameObject.hpp:76
GameObject(GameObject &&other)=default
Default move constructor..
GameObject(const GameObject &other)=default
Copy constructor.
void SetPivot(const glm::vec2 &pivot)
Set the pivot of the game object.
Definition: GameObject.hpp:108
void RemoveChild(const std::shared_ptr< GameObject > &child)
Remove a child from the game object.
Definition: GameObject.hpp:149
void SetDrawable(const std::shared_ptr< Core::Drawable > &drawable)
Set the drawable component of the game object.
Definition: GameObject.hpp:124
const std::vector< std::shared_ptr< GameObject > > & GetChildren() const
Get the children of the game object.
Definition: GameObject.hpp:99
virtual ~GameObject()=default
Default destructor.
glm::vec2 GetScaledSize() const
Get the size of its drawable component.
Definition: GameObject.hpp:90
GameObject()=default
Default constructor.
void SetVisible(const bool visible)
Set the visibility of the game object.
Definition: GameObject.hpp:133
Transform GetTransform() const
Get the transform of the game object.
Definition: GameObject.hpp:83
void AddChild(const std::shared_ptr< GameObject > &child)
Add a child to the game object.
Definition: GameObject.hpp:140
void SetZIndex(float index)
Set the z-index of the game object. z-index is used to determine the order in which game objects are ...
Definition: GameObject.hpp:117
Useful tools for development.
Definition: Animation.hpp:12