Actor.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <cstdint>
  12. class Actor
  13. {
  14. public:
  15. enum State
  16. {
  17. EActive,
  18. EPaused,
  19. EDead
  20. };
  21. Actor(class Game* game);
  22. virtual ~Actor();
  23. // Update function called from Game (not overridable)
  24. void Update(float deltaTime);
  25. // Updates all the components attached to the actor (not overridable)
  26. void UpdateComponents(float deltaTime);
  27. // Any actor-specific update code (overridable)
  28. virtual void UpdateActor(float deltaTime);
  29. // ProcessInput function called from Game (not overridable)
  30. void ProcessInput(const uint8_t* keyState);
  31. // Any actor-specific input code (overridable)
  32. virtual void ActorInput(const uint8_t* keyState);
  33. // Getters/setters
  34. const Vector2& GetPosition() const { return mPosition; }
  35. void SetPosition(const Vector2& pos) { mPosition = pos; }
  36. float GetScale() const { return mScale; }
  37. void SetScale(float scale) { mScale = scale; }
  38. float GetRotation() const { return mRotation; }
  39. void SetRotation(float rotation) { mRotation = rotation; }
  40. Vector2 GetForward() const { return Vector2(Math::Cos(mRotation), -Math::Sin(mRotation)); }
  41. State GetState() const { return mState; }
  42. void SetState(State state) { mState = state; }
  43. class Game* GetGame() { return mGame; }
  44. // Add/remove components
  45. void AddComponent(class Component* component);
  46. void RemoveComponent(class Component* component);
  47. private:
  48. // Actor's state
  49. State mState;
  50. // Transform
  51. Vector2 mPosition;
  52. float mScale;
  53. float mRotation;
  54. std::vector<class Component*> mComponents;
  55. class Game* mGame;
  56. };