TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Express::Counters::HealthBar Class Reference

#include <tbx_health_bar.hpp>

Inheritance diagram for TurtleBrains::Express::Counters::HealthBar:
TurtleBrains::Graphics::Graphic

Public Member Functions

 HealthBar (const tbGraphics::Color &fillColor=tbGraphics::ColorPalette::Green, const tbGraphics::Color &backColor=tbGraphics::ColorPalette::Black)
 
virtual ~HealthBar (void)
 
void SetSize (const tbGraphics::PixelSpace &width, const tbGraphics::PixelSpace &height)
 
const tbCore::uint16GetTotal (void) const
 
void SetTotal (const tbCore::uint16 total)
 
const tbCore::uint16GetCount (void) const
 
void SetCount (const tbCore::uint16 count)
 
void SetFillColor (const tbGraphics::Color &fillColor)
 
virtual tbGraphics::PixelSpace GetPixelWidth (void) const override
 
virtual tbGraphics::PixelSpace GetPixelHeight (void) const override
 
- Public Member Functions inherited from TurtleBrains::Graphics::Graphic
 Graphic (void)
 
 Graphic (const Graphic &other)=default
 
virtual ~Graphic (void)=default
 
Graphicoperator= (const Graphic &other)=default
 
bool IsActive (void) const
 
void SetActive (const bool isActive)
 
void Update (const float deltaTime)
 
bool IsVisible (void) const
 
void SetVisible (const bool isVisible)
 
void Render (void) const
 
const tbMath::Vector2GetPosition (void) const
 
void SetPosition (const float x, const float y)
 
void SetPosition (const tbMath::Vector2 &position)
 
const tbMath::Vector2GetOrigin (void) const
 
void SetOrigin (const AnchorLocation &anchor, const float offsetX, const float offsetY)
 
void SetOrigin (const AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero())
 
void SetOrigin (const float originX, const float originY)
 
void SetOrigin (const tbMath::Vector2 &origin)
 
float GetDepth (void) const
 
void SetDepth (const float newDepth)
 
const tbMath::Vector2GetScale (void) const
 
void SetScale (const float scale)
 
void SetScale (const tbMath::Vector2 &scale)
 
void SetScale (const float scaleX, const float scaleY)
 
tbMath::Angle GetRotation (void) const
 
void SetRotation (const tbMath::Angle &angle)
 
void SetScroll (const float scroll)
 
void SetScroll (const float scrollX, const float scrollY)
 
bool IsRelative (void) const
 
const ColorGetColor (void) const
 
virtual void SetColor (const tbGraphics::Color &newColor)
 
float GetWidth (void) const
 
float GetHeight (void) const
 
float GetScaledWidth (void) const
 
float GetScaledHeight (void) const
 
tbMath::Vector2 GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const float offsetX, const float offsetY) const
 
tbMath::Vector2 GetAnchorPosition (const tbGraphics::AnchorLocation &anchor, const tbMath::Vector2 &offset=tbMath::Vector2::Zero()) const
 
bool UnstableIsPointContained (const tbMath::Vector2 &point) const
 

Protected Member Functions

virtual void OnUpdate (const float deltaTime) override
 
virtual void OnRender (void) const override
 
- Protected Member Functions inherited from TurtleBrains::Graphics::Graphic
virtual void ApplyTransform (void) const
 
virtual void PopTransform (void) const
 

Detailed Description

Provides a simple sliding UI element that acts like a health bar.

Constructor & Destructor Documentation

◆ HealthBar()

TurtleBrains::Express::Counters::HealthBar::HealthBar ( const tbGraphics::Color fillColor = tbGraphics::ColorPalette::Green,
const tbGraphics::Color backColor = tbGraphics::ColorPalette::Black 
)
explicit

Constructs the HealthBar object via two BoxShapes of different color.

Parameters
fillColorThe color of the inner bar that represents the counter / health amount that is available in the given counter.
backColorThe color surrounding the inner fill to show the available area.

◆ ~HealthBar()

virtual TurtleBrains::Express::Counters::HealthBar::~HealthBar ( void  )
virtual

Destroys the object and cleans up resources.

Member Function Documentation

◆ GetCount()

const tbCore::uint16& TurtleBrains::Express::Counters::HealthBar::GetCount ( void  ) const

Returns the current value of the counter.

◆ GetPixelHeight()

virtual tbGraphics::PixelSpace TurtleBrains::Express::Counters::HealthBar::GetPixelHeight ( void  ) const
overridevirtual

Returns the height in pixel-space of the health bar, which is the size of the backing / border area, not the intter fill.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ GetPixelWidth()

virtual tbGraphics::PixelSpace TurtleBrains::Express::Counters::HealthBar::GetPixelWidth ( void  ) const
overridevirtual

Returns the width in pixel-space of the health bar, which is the size of the backing / border area, not the intter fill.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ GetTotal()

const tbCore::uint16& TurtleBrains::Express::Counters::HealthBar::GetTotal ( void  ) const

Returns the total value of the counter which can be set via SetTotal() the percentage of GetCount() / GetTotal() determines the display of the slider.

◆ OnRender()

virtual void TurtleBrains::Express::Counters::HealthBar::OnRender ( void  ) const
overrideprotectedvirtual

Renders the BoxShapes the make up the slider bar.

Implements TurtleBrains::Graphics::Graphic.

◆ OnUpdate()

virtual void TurtleBrains::Express::Counters::HealthBar::OnUpdate ( const float  deltaTime)
overrideprotectedvirtual

Updates the size of the BoxShapes if the the Total or Count has been changed since previous frame.

Reimplemented from TurtleBrains::Graphics::Graphic.

◆ SetCount()

void TurtleBrains::Express::Counters::HealthBar::SetCount ( const tbCore::uint16  count)

Sets the current value of the counter which will change how the slider is displayed. The count must be less-than-or-equal-to the total. There will not be an error condition triggered though a warning may be displayed.

Parameters
countThe value of the slider, to be full it would be the same as Total, and to be empty it would be 0.

◆ SetFillColor()

void TurtleBrains::Express::Counters::HealthBar::SetFillColor ( const tbGraphics::Color fillColor)

Sets the color of the fill that shows how full/empty the counter is.

Note
TODO: TurtleBrains: Made in LD39 - double check if this is desired interface.

◆ SetSize()

void TurtleBrains::Express::Counters::HealthBar::SetSize ( const tbGraphics::PixelSpace width,
const tbGraphics::PixelSpace height 
)

Set the size to your desired size in pixels.

Parameters
widthThe horizontal width of the health bar in pixel-space.
heightThe vertical height of the health bar in pixel-space.
Note
The width is uses to display the full/empty status, and thus it is assumed the width is larger than the height. Default size is: 128x10

◆ SetTotal()

void TurtleBrains::Express::Counters::HealthBar::SetTotal ( const tbCore::uint16  total)

Sets the total value of the counter to determine the display of the slider. The value is a 16bit unsigned value. If the new total is less than the current count, the count will be lowered to match the new total.

Parameters
totalThe value it takes for the slider to display as completely full. Must not be 0 or an error condition will be triggered.