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.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionTerrainComponent
(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) -
Method Summary
Modifier and TypeMethodDescriptionvoid
colorTile
(int x, int y) void
dispose()
Called when the component is disposed.void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.int
getLayer()
Layer to be rendered in.com.badlogic.gdx.maps.tiled.TiledMap
getMap()
com.badlogic.gdx.math.GridPoint2
getMapBounds
(int layer) float
float
Z index controls rendering order within a layer.void
Highlights the tile under the mouse cursor by changing its texture region.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
-
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)
-
-
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) -
getTileSize
public float getTileSize() -
getMapBounds
public com.badlogic.gdx.math.GridPoint2 getMapBounds(int layer) -
getMap
public com.badlogic.gdx.maps.tiled.TiledMap getMap() -
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
-
colorTile
public void colorTile(int x, int y) -
hoverHighlight
public void hoverHighlight()Highlights the tile under the mouse cursor by changing its texture region. When hovering over a tile on the terrain, this method performs the following: 1-Unprojects the mouse's screen position to the world position using the camera. 2-Calculates the tile's coordinates based on the world position and tile size. 3-If there was a previously highlighted tile, it restores its original texture region. 4-If the current tile under the mouse is different from the last hovered tile, it updates. 5-the tile's texture region to a highlight texture. 6-Updates the reference to the last hovered tile.- See Also:
-
TiledMapTileLayer
TiledMapTileLayer.Cell
TextureRegion
-