Package com.deco2800.game.areas.terrain
Class TerrainComponent
java.lang.Object
com.deco2800.game.components.Component
com.deco2800.game.rendering.RenderComponent
com.deco2800.game.areas.terrain.TerrainComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
Render a tiled terrain for a given tiled map and orientation. A terrain is a
map of tiles that
shows the 'ground' in the game. Enabling/disabling this component will
show/hide the terrain.
-
Nested Class Summary
Nested Classes -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionTerrainComponent
(com.badlogic.gdx.graphics.OrthographicCamera camera, com.badlogic.gdx.maps.tiled.TiledMap map, com.badlogic.gdx.maps.tiled.TiledMapRenderer renderer, TerrainComponent.TerrainOrientation orientation, float tileSize, com.badlogic.gdx.math.GridPoint2 island_size, ArrayList<ArrayList<com.badlogic.gdx.math.GridPoint2>> landTilesList, ArrayList<ArrayList<com.badlogic.gdx.math.GridPoint2>> walls) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Damages all buildings that are on watervoid
Shrinks the map by hiding the current layer, and making the previous level visible.void
dispose()
Called when the component is disposed.void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.int
com.badlogic.gdx.math.GridPoint2
ArrayList<com.badlogic.gdx.math.GridPoint2>
int
getLayer()
Layer to be rendered in.com.badlogic.gdx.maps.tiled.TiledMap
getMap()
com.badlogic.gdx.math.GridPoint2
getMapBounds
(int layer) com.badlogic.gdx.maps.tiled.TiledMapTileLayer
getTileMapTileLayer
(int layer) float
getWalls()
float
Z index controls rendering order within a layer.void
Expands the map by hiding the current layer, and making the next level visiblevoid
partOfDayPassed
(DayNightCycleStatus partOfDay) Changes the current map level to the night version when night comes aroundvoid
setIslandSize
(int x, int y) com.badlogic.gdx.math.Vector2
tileToWorldPosition
(int x, int y) com.badlogic.gdx.math.Vector2
tileToWorldPosition
(com.badlogic.gdx.math.GridPoint2 tilePos) protected void
Updates the UGS in response to map state changing: updates each coordinate in the UGS to the new tile type.com.badlogic.gdx.math.GridPoint2
worldToTilePosition
(float x, float y) float x must be world position x - using camera.unproject float y must be world position y - using camera.unprojectMethods inherited from class com.deco2800.game.rendering.RenderComponent
compareTo, create, render
Methods inherited from class com.deco2800.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
TerrainComponent
public TerrainComponent(com.badlogic.gdx.graphics.OrthographicCamera camera, com.badlogic.gdx.maps.tiled.TiledMap map, com.badlogic.gdx.maps.tiled.TiledMapRenderer renderer, TerrainComponent.TerrainOrientation orientation, float tileSize, com.badlogic.gdx.math.GridPoint2 island_size, ArrayList<ArrayList<com.badlogic.gdx.math.GridPoint2>> landTilesList, ArrayList<ArrayList<com.badlogic.gdx.math.GridPoint2>> walls)
-
-
Method Details
-
tileToWorldPosition
public com.badlogic.gdx.math.Vector2 tileToWorldPosition(com.badlogic.gdx.math.GridPoint2 tilePos) -
worldToTilePosition
public com.badlogic.gdx.math.GridPoint2 worldToTilePosition(float x, float y) float x must be world position x - using camera.unproject float y must be world position y - using camera.unproject -
tileToWorldPosition
public com.badlogic.gdx.math.Vector2 tileToWorldPosition(int x, int y) -
getCurrentMapLvl
public int getCurrentMapLvl() -
getWalls
-
damageSunkenBuildings
protected void damageSunkenBuildings()Damages all buildings that are on water -
updateUGS
protected void updateUGS()Updates the UGS in response to map state changing: updates each coordinate in the UGS to the new tile type. -
incrementMapLvl
public void incrementMapLvl()Expands the map by hiding the current layer, and making the next level visible -
decrementMapLvl
public void decrementMapLvl()Shrinks the map by hiding the current layer, and making the previous level visible. -
partOfDayPassed
Changes the current map level to the night version when night comes around- Parameters:
partOfDay
- day night cycle time period
-
getTileSize
public float getTileSize() -
getMapBounds
public com.badlogic.gdx.math.GridPoint2 getMapBounds(int layer) -
getMap
public com.badlogic.gdx.maps.tiled.TiledMap getMap() -
getLandTiles
-
setIslandSize
public void setIslandSize(int x, int y) -
getIslandSize
public com.badlogic.gdx.math.GridPoint2 getIslandSize() -
draw
public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Description copied from class:RenderComponent
Draw the renderable. Should be called only by the renderer, not manually.- Specified by:
draw
in classRenderComponent
- Parameters:
batch
- Batch to render to.
-
dispose
public void dispose()Description copied from class:Component
Called when the component is disposed. Dispose of any internal resources here.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
- Overrides:
dispose
in classRenderComponent
-
getTileMapTileLayer
public com.badlogic.gdx.maps.tiled.TiledMapTileLayer getTileMapTileLayer(int layer) -
getZIndex
public float getZIndex()Description copied from interface:Renderable
Z index controls rendering order within a layer. Higher Z index is drawn on top.- Specified by:
getZIndex
in interfaceRenderable
- Overrides:
getZIndex
in classRenderComponent
- Returns:
- Z index
-
getLayer
public int getLayer()Description copied from interface:Renderable
Layer to be rendered in. Higher layers will be rendered on top of lower layers.- Specified by:
getLayer
in interfaceRenderable
- Overrides:
getLayer
in classRenderComponent
- Returns:
- layer
-