Package com.entities
Class Firetruck
- java.lang.Object
-
- com.badlogic.gdx.graphics.g2d.TextureRegion
-
- com.badlogic.gdx.graphics.g2d.Sprite
-
- com.sprites.SimpleSprite
-
- com.sprites.MovementSprite
-
- com.entities.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 booleanisImmunebooleanisInvisible
-
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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuy()voidcheckCarparkCollision()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 openedbooleancheckDestroyed()Checks if the fire truck should be destroyedvoiddispose()Dispose of all textures used by this class and its parents.voiddrawDebug(com.badlogic.gdx.graphics.glutils.ShapeRenderer renderer)Overloaded method for drawing debug information.java.util.ArrayList<java.lang.Integer>getActivePowerups()Constants.CarparkEntrancesgetCarpark()floatgetDamage()com.badlogic.gdx.scenes.scene2d.ui.ImagegetFireTruckImage()com.badlogic.gdx.graphics.TexturegetFireTruckTexture()booleangetImmune()booleangetInvisible()ETFortressgetNearestFortress()java.util.ArrayList<java.lang.String>getPowerupDisplay()java.lang.StringgetPowerupType()floatgetPrice()floatgetRange()Constants.TruckTypegetType()ResourceBargetWaterBar()Gets the firetruck's water bar so it can be manipulated.booleanisAlive()booleanisBought()booleanisDamaged()Gets whether the firetruck is damaged.booleanisInHoseRange(com.badlogic.gdx.math.Polygon polygon)Checks if a polygon is within the range of the firetrucks hose.booleanisLowOnWater()Gets whether the firetruck has used any water.booleanisSpraying()Gets whether the firetruck is spraying water.booleanisTankEmpty()Gets if the water tank of the truck is emptyprotected voidresetSprite()Resets rotation and hit box when fire truck is spawnedvoidrespawn()Calls methods to reset the fire truck when it is to be respawnedvoidsetArrow(boolean b)voidsetHose(boolean bool)Set the hose on or offvoidsetNearestFortress(java.util.ArrayList<ETFortress> fortresses)Finds the nearest alive fortressvoidsetPowerup(int time, java.lang.String type)voidsetRespawnLocation(int number)====================================================================== Added for assessment 3 ====================================================================== Sets the respawn location which contains the name, x coord, y coord and name of car parkvoidsetToggleDelay(int delay)voidtoggleHose()Toggles the firetruck's hose to spray if off and stop if on.voidupdate(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.graphics.Camera camera)Update the position and direction of the firetruck every frame.voidupdateArrow(com.badlogic.gdx.graphics.glutils.ShapeRenderer shapeRenderer, java.util.ArrayList<ETFortress> fortresses)================================================================================== Added for assessment 3 ==================================================================================-
Methods inherited from class com.sprites.MovementSprite
applyAcceleration, getMaxSpeed, getPolygonVertices, setAccelerationRate, setDecelerationRate, setMaxSpeed, setSpeed, update
-
Methods inherited from class com.sprites.SimpleSprite
decreaseInternalTime, getCentre, getCentreX, getCentreY, getDamageHitBox, getHealthBar, getHeight, getInternalTime, getMovementHitBox, getWidth, removeSprite, resetRotation, rotate, setInternalTime, setMovementHitBox, setSize
-
Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite
draw, draw, flip, getBoundingRectangle, getColor, getOriginX, getOriginY, getRotation, getScaleX, getScaleY, getVertices, getX, getY, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY
-
Methods inherited from class com.badlogic.gdx.graphics.g2d.TextureRegion
getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split
-
-
-
-
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 onfireStation- The fire stationisBought-trueif truck is bought to start withfalseif truck needs to still be boughtgameScreen- 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 arrowfortresses- 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-trueto turn hose onfalseto 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:
drawDebugin classSimpleSprite- 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:
trueif tank is emptyfalseotherwise
-
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:
trueif fire truck is destroyedfalseotherwise
-
getCarpark
public Constants.CarparkEntrances getCarpark()
-
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()
-
getType
public Constants.TruckType getType()
-
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:
disposein classSimpleSprite
-
-