Package com.csse3200.game.areas.terrain
Class TerrainComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.rendering.RenderComponent
com.csse3200.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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTerrainComponent
(com.badlogic.gdx.graphics.OrthographicCamera camera, com.badlogic.gdx.maps.tiled.TiledMap map, com.badlogic.gdx.maps.tiled.TiledMapRenderer renderer, TerrainOrientation orientation, float tileSize, MapHandler.MapType mapType) -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Called when the component is disposed.void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.void
fillChunk
(com.badlogic.gdx.math.GridPoint2 chunkPos) Fill a chunk with tiles if it is not already loaded.Set
<com.badlogic.gdx.math.GridPoint2> getChunk
(com.badlogic.gdx.math.GridPoint2 chunkPos) int
getLayer()
Layer to be rendered in.com.badlogic.gdx.maps.tiled.TiledMap
getMap()
Get current mapcom.badlogic.gdx.math.GridPoint2
getMapBounds
(int layer) Get the bounds of the terrain map.Set
<com.badlogic.gdx.math.GridPoint2> Set
<com.badlogic.gdx.math.GridPoint2> com.badlogic.gdx.maps.tiled.TiledMap
float
Get the size of all tiles in the terrain.float
Z index controls rendering order within a layer.void
loadChunks
(com.badlogic.gdx.math.GridPoint2 chunkPos) Load all chunks around the given chunk position.void
loadChunks
(com.badlogic.gdx.math.GridPoint2 chunkPos, int r) Load all chunks in a given radius (a square - not circle) around the given chunk position.com.badlogic.gdx.math.Vector2
tileToWorldPosition
(int x, int y) com.badlogic.gdx.math.Vector2
tileToWorldPosition
(com.badlogic.gdx.math.GridPoint2 tilePos) Methods inherited from class com.csse3200.game.rendering.RenderComponent
compareTo, create, render
Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Field Details
-
CHUNK_SIZE
public static final int CHUNK_SIZE- See Also:
-
-
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, TerrainOrientation orientation, float tileSize, MapHandler.MapType mapType)
-
-
Method Details
-
tileToWorldPosition
public com.badlogic.gdx.math.Vector2 tileToWorldPosition(com.badlogic.gdx.math.GridPoint2 tilePos) -
tileToWorldPosition
public com.badlogic.gdx.math.Vector2 tileToWorldPosition(int x, int y) -
fillChunk
public void fillChunk(com.badlogic.gdx.math.GridPoint2 chunkPos) Fill a chunk with tiles if it is not already loaded.- Parameters:
chunkPos
- The position of the chunk to fill
-
loadChunks
public void loadChunks(com.badlogic.gdx.math.GridPoint2 chunkPos) Load all chunks around the given chunk position.- Parameters:
chunkPos
- The position of the chunk to load around
-
loadChunks
public void loadChunks(com.badlogic.gdx.math.GridPoint2 chunkPos, int r) Load all chunks in a given radius (a square - not circle) around the given chunk position.- Parameters:
chunkPos
- The position of the chunk to load aroundr
- The number of chunks away to spawn
-
getChunk
-
getNewChunks
-
getOldChunks
-
getActiveChunks
-
getTileSize
public float getTileSize()Get the size of all tiles in the terrain.- Returns:
- The size of all tiles in the terrain
-
getMapBounds
public com.badlogic.gdx.math.GridPoint2 getMapBounds(int layer) Get the bounds of the terrain map.- Parameters:
layer
- the bounds of the layer- Returns:
- The bounds of the terrain map
-
getMap
public com.badlogic.gdx.maps.tiled.TiledMap getMap()Get current map- Returns:
- The current map
-
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
-
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
-
getTiledMap
public com.badlogic.gdx.maps.tiled.TiledMap getTiledMap()
-