TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
tbx_health_bar.h
1 
9 #ifndef _TurtleBrainsExpress_HealthBar_h_
10 #define _TurtleBrainsExpress_HealthBar_h_
11 
12 #include "../../graphics/tb_graphic.h"
13 #include "../../graphics/tb_sprite.h"
14 #include "../../graphics/tb_text.h"
15 #include "../../graphics/tb_basic_shapes.h"
16 
17 #include "../../game/tb_entity_behavior_interface.h"
18 
19 namespace TurtleBrainsExpress
20 {
21  namespace Counters
22  {
23 
28  {
29  public:
30  explicit HealthBar(const tbGraphics::Color& fillColor = tbGraphics::ColorPalette::Green,
31  const tbGraphics::Color& backColor = tbGraphics::ColorPalette::Black);
32 
33  virtual ~HealthBar(void);
34 
35  void SetSize(const tbGraphics::PixelSpace& width, const tbGraphics::PixelSpace& height);
36 
37  const tbCore::uint16& GetTotal(void) const;
38  void SetTotal(const tbCore::uint16 total);
39  const tbCore::uint16& GetCount(void) const;
40  void SetCount(const tbCore::uint16 count);
41 
42  //
43  // Made in LD39 - double check if this is desired interface.
44  void SetFillColor(const tbGraphics::Color& fillColor);
45 
46  protected:
47  virtual void OnUpdate(const float deltaTime) override;
48  virtual void OnRender(void) const override;
49 
50  private:
51  void GenerateBoxes(void);
52 
53  tbCore::uint16 mTotal;
54  tbCore::uint16 mCount;
55 
56  tbGraphics::PixelSpace mBarWidth;
57  tbGraphics::PixelSpace mBarHeight;
58  tbGraphics::PixelSpace mBorderWeight;
59  tbGraphics::Color mFillColor;
60  tbGraphics::Color mBackColor;
61 
62  tbGraphics::BoxShape mFilling;
63  tbGraphics::BoxShape mBacking;
64  bool mIsDirty;
65  };
66 
67 
68 
69 
70 
71 
76  {
77  public:
78  explicit HealthIcons(const tbGraphics::Sprite& fillingSprite, const tbGraphics::Sprite& backingSprite);
79  virtual ~HealthIcons(void);
80 
81  void SetIcons(const tbGraphics::Sprite& fillingSprite, const tbGraphics::Sprite& backingSprite);
82 
83  const tbCore::uint16& GetTotal(void) const;
84  void SetTotal(const tbCore::uint16 total);
85  const tbCore::uint16& GetCount(void) const;
86  void SetCount(const tbCore::uint16 count);
87 
88  protected:
89  virtual void OnUpdate(const float deltaTime) override;
90  virtual void OnRender(void) const override;
91 
92  private:
93  tbCore::uint16 mTotal;
94  tbCore::uint16 mCount;
95  tbGraphics::PixelSpace mPadding;
96  tbGraphics::Sprite mFillingSprite;
97  tbGraphics::Sprite mBackingSprite;
98  };
99 
100 
101 
102 
103  //
104  // - Optional icon sprite/image/graphic??
105  // - Optional total counter / target value X; 3 / X
106  //
107  class Counter : public tbGraphics::Text
108  {
109  public:
110  explicit Counter(tbCore::uint16 total);
111  virtual ~Counter(void);
112 
113  const tbCore::uint16& GetTotal(void) const;
114  void SetTotal(const tbCore::uint16 total);
115  const tbCore::uint16& GetCount(void) const;
116  void SetCount(const tbCore::uint16 count);
117 
118  void JumpDisplay(void);
119 
120  protected:
121  virtual void OnUpdate(const float deltaTime) override;
122 
123  private:
124  tbCore::uint16 mTotal;
125  tbCore::uint16 mCount;
126  tbCore::uint16 mDisplayedCount;
127 
128  float mTimePerChange;
129  float mChangeTimer;
130  };
131 
132  //
133  // - Small little class that takes/allows an animated sprite to be set
134  // - follows some form of pattern similar to rxi's butterfly/fish?
135  // - used simply as decoration, to liven an environment.
136  //
138  {
139  public:
141  virtual ~ButterflyBehavior(void);
142 
143  void OnAdd(void) override;
144  void OnSimulate(void) override;
145 
146  private:
147  tbMath::Vector2 mInitialPosition;
148  tbMath::Vector2 mRange;
149  tbGame::GameTimer mTimer;
150  };
151 
152  //
153  //
154  //
155 
156 
157  }; /* namespace Counters */
158 }; /* namespace TurtleBrainsExpress */
159 
161 
162 #endif /* _TurtleBrainsExpress_HealthBar_h_ */
Definition: tb_vector.h:47
Definition: tb_graphic.h:61
virtual void OnUpdate(const float deltaTime) override
Definition: tb_entity.h:46
Definition: tbx_health_bar.h:21
uint16_t uint16
Unsigned integer with a size of 16 bits. Supports values from 0 to 65535.
Definition: tb_types.h:26
virtual void OnRender(void) const override
Definition: tb_entity_behavior_interface.h:25
A collection of objects and functions to express games quickly.
Definition: tbx_health_bar.h:27
Definition: tb_color.h:23
virtual void OnRender(void) const override
Definition: tbx_health_bar.h:75
virtual void OnUpdate(const float deltaTime) override
tbCore::uint16 PixelSpace
Definition: tb_texture_manager.h:35
Definition: tb_text.h:42
Definition: tbx_health_bar.h:137
Definition: tbx_health_bar.h:107
virtual void OnUpdate(const float deltaTime) override
Definition: tb_game_timer.h:25
Definition: tb_basic_shapes.h:220
Definition: tb_sprite.h:136