TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tbx_cutscene_entity.hpp
1 
9 #ifndef TurtleBrainsExpress_CutsceneEntity_hpp
10 #define TurtleBrainsExpress_CutsceneEntity_hpp
11 
12 #include <turtle_brains/core/tb_string.hpp>
13 #include <turtle_brains/core/tb_dynamic_structure.hpp>
14 #include <turtle_brains/math/tb_interpolation.hpp>
15 #include <turtle_brains/game/tb_entity.hpp>
16 #include <turtle_brains/game/tb_game_timer.hpp>
17 
18 #include <unordered_map>
19 
20 namespace TurtleBrainsExpress
21 {
22  namespace Entities
23  {
25  namespace Unstable
26  {
27 
31  class CutsceneEntity : public tbGame::Entity
32  {
33  public:
37  explicit CutsceneEntity(void);
38 
46  explicit CutsceneEntity(const tbCore::tbString& scriptFile, const std::vector<tbCore::tbString>& parameters = { });
47 
51  virtual ~CutsceneEntity(void);
52 
56  bool IsPlaying(void) const;
57 
64  void Play(bool isLooping);
65 
69  void Pause(void);
70 
74  void Stop(void);
75 
81  static void CheckAndReloadCutsceneScripts(void);
82 
83  protected:
84  enum TweenChannel
85  {
86  Position,
87  Rotation,
88  Scale,
89  Count
90  };
91 
92  struct KeyFrame
93  {
94  tbGame::GameTimer mStartTime;
95  tbMath::Vector2 mPosition;
96  tbMath::Vector2 mScale;
97  tbMath::Angle mRotation;
98  tbGraphics::Color mColor;
99  tbMath::Interpolation::InterpolationMode mTweenMode[TweenChannel::Count];
100  };
101 
102  virtual void OnAdd(void) override;
103  virtual void OnRemove(void) override;
104  virtual void OnSimulate(void) override;
105  virtual void OnUpdate(const float deltaTime) override;
106  virtual void OnRender(void) const override;
107  virtual void OnCollide(const tbGame::Entity& otherEntity) override;
108 
109  void AddSceneProp(const tbCore::tbString& name, tbGraphics::Graphic& graphic, bool setInitialFrame);
110  void AddSceneProp(const tbCore::tbString& name, tbGraphics::Graphic* graphic, bool setInitialFrame);
111 
112  void AddKeyFrame(const tbCore::tbString& name, const KeyFrame& keyFrame, bool additive);
113  void AddKeyFrame(const tbCore::tbString& name, const tbGraphics::Graphic& graphic,
114  const tbGame::GameTimer& startTime, bool additive);
115  bool GetLastKeyFrame(const tbCore::tbString& name, KeyFrame& keyFrame) const;
116 
117  private:
118  struct SceneProp
119  {
120  tbGraphics::Graphic* mGraphic;
121  std::vector<KeyFrame> mKeyFrames;
122  size_t mCurrentFrameIndex;
123  };
124 
125  void AddKeyFrame(SceneProp& sceneProp, const KeyFrame& keyFrame, bool additive);
126 
127  static KeyFrame BetweenKeyFrames(float percentage, const KeyFrame& start, const KeyFrame& final);
128  static KeyFrame KeyFrameFromGraphic(const tbGraphics::Graphic& graphic, const tbGame::GameTimer& startTime = 0);
129  static void SetGraphicToKeyFrame(tbGraphics::Graphic& graphic, const KeyFrame& keyFrame);
130 
131  void ClearScript(void);
132  void LoadScript(void);
133  tbGraphics::Graphic* LoadGraphic(const tbCore::DynamicStructure& graphicData) const;
134  void LoadSceneProp(const tbCore::DynamicStructure& propData, SceneProp& sceneProp) const;
135  bool LoadKeyFrame(const tbCore::DynamicStructure& keyFrameData, KeyFrame& keyFrame, const SceneProp& sceneProp) const;
136 
141  bool ReallyAddSceneProp(const tbCore::tbString& name, tbGraphics::Graphic& graphic, bool setInitialFrame);
142  bool ReallyAddSceneProp(const tbCore::tbString& name, const SceneProp& sceneProp);
143 
144  typedef std::unordered_map<tbCore::tbString, SceneProp> ScenePropTable;
145  ScenePropTable mSceneProps;
146  tbGame::GameTimer mCurrentTime;
147  const tbCore::tbString mScriptFile;
148  const std::vector<tbCore::tbString> mScriptParameters;
149  bool mIsPlaying;
150  bool mIsLooping;
151  };
152 
153  }; /* namespace Unstable */
155 
156  }; /* namespace Entities */
157 }; /* namespace TurtleBrainsExpress */
158 
160 
161 #endif /* TurtleBrainsExpress_CutsceneEntity_hpp */
Definition: tb_vector.hpp:48
Definition: tb_graphic.hpp:61
Definition: tb_entity.hpp:46
A collection of objects and functions to express games quickly.
Definition: tb_color.hpp:24
Definition: tb_dynamic_structure.hpp:37
Definition: tbx_cutscene_entity.hpp:22
Definition: tb_angle.hpp:34
std::string tbString
Definition: tb_string.hpp:335
Definition: tb_game_timer.hpp:25