Class HealthBarComponent

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>

public class HealthBarComponent extends RenderComponent
The Health Bar Component can be added to entities This component will display the health under the entity The health is specified by the combat stats component
  • Constructor Details

    • HealthBarComponent

      public HealthBarComponent(EntityType entityType)
      Health bar will display health of entity in game. Buildings and Friendly entity types will display green health and enemies will display red health
      Parameters:
      entityType - Type of entity. e.g. Friendly, Enemy, Building
  • Method Details

    • create

      public void create()
      Description copied from class: Component
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class RenderComponent
    • dispose

      public void dispose()
      Description copied from class: Component
      Called when the component is disposed. Dispose of any internal resources here.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class RenderComponent
    • draw

      protected void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch)
      Description copied from class: RenderComponent
      Draw the renderable. Should be called only by the renderer, not manually.
      Specified by:
      draw in class RenderComponent
      Parameters:
      batch - Batch to render to.
    • update

      public void update()
      Description copied from class: Component
      Called once per frame of the game, and should be used for most component logic. Not called if component is disabled.
      Overrides:
      update in class Component
    • updateHealth

      public void updateHealth(int newHealth)
      Event trigger by event listener. When the health is updated it causes the health bar to display if it is hidden Also restarts the timer that automatically hides health bar
      Parameters:
      newHealth - new health
    • hideHealthBar

      public void hideHealthBar()
      Hides health bar
    • showHealthBar

      public void showHealthBar(long time)
      Makes health bar visible for an amount of time
      Parameters:
      time - time in milliseconds
    • showHealthBar

      public void showHealthBar()
      Makes health bar visible for default amount of time
    • getVisible

      public boolean getVisible()
    • setEntityType

      public void setEntityType(EntityType entityType)
    • getZIndex

      public float getZIndex()
      Description copied from interface: Renderable
      Z index controls rendering order within a layer. Higher Z index is drawn on top.
      Specified by:
      getZIndex in interface Renderable
      Overrides:
      getZIndex in class RenderComponent
      Returns:
      Z index