SFGF
GameObject.hpp
1 #ifndef GAMEOBJECT_HPP
2 #define GAMEOBJECT_HPP
3 
4 /* =========================================================== *
5  * SFGF (c) Kamil Koczurek | koczurekk@gmail.com *
6  * GNU GPL v3 License http://www.gnu.org/licenses/gpl-3.0.html *
7  * =========================================================== */
8 
9 #include <SFML/Graphics/Transformable.hpp>
10 #include <SFML/System/Time.hpp>
11 #include "CopyLock.hpp"
12 
13 namespace sfgf {
14  class GameObject
15  : public sf::Transformable {
16  private:
17  const GameObject* m_parent = nullptr;
18  const CopyLock m_copyLock;
19 
20  public:
21  virtual ~GameObject() {}
22 
23  virtual void update(sf::Time);
24 
25  void setParent(const GameObject& parent);
26  const GameObject& getParent() const;
27 
28  sf::Transform getTransform() const;
29  };
30  void GameObject::update(sf::Time)
31  { }
32 
33  void GameObject::setParent(const GameObject& parent) {
34  m_parent = &parent;
35  }
36  const GameObject& GameObject::getParent() const {
37  return *m_parent;
38  }
39 
40  sf::Transform GameObject::getTransform() const {
41  if(m_parent) {
42  return m_parent->getTransform() * sf::Transformable::getTransform();
43  }
44 
45  return sf::Transformable::getTransform();
46  }
47 }
48 
49 #endif // GAMEOBJECT_HPP
Contains all SFGF classes.
Definition: GameObject.hpp:14
Definition: CopyLock.hpp:10