GameMap class - UQcsse3200/2023-studio-1 GitHub Wiki
The GameMap class will be slightly overhauled in Sprint3 to allow for the easier access of variables and a more simple instantiation to allow for much easier testing with the GameMap class (and therefore testing with Terrain)
The GameMap class is used to store and easily access and manage the components related to the game map. The 4 variables the class stores are TerrainFactory, TiledMap, TerrainComponent, and Logger instances.
The TerrainFactory class is used to create the game map and is responsible for instantiating both the TiledMap stored in the GameMap class and the TerrainComponent used to render the map in the SpaceGameArea class. The class contains a function to read pre-defined maps saved in the assets folder and load them into the game.
The TiledMap class is used in creating the TerrainComponent instance. It is also important for storing a TiledMapTileLayer instance which holds a 2D array of Cell objects used to store the TerrainTile objects. The GameMap class provides some functions to access these TerrainTile objects.
The Logger instance was included to allow for the logging of info and debugging statements.
The GameMap class has the following public functions:
-
GameMap(TerrainFactory terrainFactory): Instantiates a
GameMapclass instance. -
TerrainFactory getTerrainFactory(): Returns the
TerrainFactoryinstance. -
TiledMap getTiledMap(): Returns the
TiledMapinstance. -
TerrainComponent getTerrainComponent(): Returns the
TerrainComponentinstance. -
void setTerrainComponent(TerrainComponent terrainComponent): Sets the
TerrainComponentinstance. -
public GridPoint2 getMapSize(): Returns a copy of the
GridPoint2instance containing the map size. -
TerrainTile getTile(GridPoint2 gridPoint): Gets the
TerrainTileat the specifiedGridPoint2instance. -
TerrainTile getTile(Vector2 vector): Gets the
TerrainTileat the specifiedVector2instance. -
Vector2 tileCoordinatesToVector(GridPoint2 gridPoint2): Converts a
GridPoint2instance into its correspondingVector2instance. -
GridPoint2 vectorToTileCoordinates(Vector2 vector): Converts a
Vector2instance into its correspondingGridPoint2instance. -
ArrayList getTraversableTileCoordinates(): Returns an
ArrayListofGridPoint2instances of traversable tile coordinates. -
ArrayList getNonTraversableTileCoordinates(): Returns an
ArrayListofGridPoint2instances of non-traversable tile coordinates.

The following sequence diagram is heavily simplified. It does not go into depth with the createGameTiles method, the creation of the TiledMapRenderer renderer instance, nor the utilisation of the TerrainComponent entity in the SpaceGameArea class.
