GameMap class - UQcsse3200/2023-studio-1 GitHub Wiki

GameMap Class

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 GameMap class instance.
  • TerrainFactory getTerrainFactory(): Returns the TerrainFactory instance.
  • TiledMap getTiledMap(): Returns the TiledMap instance.
  • TerrainComponent getTerrainComponent(): Returns the TerrainComponent instance.
  • void setTerrainComponent(TerrainComponent terrainComponent): Sets the TerrainComponent instance.
  • public GridPoint2 getMapSize(): Returns a copy of the GridPoint2 instance containing the map size.
  • TerrainTile getTile(GridPoint2 gridPoint): Gets the TerrainTile at the specified GridPoint2 instance.
  • TerrainTile getTile(Vector2 vector): Gets the TerrainTile at the specified Vector2 instance.
  • Vector2 tileCoordinatesToVector(GridPoint2 gridPoint2): Converts a GridPoint2 instance into its corresponding Vector2 instance.
  • GridPoint2 vectorToTileCoordinates(Vector2 vector): Converts a Vector2 instance into its corresponding GridPoint2 instance.
  • ArrayList getTraversableTileCoordinates(): Returns an ArrayList of GridPoint2 instances of traversable tile coordinates.
  • ArrayList getNonTraversableTileCoordinates(): Returns an ArrayList of GridPoint2 instances of non-traversable tile coordinates.

UML Diagram of Map System

image

Sequence Diagram of Map System

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. image

⚠️ **GitHub.com Fallback** ⚠️