Class GameMap

java.lang.Object
com.csse3200.game.areas.terrain.GameMap

public class GameMap extends Object
the GameMap class is used to store and easily access and manage the components related to the game map
  • Constructor Summary

    Constructors
    Constructor
    Description
    GameMap(TerrainFactory terrainFactory)
    Creates a new GameMap instance, setting the terrainFactory and instantiating a new TiledMap instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Creates the TerrainComponent instance used to render the SpaceGameArea map and stores it in the GameMap class.
    void
    Creates the TerrainComponent instance used to render a test game map.
    com.badlogic.gdx.math.GridPoint2
    Returns a GridPoint2 instance that contains the size of the map.
    List<com.badlogic.gdx.math.GridPoint2>
    Retrieves a list of grid coordinates representing non-traversable tiles on the map.
    Returns the TerrainComponent instance stored in the GameMap class.
    Returns the TerrainFactory instance stored in the GameMap class.
    getTile(com.badlogic.gdx.math.GridPoint2 gridPoint)
    Gets the TerrainTile at the specified GridPoint2 position.
    getTile(com.badlogic.gdx.math.Vector2 vector)
    Gets the TerrainTile at the specified Vector2 position.
    com.badlogic.gdx.maps.tiled.TiledMap
    Returns the TiledMap instance stored in the GameMap class.
    List<com.badlogic.gdx.math.GridPoint2>
    Retrieves a list of grid coordinates representing traversable tiles on the map.
    void
    loadTestTerrain(String testMapFilePath)
    Instantiates the GameMap with a test file map to be used in JUnit testing.
    void
    Sets the TerrainComponent.
    com.badlogic.gdx.math.Vector2
    tileCoordinatesToVector(com.badlogic.gdx.math.GridPoint2 gridPoint2)
    Converts a GridPoint2 instance into a Vector2 instance representing the same TerrainTile position on the map layer.
    com.badlogic.gdx.math.GridPoint2
    vectorToTileCoordinates(com.badlogic.gdx.math.Vector2 vector)
    Converts a Vector2 instance into a GridPoint2 instance representing the same TerrainTile position on the map layer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GameMap

      public GameMap(TerrainFactory terrainFactory)
      Creates a new GameMap instance, setting the terrainFactory and instantiating a new TiledMap instance.
      Parameters:
      terrainFactory - the terrainFactory passed to the SpaceGameArea from the MainGameScreen class.
  • Method Details

    • createTerrainComponent

      public void createTerrainComponent()
      Creates the TerrainComponent instance used to render the SpaceGameArea map and stores it in the GameMap class. Additionally, updates the TiledMap instance so that getter and setter methods for accessing TerrainTile instances can function correctly.
    • createTestTerrainComponent

      public void createTestTerrainComponent(String testMapFilePath)
      Creates the TerrainComponent instance used to render a test game map. Additionally, updates the TiledMap instance so that the getter and setter methods for accessing TerrainTile instances can function correctly. This method is intended to allow for play testing of different game maps. Trying to generate a TerrainComponent through JUnit tests can be difficult, so an alternate loadTestTerrain() method has been provided to only set the TiledMap instance needed for interacting with terrain.
      Parameters:
      testMapFilePath - the file path of the test map file to load.
    • loadTestTerrain

      public void loadTestTerrain(String testMapFilePath)
      Instantiates the GameMap with a test file map to be used in JUnit testing. This updates the TiledMap instance so that the getter and setter methods for accessing TerrainTile instances can function correctly in JUnit tests that require them. This method does not create a TerrainComponent, which means it cannot be used to render an actual game map.
      Parameters:
      testMapFilePath - the file path of the test map file to load.
    • getTerrainFactory

      public TerrainFactory getTerrainFactory()
      Returns the TerrainFactory instance stored in the GameMap class.
      Returns:
      the terrainFactory variable.
    • getTiledMap

      public com.badlogic.gdx.maps.tiled.TiledMap getTiledMap()
      Returns the TiledMap instance stored in the GameMap class.
      Returns:
      the tiledMap variable.
    • getTerrainComponent

      public TerrainComponent getTerrainComponent()
      Returns the TerrainComponent instance stored in the GameMap class.
      Returns:
      the terrainComponent variable.
    • setTerrainComponent

      public void setTerrainComponent(TerrainComponent terrainComponent)
      Sets the TerrainComponent.
      Parameters:
      terrainComponent - the terrainComponent to be set.
    • getMapSize

      public com.badlogic.gdx.math.GridPoint2 getMapSize()
      Returns a GridPoint2 instance that contains the size of the map.
      Returns:
      a copy of the GridPoint2 instance which contains the dimensions of the map.
    • getTile

      public TerrainTile getTile(com.badlogic.gdx.math.GridPoint2 gridPoint)
      Gets the TerrainTile at the specified GridPoint2 position. The x and y values in the GridPoint2 class directly correspond to the tile's position in the map layer. (0, 0) is the bottom left of the map.
      Parameters:
      gridPoint - The GridPoint2 instance representing the target TerrainTile's position.
      Returns:
      TerrainTile instance at the specified position IF the gridpoint is within the bounds of the map, null otherwise
    • getTile

      public TerrainTile getTile(com.badlogic.gdx.math.Vector2 vector)
      Gets the TerrainTile at the specified Vector2 position. The x and y float values in the Vector2 class are transformed so that they correspond to the integer positions of the TerrainTile in the map layer. (0, 0) is the bottom left of the map.

      If using the Vector2 position variable from the Entity class, it is important to remember that the vector points to the bottom left of the entity , not the centre of the entity (This is important to know if the entity uses animations since the entity size may be larger than the actual sprite). The Entity class provides the getPosition() and getCentredPosition() methods to help retrieve an appropriate Vector2 instance to use.

      Parameters:
      vector - The Vector2 instance representing the target TerrainTile's position.
      Returns:
      TerrainTile instance at the specified position IF the vector is within the bounds of the map, null otherwise
    • tileCoordinatesToVector

      public com.badlogic.gdx.math.Vector2 tileCoordinatesToVector(com.badlogic.gdx.math.GridPoint2 gridPoint2)
      Converts a GridPoint2 instance into a Vector2 instance representing the same TerrainTile position on the map layer. The integer values in the GridPoint2 class which directly correspond to the TerrainTile coordinates are transformed for the new Vector2 instance.
      Parameters:
      gridPoint2 - The GridPoint2 instance being used to create a corresponding Vector2 instance.
      Returns:
      the new Vector2 instance.
    • vectorToTileCoordinates

      public com.badlogic.gdx.math.GridPoint2 vectorToTileCoordinates(com.badlogic.gdx.math.Vector2 vector)
      Converts a Vector2 instance into a GridPoint2 instance representing the same TerrainTile position on the map layer. The float values in the Vector2 instance are transformed to integer x and y values for the GridPoint2 instance.
      Parameters:
      vector - The Vector2 instance being used to create a corresponding GridPoint2 instance.
      Returns:
      the new GridPoint2 instance.
    • getTraversableTileCoordinates

      public List<com.badlogic.gdx.math.GridPoint2> getTraversableTileCoordinates()
      Retrieves a list of grid coordinates representing traversable tiles on the map.
      Returns:
      An ArrayList of GridPoint2 objects containing the coordinates of traversable tiles.
    • getNonTraversableTileCoordinates

      public List<com.badlogic.gdx.math.GridPoint2> getNonTraversableTileCoordinates()
      Retrieves a list of grid coordinates representing non-traversable tiles on the map.
      Returns:
      An ArrayList of GridPoint2 objects containing the coordinates of non-traversable tiles.