2
0

Actor.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include <vector>
  10. #include "Math.h"
  11. class Actor
  12. {
  13. public:
  14. enum State
  15. {
  16. EActive,
  17. EPaused,
  18. EDead
  19. };
  20. Actor(class Game* game);
  21. virtual ~Actor();
  22. // Update function called from Game (not overridable)
  23. void Update(float deltaTime);
  24. // Updates all the components attached to the actor (not overridable)
  25. void UpdateComponents(float deltaTime);
  26. // Any actor-specific update code (overridable)
  27. virtual void UpdateActor(float deltaTime);
  28. // Getters/setters
  29. const Vector2& GetPosition() const { return mPosition; }
  30. void SetPosition(const Vector2& pos) { mPosition = pos; }
  31. float GetScale() const { return mScale; }
  32. void SetScale(float scale) { mScale = scale; }
  33. float GetRotation() const { return mRotation; }
  34. void SetRotation(float rotation) { mRotation = rotation; }
  35. State GetState() const { return mState; }
  36. void SetState(State state) { mState = state; }
  37. class Game* GetGame() { return mGame; }
  38. // Add/remove components
  39. void AddComponent(class Component* component);
  40. void RemoveComponent(class Component* component);
  41. private:
  42. // Actor's state
  43. State mState;
  44. // Transform
  45. Vector2 mPosition;
  46. float mScale;
  47. float mRotation;
  48. std::vector<class Component*> mComponents;
  49. class Game* mGame;
  50. };