41 if (child ==
nullptr)
return;
96 if (node ==
nullptr)
return;
108 idGameObject = node->getGameObject();
122 std::vector<GameObject*> taggedGameObjects;
125 taggedGameObjects.push_back(node->getGameObject());
130 if (tag ==
"Player" || tag ==
"Bow") {
136 return taggedGameObjects;
150 auto health = players[0]->getComponent<
Health>();
151 if (health->getHealth() <= 0) {
157 if (enemies.empty() && keys.empty()) {
Core class representing an entity in the game world.
std::string getTag()
Gets the tag identifier of the GameObject.
void setSceneNode(SceneNode *sceneNode)
Sets the SceneNode for this GameObject.
std::string getId()
Gets the unique identifier of the GameObject.
A component for managing health of game objects.
Represents a node in the scene graph, encapsulating a game object and its hierarchy.
bool m_isBackground
Flag to indicate whether this node is part of the background.
void addChild(GameObject *child, bool isBackground=false)
Adds a child game object to this node.
void setIsBackground(bool isBackground)
Sets whether this node is part of the background.
~SceneNode()
Destructor, ensures proper cleanup of node resources. This destructor is private to ensure that Scene...
bool isBackground()
Checks if this node is part of the background.
GameObject * m_gameObject
Pointer to the GameObject this node represents.
SceneNode * m_parent
Pointer to the parent node in the scene graph.
void setDestroy(bool destroy)
Sets the destruction state of this node.
bool m_destroy
Flag to indicate whether this node is scheduled for destruction.
bool readyToDestroy()
Checks if this node is marked for destruction.
std::vector< SceneNode * > m_children
List of child nodes.
SceneNode(GameObject *gameObject)
Constructor that assigns a game object to this node.
const std::vector< SceneNode * > getChildren()
Returns the children of this node.
SceneNode * getParent()
Gets the parent of this node.
GameObject * getGameObject()
Gets the GameObject associated with this node.
std::unordered_map< std::string, std::vector< GameObject * > > m_cachedGameObjectsInFrame
Cache for faster lookup of GameObjects by tag within a frame.
std::unordered_map< std::string, GameObject * > m_cachedGameObjects
Cache for faster lookup of GameObjects by ID.
GameObject * findGameObjectById(std::string id)
Finds a GameObject by its ID.
SceneNode * m_root
Root node of the scene tree.
SceneTree()
Constructor for creating a root node of the scene tree.
void addChild(GameObject *child, bool isBackground=false)
Adds a child GameObject to the scene tree.
void resetCachedGameObjectsInFrame()
Resets the cached game objects for a new frame, clearing the current frame's cache.
~SceneTree()
Destructor, cleans up the tree resources.
void traverseTree(std::function< void(SceneNode *)> callback)
Traverses the entire tree, executing a callback on each node.
std::vector< GameObject * > & findCachedGameObjectsInFrame(std::string tag)
Retrieves the game objects cached by tag.
int gameStatus()
Retrieves the current game status.
std::vector< GameObject * > findGameObjectsByTag(std::string tag)
Finds GameObjects by a tag.
Defines the Health class, a component for managing the health of game objects.
Defines the SceneNode and SceneTree classes for managing game objects within scenes.