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 TypeMethodDescriptionvoidcreate()Called when the entity is created and registered.voiddispose()Called when the component is disposed.protected voiddraw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.booleanfloatZ index controls rendering order within a layer.voidHides health barvoidsetEntityType(EntityType entityType) voidMakes health bar visible for default amount of timevoidshowHealthBar(long time) Makes health bar visible for an amount of timevoidupdate()Called once per frame of the game, and should be used for most component logic.voidupdateHealth(int newHealth) Event trigger by event listener.Methods inherited from class com.deco2800.game.rendering.RenderComponent
compareTo, getLayer, renderMethods 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:ComponentCalled 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:
createin classRenderComponent
-
dispose
public void dispose()Description copied from class:ComponentCalled when the component is disposed. Dispose of any internal resources here.- Specified by:
disposein interfacecom.badlogic.gdx.utils.Disposable- Overrides:
disposein classRenderComponent
-
draw
protected void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Description copied from class:RenderComponentDraw the renderable. Should be called only by the renderer, not manually.- Specified by:
drawin classRenderComponent- Parameters:
batch- Batch to render to.
-
update
public void update()Description copied from class:ComponentCalled 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:RenderableZ index controls rendering order within a layer. Higher Z index is drawn on top.- Specified by:
getZIndexin interfaceRenderable- Overrides:
getZIndexin classRenderComponent- Returns:
- Z index
-