Class health

java.lang.Object
name.moore.kevin.ze.components.health
All Implemented Interfaces:
com.simsilica.es.EntityComponent

public class health extends Object implements com.simsilica.es.EntityComponent
A component that tracks the health of an entity. Having this component means it is damageable.

The more damage an entity has, the less effective it becomes.

Author:
Kevin Moore <dev@kevin.moore.name>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static double
     
    private double
    How damageable is this entity going to be.
    private javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless>
    Health as a percentage.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default new health component with default 100% health, moderate fragility.
    health​(Double s, double f)
    The health is from 0 to 100, values outside this range are cropped.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
     
    javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless>
    The health can be returned in different formats:
    javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless>
    minus​(javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> loss)
     
    void
    setHealth​(javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> h)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • FRAGILE_DEFAULT

      public static double FRAGILE_DEFAULT
    • health

      private javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> health
      Health as a percentage. 100 is full health.
    • fragility

      private double fragility
      How damageable is this entity going to be. A high fragility means it will be damaged in preference to a less fragile entity. Assume this is 0 -> 10 (highly fragile), defaults to 5.
  • Constructor Details

    • health

      public health()
      Default new health component with default 100% health, moderate fragility.
    • health

      public health(Double s, double f)
      The health is from 0 to 100, values outside this range are cropped.
      Parameters:
      s - a percentage health
      f - fragility 0->10
  • Method Details

    • setHealth

      public void setHealth(javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> h)
      Parameters:
      h -
    • minus

      public javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> minus(javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> loss)
      Parameters:
      loss - percentage amount to reduce by - clamped to 100%
      Returns:
      updated health
    • getHealth

      public javax.measure.Measure<Double,​javax.measure.quantity.Dimensionless> getHealth()
      The health can be returned in different formats:
      
       getHealth().getValue() = real number eg 76.1
       getHealth().doubleValue(Unit.ONE) = decimal eg 0.761
       
      Returns:
      health as a Double
    • getFragility

      public double getFragility()
    • toString

      public String toString()
      Overrides:
      toString in class Object