Package com.misc

Class ResourceBar


  • public class ResourceBar
    extends java.lang.Object
    Resource bars used by sprites to indicate properties of sprites. These are graphical and displayed to the user.
    Since:
    17/12/2019
    • Constructor Summary

      Constructors 
      Constructor Description
      ResourceBar​(float spriteWidth, float spriteHeight)
      Constructor for this class, gathers required information so that it can be drawn.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addResourceAmount​(int amount)
      Add a value to the resource bar.
      int getCurrentAmount()
      Get the current resource amount.
      float getFade()
      Get the bar's alpha value, manipulated to remain in the range 0-1.
      float getMaxAmount()
      Get the max resource amount.
      void resetResourceAmount()
      Reset the resource amount back to its original full capacity, this is used for replenishing the fire truck's water after the tutorial has finished
      void setColourRange​(com.badlogic.gdx.graphics.Color[] colours)
      Set the colour range of the bar.
      void setCurrentAmount​(int amount)
      Set the current resource amount.
      void setFade​(boolean shouldFadeIn, boolean shouldFadeOut)
      Fade the bar either in or out using it's alpha value.
      void setMaxResource​(int maxAmount)
      Set the maximum limit for the resource bar.
      void setPosition​(float spriteXPos, float spriteYPos)
      Set the position of the bar, takes into account the sprite's dimensions
      void subtractResourceAmount​(int amount)
      Subtract a value from the resource bar.
      void update​(com.badlogic.gdx.graphics.g2d.Batch batch)
      Draw the resource bar.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ResourceBar

        public ResourceBar​(float spriteWidth,
                           float spriteHeight)
        Constructor for this class, gathers required information so that it can be drawn.
        Parameters:
        spriteWidth - The width of the sprite.
        spriteHeight - The height of the sprite.
    • Method Detail

      • update

        public void update​(com.badlogic.gdx.graphics.g2d.Batch batch)
        Draw the resource bar. Needs to be called every frame.
        Parameters:
        batch - The batch to draw the resource bar onto.
      • setPosition

        public void setPosition​(float spriteXPos,
                                float spriteYPos)
        Set the position of the bar, takes into account the sprite's dimensions
        Parameters:
        spriteXPos - The x-coordinate of the sprite.
        spriteYPos - The y-coordinate of the sprite.
      • setFade

        public void setFade​(boolean shouldFadeIn,
                            boolean shouldFadeOut)
        Fade the bar either in or out using it's alpha value.
        Parameters:
        shouldFadeIn - Whether to fade in (true) or out (false)
        shouldFadeOut - Whether to fade out (true) or out (false)
      • getFade

        public float getFade()
        Get the bar's alpha value, manipulated to remain in the range 0-1.
        Returns:
        The alpha value of the bar
      • setColourRange

        public void setColourRange​(com.badlogic.gdx.graphics.Color[] colours)
        Set the colour range of the bar. The bar is split into 3 sections so 3 colours are required.
        Parameters:
        colours - The colours the sprite will use;
      • getCurrentAmount

        public int getCurrentAmount()
        Get the current resource amount.
        Returns:
        The current resource amount;
      • setCurrentAmount

        public void setCurrentAmount​(int amount)
        Set the current resource amount.
        Parameters:
        amount - The amount the current resource amount will be set to;
      • getMaxAmount

        public float getMaxAmount()
        Get the max resource amount.
        Returns:
        The max resource amount;
      • setMaxResource

        public void setMaxResource​(int maxAmount)
        Set the maximum limit for the resource bar.
        Parameters:
        maxAmount - The maximum limit for the resource bar.
      • addResourceAmount

        public void addResourceAmount​(int amount)
        Add a value to the resource bar.
        Parameters:
        amount - The value to add to the resource bar.
      • subtractResourceAmount

        public void subtractResourceAmount​(int amount)
        Subtract a value from the resource bar.
        Parameters:
        amount - The value to subtract from the resource bar.
      • resetResourceAmount

        public void resetResourceAmount()
        Reset the resource amount back to its original full capacity, this is used for replenishing the fire truck's water after the tutorial has finished