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>
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
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionHealthBarComponent
(EntityType entityType) Health bar will display health of entity in game. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Called when the component is disposed.protected void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.boolean
float
Z index controls rendering order within a layer.void
Hides health barvoid
setEntityType
(EntityType entityType) void
Makes health bar visible for default amount of timevoid
showHealthBar
(long time) Makes health bar visible for an amount of timevoid
update()
Called once per frame of the game, and should be used for most component logic.void
updateHealth
(int newHealth) Event trigger by event listener.Methods inherited from class com.deco2800.game.rendering.RenderComponent
compareTo, getLayer, render
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, isAnimationRenderComponent, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
HealthBarComponent
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 classRenderComponent
-
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 interfacecom.badlogic.gdx.utils.Disposable
- Overrides:
dispose
in classRenderComponent
-
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 classRenderComponent
- 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. -
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
-
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
-