Package com.entities

Class Firetruck


  • public class Firetruck
    extends MovementSprite
    The Firetruck implementation. A sprite capable of moving and colliding with other sprites.
    Since:
    16/12/2019
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean isImmune  
      boolean isInvisible  
    • Constructor Summary

      Constructors 
      Constructor Description
      Firetruck​(java.util.ArrayList<com.badlogic.gdx.graphics.Texture> textureSlices, java.util.ArrayList<com.badlogic.gdx.graphics.Texture> frames, Constants.TruckType type, com.badlogic.gdx.maps.tiled.TiledMapTileLayer collisionLayer, com.badlogic.gdx.maps.tiled.TiledMapTileLayer carparkLayer, Firestation fireStation, boolean isBought, GameScreen gameScreen)
      Creates a firetruck capable of moving and colliding with the tiledMap and other sprites.
    • Field Detail

      • isInvisible

        public boolean isInvisible
      • isImmune

        public boolean isImmune
    • Constructor Detail

      • Firetruck

        public Firetruck​(java.util.ArrayList<com.badlogic.gdx.graphics.Texture> textureSlices,
                         java.util.ArrayList<com.badlogic.gdx.graphics.Texture> frames,
                         Constants.TruckType type,
                         com.badlogic.gdx.maps.tiled.TiledMapTileLayer collisionLayer,
                         com.badlogic.gdx.maps.tiled.TiledMapTileLayer carparkLayer,
                         Firestation fireStation,
                         boolean isBought,
                         GameScreen gameScreen)
        Creates a firetruck capable of moving and colliding with the tiledMap and other sprites. It also requires an ID so that it can be focused with the camera. Drawn with the given texture at the given position.
        Parameters:
        textureSlices - The array of textures used to draw the firetruck with.
        frames - The texture used to draw the water with.
        type - The properties of the truck inherited from Constants.
        collisionLayer - The layer of the map the firetruck collides with.
        carparkLayer - The layer of the map the carparks are on
        fireStation - The fire station
        isBought - true if truck is bought to start with false if truck needs to still be bought
        gameScreen - GameScreen to get difficulty and save controls
    • Method Detail

      • update

        public void update​(com.badlogic.gdx.graphics.g2d.Batch batch,
                           com.badlogic.gdx.graphics.Camera camera)
        Update the position and direction of the firetruck every frame.
        Parameters:
        batch - The batch to draw onto.
        camera - Used to get the centre of the screen.
      • checkCarparkCollision

        public void checkCarparkCollision()
        Checks if the firetruck enters a car park, set the respawn location of the fire truck to that car park and sets the menu to be opened
      • setRespawnLocation

        public void setRespawnLocation​(int number)
        ====================================================================== Added for assessment 3 ====================================================================== Sets the respawn location which contains the name, x coord, y coord and name of car park
        Parameters:
        number - from tile map custom property
      • updateArrow

        public void updateArrow​(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer,
                                java.util.ArrayList<ETFortress> fortresses)
        ================================================================================== Added for assessment 3 ==================================================================================

        Updates the arrow to point at the nearest fortress to help the user know where to go

        Parameters:
        shapeRenderer - to draw the arrow
        fortresses - list of fortresses
      • resetSprite

        protected void resetSprite()
        Resets rotation and hit box when fire truck is spawned
      • setNearestFortress

        public void setNearestFortress​(java.util.ArrayList<ETFortress> fortresses)
        Finds the nearest alive fortress
        Parameters:
        fortresses - list of fortresses
      • isInHoseRange

        public boolean isInHoseRange​(com.badlogic.gdx.math.Polygon polygon)
        Checks if a polygon is within the range of the firetrucks hose.
        Parameters:
        polygon - The polygon that needs to be checked.
        Returns:
        Whether the polygon is in the hose's range
      • isDamaged

        public boolean isDamaged()
        Gets whether the firetruck is damaged.
        Returns:
        Whether the firetruck is damaged.
      • isLowOnWater

        public boolean isLowOnWater()
        Gets whether the firetruck has used any water.
        Returns:
        Whether the firetruck has used any water.
      • toggleHose

        public void toggleHose()
        Toggles the firetruck's hose to spray if off and stop if on.
      • setHose

        public void setHose​(boolean bool)
        Set the hose on or off
        Parameters:
        bool - true to turn hose on false to turn hose off
      • drawDebug

        public void drawDebug​(com.badlogic.gdx.graphics.glutils.ShapeRenderer renderer)
        Overloaded method for drawing debug information. Draws the hitbox as well as the hose range indicator.
        Overrides:
        drawDebug in class SimpleSprite
        Parameters:
        renderer - The renderer used to draw the hitbox and range indicator with.
      • getWaterBar

        public ResourceBar getWaterBar()
        Gets the firetruck's water bar so it can be manipulated.
        Returns:
        The firetruck's water bar.
      • isSpraying

        public boolean isSpraying()
        Gets whether the firetruck is spraying water.
        Returns:
        Whether the firetruck is spraying water.
      • isTankEmpty

        public boolean isTankEmpty()
        Gets if the water tank of the truck is empty
        Returns:
        true if tank is empty false otherwise
      • respawn

        public void respawn()
        Calls methods to reset the fire truck when it is to be respawned
      • checkDestroyed

        public boolean checkDestroyed()
        Checks if the fire truck should be destroyed
        Returns:
        true if fire truck is destroyed false otherwise
      • getFireTruckTexture

        public com.badlogic.gdx.graphics.Texture getFireTruckTexture()
      • getFireTruckImage

        public com.badlogic.gdx.scenes.scene2d.ui.Image getFireTruckImage()
      • isAlive

        public boolean isAlive()
      • getRange

        public float getRange()
      • getPrice

        public float getPrice()
      • getDamage

        public float getDamage()
      • buy

        public void buy()
      • isBought

        public boolean isBought()
      • setToggleDelay

        public void setToggleDelay​(int delay)
      • getNearestFortress

        public ETFortress getNearestFortress()
      • setArrow

        public void setArrow​(boolean b)
      • getInvisible

        public boolean getInvisible()
      • getImmune

        public boolean getImmune()
      • getPowerupType

        public java.lang.String getPowerupType()
      • getPowerupDisplay

        public java.util.ArrayList<java.lang.String> getPowerupDisplay()
      • getActivePowerups

        public java.util.ArrayList<java.lang.Integer> getActivePowerups()
      • setPowerup

        public void setPowerup​(int time,
                               java.lang.String type)
      • dispose

        public void dispose()
        Dispose of all textures used by this class and its parents.
        Overrides:
        dispose in class SimpleSprite