TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tbx_health_bar.hpp
1 
9 #ifndef TurtleBrainsExpress_HealthBar_hpp
10 #define TurtleBrainsExpress_HealthBar_hpp
11 
12 #include <turtle_brains/graphics/tb_graphic.hpp>
13 #include <turtle_brains/graphics/tb_sprite.hpp>
14 #include <turtle_brains/graphics/tb_text.hpp>
15 #include <turtle_brains/graphics/tb_basic_shapes.hpp>
16 
17 #include <turtle_brains/game/tb_entity_behavior_interface.hpp>
18 #include <turtle_brains/game/tb_game_timer.hpp>
19 
20 namespace TurtleBrainsExpress
21 {
22  namespace Counters
23  {
24 
29  {
30  public:
41 
45  virtual ~HealthBar(void);
46 
56  void SetSize(const tbGraphics::PixelSpace& width, const tbGraphics::PixelSpace& height);
57 
62  const tbCore::uint16& GetTotal(void) const;
63 
72  void SetTotal(const tbCore::uint16 total);
73 
77  const tbCore::uint16& GetCount(void) const;
78 
87  void SetCount(const tbCore::uint16 count);
88 
94  void SetFillColor(const tbGraphics::Color& fillColor);
95 
100  virtual tbGraphics::PixelSpace GetPixelWidth(void) const override;
101 
106  virtual tbGraphics::PixelSpace GetPixelHeight(void) const override;
107 
108  protected:
113  virtual void OnUpdate(const float deltaTime) override;
114 
118  virtual void OnRender(void) const override;
119 
120  private:
125  void GenerateBoxes(void);
126 
127  tbCore::uint16 mTotal;
128  tbCore::uint16 mCount;
129 
130  tbGraphics::PixelSpace mBarWidth;
131  tbGraphics::PixelSpace mBarHeight;
132  tbGraphics::PixelSpace mBorderWeight;
133  tbGraphics::Color mFillColor;
134  tbGraphics::Color mBackColor;
135 
136  tbGraphics::BoxShape mFilling;
137  tbGraphics::BoxShape mBacking;
138  bool mIsDirty;
139  };
140 
141 
147  {
148  public:
158  explicit HealthIcons(const tbGraphics::Sprite& fillingSprite, const tbGraphics::Sprite& backingSprite);
159 
163  virtual ~HealthIcons(void);
164 
173  void SetIcons(const tbGraphics::Sprite& fillingSprite, const tbGraphics::Sprite& backingSprite);
174 
179  const tbCore::uint16& GetTotal(void) const;
180 
189  void SetTotal(const tbCore::uint16 total);
190 
194  const tbCore::uint16& GetCount(void) const;
195 
204  void SetCount(const tbCore::uint16 count);
205 
206  protected:
211  virtual void OnRender(void) const override;
212 
213  private:
214  tbCore::uint16 mTotal;
215  tbCore::uint16 mCount;
216  tbGraphics::PixelSpace mPadding;
217  tbGraphics::Sprite mFillingSprite;
218  tbGraphics::Sprite mBackingSprite;
219  };
220 
221 
225 
226  // - Optional icon sprite/image/graphic??
227  // - Optional total counter / target value X; 3 / X
228  //
229  class Counter : public tbGraphics::Text
230  {
231  public:
237  explicit Counter(tbCore::uint16 total);
238 
242  virtual ~Counter(void);
243 
248  const tbCore::uint16& GetTotal(void) const;
249 
258  void SetTotal(const tbCore::uint16 total);
259 
263  const tbCore::uint16& GetCount(void) const;
264 
273  void SetCount(const tbCore::uint16 count);
274 
278  void JumpDisplay(void);
279 
280  protected:
284  virtual void OnUpdate(const float deltaTime) override;
285 
286  private:
287  tbCore::uint16 mTotal;
288  tbCore::uint16 mCount;
289  tbCore::uint16 mDisplayedCount;
290 
291  float mTimePerChange;
292  float mChangeTimer;
293  };
294 
296  namespace Unstable
297  {
301  // - Small little class that takes/allows an animated sprite to be set
302  // - follows some form of pattern similar to rxi's butterfly/fish?
303  // - used simply as decoration, to liven an environment.
304  //
305  class ButterflyBehavior : public tbGame::EntityBehaviorInterface
306  {
307  public:
308  ButterflyBehavior(tbGame::Entity& entity);
309  virtual ~ButterflyBehavior(void);
310 
311  void OnAdd(void) override;
312  void OnSimulate(void) override;
313 
314  private:
315  tbMath::Vector2 mInitialPosition;
316  tbMath::Vector2 mRange;
317  tbGame::GameTimer mTimer;
318  };
319  };
321 
322  }; /* namespace Counters */
323 }; /* namespace TurtleBrainsExpress */
324 
326 
327 #endif /* TurtleBrainsExpress_HealthBar_hpp */
Definition: tb_vector.hpp:48
Definition: tb_graphic.hpp:61
Definition: tb_entity.hpp:46
Definition: tbx_health_bar.hpp:22
void SetTotal(const tbCore::uint16 total)
void SetIcons(const tbGraphics::Sprite &fillingSprite, const tbGraphics::Sprite &backingSprite)
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.hpp:26
virtual void OnRender(void) const override
virtual tbGraphics::PixelSpace GetPixelHeight(void) const override
Definition: tb_entity_behavior_interface.hpp:24
A collection of objects and functions to express games quickly.
void SetCount(const tbCore::uint16 count)
void SetFillColor(const tbGraphics::Color &fillColor)
HealthBar(const tbGraphics::Color &fillColor=tbGraphics::ColorPalette::Green, const tbGraphics::Color &backColor=tbGraphics::ColorPalette::Black)
void SetCount(const tbCore::uint16 count)
virtual tbGraphics::PixelSpace GetPixelWidth(void) const override
HealthIcons(const tbGraphics::Sprite &fillingSprite, const tbGraphics::Sprite &backingSprite)
Definition: tbx_health_bar.hpp:28
Definition: tb_color.hpp:24
virtual void OnRender(void) const override
Definition: tbx_health_bar.hpp:146
const tbCore::uint16 & GetTotal(void) const
virtual void OnUpdate(const float deltaTime) override
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.hpp:36
Definition: tb_text.hpp:42
void SetTotal(const tbCore::uint16 total)
const tbCore::uint16 & GetTotal(void) const
const tbCore::uint16 & GetCount(void) const
void SetCount(const tbCore::uint16 count)
const tbCore::uint16 & GetCount(void) const
const tbCore::uint16 & GetCount(void) const
Definition: tbx_health_bar.hpp:229
void SetTotal(const tbCore::uint16 total)
void SetSize(const tbGraphics::PixelSpace &width, const tbGraphics::PixelSpace &height)
const tbCore::uint16 & GetTotal(void) const
virtual void OnUpdate(const float deltaTime) override
Definition: tb_game_timer.hpp:25
Definition: tb_basic_shapes.hpp:237
Definition: tb_sprite.hpp:136