Package com.deco2800.game.components
Class HealthBarComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.rendering.RenderComponent
com.deco2800.game.components.HealthBarComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
Renders the entities health bar. Requires CombatStatsComponent
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
As soon as the entity is created we want to get its CombatStatsComponent.protected void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) When the render calls draw we render the health bar with any adjustments made so it reflects the remaining or added heathcom.badlogic.gdx.scenes.scene2d.ui.ProgressBar
Returns the progress bar that represents the heath bar percentage to being displayedfloat
Z index controls rendering order within a layer.void
setCombatStatsComponent
(CombatStatsComponent combatStatsComponent) void
setRenderUtil
(RenderUtil renderUtil) For setting a renderUtil if instantiated as a mock or otherwiseMethods inherited from class com.deco2800.game.rendering.RenderComponent
compareTo, dispose, getLayer, render
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
HealthBarComponent
public HealthBarComponent(int width, int height) Constructs a new health bar- Parameters:
width
- the width of the health bar in pixelsheight
- the height of the healbar in pixels
-
-
Method Details
-
setCombatStatsComponent
-
getProgressBar
public com.badlogic.gdx.scenes.scene2d.ui.ProgressBar getProgressBar()Returns the progress bar that represents the heath bar percentage to being displayed- Returns:
- the progress bar representing health
-
setRenderUtil
For setting a renderUtil if instantiated as a mock or otherwise- Parameters:
renderUtil
- the instance to use
-
create
public void create()As soon as the entity is created we want to get its CombatStatsComponent. This means the order in which you add the HealthBarComponent and CombatStatsComponent is important. You are expected to have CombatStatsComponent first added. fullHealth refers to the initial health of the entity when constructed- Overrides:
create
in classRenderComponent
-
draw
protected void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) When the render calls draw we render the health bar with any adjustments made so it reflects the remaining or added heath- Specified by:
draw
in classRenderComponent
- Parameters:
batch
- Batch to render to.
-
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 interfaceRenderable
- Overrides:
getZIndex
in classRenderComponent
- Returns:
- Z index
-