1 #ifndef GAME_OBJECT_HPP 2 #define GAME_OBJECT_HPP 4 #include <unordered_map> 5 #include "RenderManager.hpp" 7 #include "Component.hpp" 14 class GameObject :
public std::enable_shared_from_this<GameObject> {
20 static std::shared_ptr<GameObject>
32 bool isPermanent =
false);
38 static std::shared_ptr<GameObject>
91 static_assert(std::is_base_of<Component, C>::value,
92 "C must derive from Component");
96 return std::shared_ptr<C>(NULL);
98 return std::static_pointer_cast<C>(it->second);
107 static_assert(std::is_base_of<Component, C>::value,
108 "C must derive from Component");
110 static_cast<std::shared_ptr<Component>
>(comp)->SetParentGameObject(
111 std::weak_ptr<GameObject>(shared_from_this()));
115 return shared_from_this();
Vector2 scale
The scale of this GameObject.
Definition: GameObject.hpp:55
bool IsColliding(const GameObject &other) const
Gets whether this GameObject is colliding with another.
Definition: GameObject.cpp:35
void Enable()
Enables this GameObject.
Definition: GameObject.cpp:31
static std::shared_ptr< GameObject > Create(int posX, int posY, int width, int height, bool isUI=false, bool isPermanent=false)
Creates a GameObject.
Definition: GameObject.cpp:10
static std::shared_ptr< GameObject > CreateStandard(int posX, int posY, int width, int height)
Creates a non-UI, non-permanent GameObject.
Definition: GameObject.cpp:18
static int GetTypeID()
Gets a new unused component id.
Definition: GameObject.hpp:148
std::shared_ptr< C > GetComponent()
Gets the first component of type C in the component map or null if none are found.
Definition: GameObject.hpp:90
bool IsActive() const
Gets whether this GameObject is active.
Definition: GameObject.cpp:33
SDL_Rect ScreenRegion()
Determines the screen region this object takes up.
Definition: GameObject.cpp:44
Basic class representation of a vector 2 with an x and y coordinate.
Definition: Vector2.hpp:8
GameObject(int posX, int posY, int width, int height, bool isUI)
Constructs a GameObject.
Definition: GameObject.cpp:7
void Update()
Updates this GameObject.
Definition: GameObject.cpp:23
A GameObject class.
Definition: GameObject.hpp:14
std::unordered_map< int, std::shared_ptr< Component > > componentMap
The map of component ids and components for this GameObject.
Definition: GameObject.hpp:132
bool active
Whether or not this GameObject is active.
Definition: GameObject.hpp:135
Vector2 position
The position of this GameObject.
Definition: GameObject.hpp:52
void Disable()
Disables this GameObject.
Definition: GameObject.cpp:29
static int lastTypeID
The last component id used.
Definition: GameObject.hpp:141
std::shared_ptr< GameObject > AddComponent(std::shared_ptr< C > comp)
Adds a component of type C to the component map.
Definition: GameObject.hpp:106
bool isUI
Whether this GameObject should use direct screen coordinates.
Definition: GameObject.hpp:138